-
Notifications
You must be signed in to change notification settings - Fork 25
/
telegramdialoglistmodel.h
184 lines (148 loc) · 5.98 KB
/
telegramdialoglistmodel.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#ifndef TELEGRAMDIALOGLISTMODEL_H
#define TELEGRAMDIALOGLISTMODEL_H
#include <QObject>
#include <QJSValue>
#include "telegramqml_macros.h"
#include "telegramqml_global.h"
#include "telegramabstractenginelistmodel.h"
class UpdatesType;
class InputPeerObject;
class TelegramDialogListItem;
class TelegramDialogListModelPrivate;
class TELEGRAMQMLSHARED_EXPORT TelegramDialogListModel : public TelegramAbstractEngineListModel
{
Q_OBJECT
Q_ENUMS(VisibilityFlags)
Q_ENUMS(SortFlag)
Q_ENUMS(DataRoles)
Q_ENUMS(SecretChatState)
Q_PROPERTY(int visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)
Q_PROPERTY(QList<qint32> sortFlag READ sortFlag WRITE setSortFlag NOTIFY sortFlagChanged)
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
Q_PROPERTY(QJSValue dateConvertorMethod READ dateConvertorMethod WRITE setDateConvertorMethod NOTIFY dateConvertorMethodChanged)
Q_PROPERTY(QJSValue messageTextMethod READ messageTextMethod WRITE setMessageTextMethod NOTIFY messageTextMethodChanged)
Q_PROPERTY(bool refreshing READ refreshing NOTIFY refreshingChanged)
Q_PROPERTY(bool useCache READ useCache WRITE setUseCache NOTIFY useCacheChanged)
Q_PROPERTY(QVariantMap categories READ categories WRITE setCategories NOTIFY categoriesChanged)
Q_PROPERTY(QVariantList itemsList READ itemsList NOTIFY itemsListChanged)
public:
enum VisibilityFlags {
VisibilityEmptyDialogs = 1,
VisibilityDeletedDialogs = 2,
VisibilityOnlineUsersOnly = 4,
VisibilityContacts = 8,
VisibilityNonContacts = 16,
VisibilityBots = 32,
VisibilityUsers = VisibilityContacts | VisibilityNonContacts,
VisibilityChats = 64,
VisibilityChannels = 128,
VisibilitySecretChats = 256,
VisibilityAll = VisibilityEmptyDialogs | VisibilityDeletedDialogs | VisibilitySecretChats |
VisibilityUsers | VisibilityChats | VisibilityChannels | VisibilityBots
};
enum SortFlag {
SortByType = 0,
SortByName = 1,
SortByDate = 2,
SortByUnreads = 3,
SortByOnline = 4,
SortByCategories = 5
};
enum DataRoles {
RoleDialogItem = Qt::UserRole,
RoleChatItem,
RoleUserItem,
RoleTopMessageItem,
RolePeerItem,
RolePeerHex,
RoleIsSecretChat,
RoleSecretChatState,
RoleName,
RoleMessageDate,
RoleMessageUnread,
RoleMessage,
RoleMessageOut,
RoleMessageType,
RoleMessageUser,
RoleLastOnline,
RoleIsOnline,
RoleStatus,
RoleStatusText,
RoleTyping,
RoleUnreadCount,
RoleMute,
RoleCategory,
RoleSecretChatStatus
};
enum SecretChatState {
SecretChatStateInit = 0,
SecretChatStateRequested,
SecretChatStateAccepted,
SecretChatStateCancelled
};
TelegramDialogListModel(QObject *parent = 0);
virtual ~TelegramDialogListModel();
int visibility() const;
void setVisibility(int visibility);
QList<qint32> sortFlag() const;
void setSortFlag(const QList<qint32> &sortFlag);
void setFilter(const QString &filter);
QString filter() const;
QJSValue dateConvertorMethod() const;
void setDateConvertorMethod(const QJSValue &method);
QJSValue messageTextMethod() const;
void setMessageTextMethod(const QJSValue &method);
void setUseCache(bool useCache);
bool useCache() const;
QVariantMap categories() const;
void setCategories(const QVariantMap &categories);
QVariantList itemsList() const;
bool refreshing() const;
QByteArray id(const QModelIndex &index) const;
int count() const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QHash<int, QByteArray> roleNames() const;
static QStringList requiredProperties();
Q_SIGNALS:
void visibilityChanged();
void sortFlagChanged();
void filterChanged();
void dateConvertorMethodChanged();
void messageTextMethodChanged();
void refreshingChanged();
void categoriesChanged();
void useCacheChanged();
void itemsListChanged();
public Q_SLOTS:
int indexOf(InputPeerObject *peer);
void clearHistory(InputPeerObject *peer, bool justClear = false, const QJSValue &callback = QJSValue());
void addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber, const QJSValue &callback = QJSValue());
protected:
void refresh();
void clean();
void resort();
void timerEvent(QTimerEvent *e);
virtual QString statusText(const TelegramDialogListItem &item) const;
virtual QString convertDate(const QDateTime &td) const;
virtual QString messageText(class TQmlMessageObject *msg) const;
virtual void connectTelegram();
private:
void getDialogsFromServer(const class InputPeer &offset, qint32 offsetId, qint32 offsetDate, int limit, QHash<QByteArray, TelegramDialogListItem> *items = 0);
void getSecretChats();
void getContactsFromServer();
class InputPeer processOnResult(const class MessagesDialogs &result, QHash<QByteArray, TelegramDialogListItem> *items);
void changed(const QHash<QByteArray, TelegramDialogListItem> &items);
QList<QByteArray> getSortedList(const QHash<QByteArray, TelegramDialogListItem> &items);
void connectChatSignals(const QByteArray &id, class ChatObject *chat);
void connectUserSignals(const QByteArray &id, class UserObject *user);
void connectMessageSignals(const QByteArray &id, class TQmlMessageObject *message);
void connectDialogSignals(const QByteArray &id, class DialogObject *dialog);
virtual void onUpdates(const UpdatesType &update);
void insertUpdate(const Update &update);
void setRefreshing(bool stt);
void clearHistoryAnswer(qint64 msgId, const MessagesAffectedHistory &result);
private:
TelegramDialogListModelPrivate *p;
};
#endif // TELEGRAMDIALOGLISTMODEL_H