-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconversationmodel.h
124 lines (96 loc) · 3.59 KB
/
conversationmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Hanghish
Copyright (C) 2015 Daniele Rogora
This file is part of Hangish.
Hangish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hangish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Nome-Programma. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef CONVERSATIONMODEL_H
#define CONVERSATIONMODEL_H
#include <QAbstractListModel>
#include "qtimports.h"
#include "structs.h"
class ConversationElement {
public:
QNetworkReply *id;
QString text;
QString sender;
QString timestamp;
QString senderId;
QString fullimageUrl;
QString previewImageUrl;
QString video;
QString uniqueId;
int type;
bool read;
QDateTime ts;
ConversationElement(QNetworkReply *pId, QString pSender, QString pSenderId, QString pText, QString pTS, QString pFullImageUrl, QString pPrevImageUrl, QString pVideo, bool pRead, QDateTime pts, int pType, QString uid) {
id = pId;
text = pText;
sender = pSender;
senderId = pSenderId;
timestamp = pTS;
fullimageUrl = pFullImageUrl;
previewImageUrl = pPrevImageUrl;
video = pVideo;
read = pRead;
ts = pts;
type = pType;
uniqueId = uid;
}
};
class ConversationModel : public QAbstractListModel
{
QList<Conversation> conversations;
Q_OBJECT
Q_PROPERTY(QString cid READ getCid WRITE loadConversation FINAL)
public:
void updateReadState(ReadState rs);
void addConversation(Conversation c);
bool addEventToConversation(QString convId, Event e, bool bottom=true);
void addSentMessage(QNetworkReply *id, QString convId, Event evt);
void addErrorMessage(QNetworkReply *id, QString convId, Event evt);
void addOutgoingMessage(QNetworkReply *id, QString convId, Event evt);
QDateTime getFirstEventTs(QString convId);
QString id, name;
enum ConversationRoles {
IdRole = Qt::UserRole + 1,
SenderRole,
SenderIdRole,
TextRole,
FullImageRole,
PreviewImageRole,
VideoRole,
TimestampRole,
ReadRole,
UidRole
};
int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
explicit ConversationModel(QObject *parent = 0);
void loadConversation(QString cId);
QString getCid();
bool addConversationElement(QNetworkReply *id, QString sender, QString senderId, QString timestamp, QString text, QString fullimageUrl, QString previewimageUrl, QString video, bool read, QDateTime pts, int type, bool isMine, QString uid);
void prependConversationElement(QString sender, QString senderId, QString timestamp, QString text, QString fullimageUrl, QString previewimageUrl, QString video, bool read, QDateTime pts, int type, QString uid);
void deleteMsgWError(QString text);
private:
QString getSenderName(QString chatId, QList<Participant> participants);
QList<ConversationElement *> myList;
protected:
QHash<int, QByteArray> roleNames() const;
signals:
void conversationRequested(QString cid);
public slots:
void conversationLoaded();
private slots:
void deleteMsg(QNetworkReply *id);
};
#endif // CONVERSATIONMODEL_H