Merge lp:~libqtelegram-team/telegram-app/dev-block-users into lp:telegram-app/dev
- dev-block-users
- Merge into libqtelegram-dev
Proposed by
Michał Karnicki
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Giulio Collura | ||||
Approved revision: | 193 | ||||
Merged at revision: | 189 | ||||
Proposed branch: | lp:~libqtelegram-team/telegram-app/dev-block-users | ||||
Merge into: | lp:telegram-app/dev | ||||
Diff against target: |
1843 lines (+923/-344) 24 files modified
lib/telegram.h (+1/-0) lib/types/inputpeer.h (+3/-0) qmlplugin/CMakeLists.txt (+4/-0) qmlplugin/data.cpp (+94/-12) qmlplugin/data.h (+11/-1) qmlplugin/dbmanager.cpp (+15/-1) qmlplugin/dbmanager.h (+1/-0) qmlplugin/dbschema.h (+6/-0) qmlplugin/models/blockedusersmodel.cpp (+74/-0) qmlplugin/models/blockedusersmodel.h (+56/-0) qmlplugin/models/dialogmodel.cpp (+61/-62) qmlplugin/models/dialogmodel.h (+6/-0) qmlplugin/models/groupmodel.cpp (+1/-3) qmlplugin/models/profilemodel.cpp (+366/-197) qmlplugin/models/profilemodel.h (+151/-66) qmlplugin/rawapiclient.cpp (+12/-1) qmlplugin/rawapiclient.h (+4/-1) qmlplugin/rawapiservice.cpp (+2/-0) qmlplugin/rawapiservice.h (+2/-0) qmlplugin/telegramclient.cpp (+3/-0) qmlplugin/telegramclient.h (+3/-0) qmlplugin/telegramplugin.cpp (+4/-0) qmlplugin/telegramservice.cpp (+35/-0) qmlplugin/telegramservice.h (+8/-0) |
||||
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/dev-block-users | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Giulio Collura | Approve | ||
Review via email: mp+254009@code.launchpad.net |
Commit message
Description of the change
Support for blocking users.
- ads user ProfileModel class
- ads blocking capability
To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote : | # |
Revision history for this message
Giulio Collura (gcollura) wrote : | # |
This is perfect too.
I tested it by:
- already have a blocked contact
- install this version
- see that all the already blocked contacts are correctly showed
- block/unblock sync with android (block from android, unblock from ubuntu and vice-versa)
Nicely done!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/telegram.h' | |||
2 | --- lib/telegram.h 2015-03-03 21:38:35 +0000 | |||
3 | +++ lib/telegram.h 2015-03-27 11:52:28 +0000 | |||
4 | @@ -229,6 +229,7 @@ | |||
5 | 229 | // Working with blacklist | 229 | // Working with blacklist |
6 | 230 | void contactsBlockAnswer(qint64 id, bool ok); | 230 | void contactsBlockAnswer(qint64 id, bool ok); |
7 | 231 | void contactsUnblockAnswer(qint64 id, bool ok); | 231 | void contactsUnblockAnswer(qint64 id, bool ok); |
8 | 232 | void contactsBlockResult(qint64 id, bool ok); | ||
9 | 232 | void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); | 233 | void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); |
10 | 233 | 234 | ||
11 | 234 | // Working with messages | 235 | // Working with messages |
12 | 235 | 236 | ||
13 | === modified file 'lib/types/inputpeer.h' | |||
14 | --- lib/types/inputpeer.h 2014-10-03 10:34:51 +0000 | |||
15 | +++ lib/types/inputpeer.h 2015-03-27 11:52:28 +0000 | |||
16 | @@ -41,6 +41,9 @@ | |||
17 | 41 | m_accessHash(0), | 41 | m_accessHash(0), |
18 | 42 | m_classType(classType) {} | 42 | m_classType(classType) {} |
19 | 43 | 43 | ||
20 | 44 | qint32 id() { | ||
21 | 45 | return (m_classType == typeInputPeerChat) ? m_chatId : m_userId; | ||
22 | 46 | } | ||
23 | 44 | void setUserId(qint32 userId) { | 47 | void setUserId(qint32 userId) { |
24 | 45 | m_userId = userId; | 48 | m_userId = userId; |
25 | 46 | } | 49 | } |
26 | 47 | 50 | ||
27 | === modified file 'qmlplugin/CMakeLists.txt' | |||
28 | --- qmlplugin/CMakeLists.txt 2015-02-18 17:53:54 +0000 | |||
29 | +++ qmlplugin/CMakeLists.txt 2015-03-27 11:52:28 +0000 | |||
30 | @@ -40,6 +40,10 @@ | |||
31 | 40 | models/dialogmodel.cpp | 40 | models/dialogmodel.cpp |
32 | 41 | models/groupmembersmodel.h | 41 | models/groupmembersmodel.h |
33 | 42 | models/groupmembersmodel.cpp | 42 | models/groupmembersmodel.cpp |
34 | 43 | models/profilemodel.h | ||
35 | 44 | models/profilemodel.cpp | ||
36 | 45 | models/blockedusersmodel.h | ||
37 | 46 | models/blockedusersmodel.cpp | ||
38 | 43 | models/messagesmodel.cpp | 47 | models/messagesmodel.cpp |
39 | 44 | models/contactsmodel.cpp | 48 | models/contactsmodel.cpp |
40 | 45 | models/dialogsmodel.cpp | 49 | models/dialogsmodel.cpp |
41 | 46 | 50 | ||
42 | === modified file 'qmlplugin/data.cpp' | |||
43 | --- qmlplugin/data.cpp 2015-03-17 11:39:18 +0000 | |||
44 | +++ qmlplugin/data.cpp 2015-03-27 11:52:28 +0000 | |||
45 | @@ -864,6 +864,75 @@ | |||
46 | 864 | qCDebug(TG_PLUGIN_PROFILING) << "onContactsGetContactsAnswer - elapsed time:" << time.elapsed() << "ms"; | 864 | qCDebug(TG_PLUGIN_PROFILING) << "onContactsGetContactsAnswer - elapsed time:" << time.elapsed() << "ms"; |
47 | 865 | } | 865 | } |
48 | 866 | 866 | ||
49 | 867 | void Data::putBlockedUsers(const QList<qint32> ids, const bool replace) { | ||
50 | 868 | if (ids.length() == 0) return; | ||
51 | 869 | |||
52 | 870 | QSqlQuery query; | ||
53 | 871 | if (replace) { | ||
54 | 872 | query.prepare("DELETE FROM blocked_users"); | ||
55 | 873 | query.exec(); | ||
56 | 874 | } | ||
57 | 875 | mDbManager.beginTransaction(); | ||
58 | 876 | query.prepare("REPLACE INTO blockedUsers VALUES(:id)"); | ||
59 | 877 | foreach (const qint32 &id, ids) { | ||
60 | 878 | query.bindValue(":id", id); | ||
61 | 879 | if (!query.exec()) { | ||
62 | 880 | mDbManager.rollbackTransaction(); | ||
63 | 881 | return; | ||
64 | 882 | } | ||
65 | 883 | } | ||
66 | 884 | mDbManager.finishTransaction(); | ||
67 | 885 | } | ||
68 | 886 | |||
69 | 887 | void Data::blockUser(qint32 id) { | ||
70 | 888 | QSqlQuery query; | ||
71 | 889 | query.prepare("REPLACE INTO blockedUsers VALUES(:id)"); | ||
72 | 890 | query.bindValue(":id", id); | ||
73 | 891 | query.exec(); | ||
74 | 892 | Q_EMIT userBlocked(id); | ||
75 | 893 | } | ||
76 | 894 | |||
77 | 895 | void Data::unblockUser(qint32 id) { | ||
78 | 896 | QSqlQuery query; | ||
79 | 897 | query.prepare("DELETE FROM blockedUsers WHERE uid = :id"); | ||
80 | 898 | query.bindValue(":id", id); | ||
81 | 899 | query.exec(); | ||
82 | 900 | Q_EMIT userUnblocked(id); | ||
83 | 901 | } | ||
84 | 902 | |||
85 | 903 | void Data::onGetBlockedContactsAnswer(qint64, qint32, QList<ContactBlocked> blocked, QList<User> users) { | ||
86 | 904 | qCDebug(TG_PLUGIN_LOGIC) << "onGetBlockedContactsAnswer"; | ||
87 | 905 | |||
88 | 906 | mDbManager.beginTransaction(); | ||
89 | 907 | Q_FOREACH (const User &user, users) { | ||
90 | 908 | if (!insertOrUpdateUser(user)) { | ||
91 | 909 | mDbManager.rollbackTransaction(); | ||
92 | 910 | return; | ||
93 | 911 | } | ||
94 | 912 | } | ||
95 | 913 | QList<qint32> blockedUserIds; | ||
96 | 914 | Q_FOREACH (const ContactBlocked &contact, blocked) { | ||
97 | 915 | blockedUserIds.append(contact.userId()); | ||
98 | 916 | } | ||
99 | 917 | putBlockedUsers(blockedUserIds, true); | ||
100 | 918 | mDbManager.finishTransaction(); | ||
101 | 919 | Q_EMIT usersBlocked(blockedUserIds); | ||
102 | 920 | } | ||
103 | 921 | |||
104 | 922 | void Data::onBlockContactAnswer(qint64 requestId, bool ok) { | ||
105 | 923 | qint32 userId = mBlockRequests.take(requestId); | ||
106 | 924 | if (userId != 0 && ok) { | ||
107 | 925 | blockUser(userId); | ||
108 | 926 | } | ||
109 | 927 | } | ||
110 | 928 | |||
111 | 929 | void Data::onUnblockContactsAnswer(qint64 requestId, bool ok) { | ||
112 | 930 | qint32 userId = mBlockRequests.take(requestId); | ||
113 | 931 | if (userId != 0 && ok) { | ||
114 | 932 | unblockUser(userId); | ||
115 | 933 | } | ||
116 | 934 | } | ||
117 | 935 | |||
118 | 867 | void Data::onMessagesGetHistoryAnswer(qint64, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users) { | 936 | void Data::onMessagesGetHistoryAnswer(qint64, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users) { |
119 | 868 | QTime time; | 937 | QTime time; |
120 | 869 | time.start(); | 938 | time.start(); |
121 | @@ -954,7 +1023,9 @@ | |||
122 | 954 | qint32 deleteChatId = mChatsToDelete.take(id); | 1023 | qint32 deleteChatId = mChatsToDelete.take(id); |
123 | 955 | if (deleteChatId != 0) { | 1024 | if (deleteChatId != 0) { |
124 | 956 | qCDebug(TG_PLUGIN_LOGIC) << "deleting chat:" << deleteChatId; | 1025 | qCDebug(TG_PLUGIN_LOGIC) << "deleting chat:" << deleteChatId; |
126 | 957 | deleteDialog(deleteChatId); | 1026 | TelegramService *service = static_cast<TelegramService *>(mServiceRef); |
127 | 1027 | qint32 id = service->deleteChatUser(deleteChatId, service->ourId()); | ||
128 | 1028 | mChatsToDelete.insert(id, service->ourId()); | ||
129 | 958 | } | 1029 | } |
130 | 959 | 1030 | ||
131 | 960 | clientState.setPts(pts); | 1031 | clientState.setPts(pts); |
132 | @@ -1469,15 +1540,21 @@ | |||
133 | 1469 | return; | 1540 | return; |
134 | 1470 | } | 1541 | } |
135 | 1471 | 1542 | ||
136 | 1543 | mDbManager.finishTransaction(); | ||
137 | 1544 | |||
138 | 1545 | Q_FOREACH (const Chat &chat, chats) { | ||
139 | 1546 | Q_EMIT chatUpdated(chat.id()); | ||
140 | 1547 | } | ||
141 | 1548 | |||
142 | 1549 | // handle chat deletion - after self has deleted the chat from UI | ||
143 | 1550 | qint32 chatId = mChatsToDelete.take(id); | ||
144 | 1551 | if (chatId != 0) { | ||
145 | 1552 | deleteChat(chatId); | ||
146 | 1553 | Q_EMIT chatDeleted(chatId); | ||
147 | 1554 | } | ||
148 | 1555 | |||
149 | 1472 | // send signal with the action related message | 1556 | // send signal with the action related message |
150 | 1473 | MessageItem messageItem = getMessage(message.id()); | 1557 | MessageItem messageItem = getMessage(message.id()); |
151 | 1474 | |||
152 | 1475 | mDbManager.finishTransaction(); | ||
153 | 1476 | |||
154 | 1477 | Q_FOREACH (const Chat &chat, chats) { | ||
155 | 1478 | Q_EMIT chatUpdated(chat.id()); | ||
156 | 1479 | } | ||
157 | 1480 | |||
158 | 1481 | Q_EMIT messageAdded(messageItem); | 1558 | Q_EMIT messageAdded(messageItem); |
159 | 1482 | 1559 | ||
160 | 1483 | qCDebug(TG_PLUGIN_PROFILING) << "onMessagesDeleteChatUsersAnswer - end:" << time.elapsed() << "ms"; | 1560 | qCDebug(TG_PLUGIN_PROFILING) << "onMessagesDeleteChatUsersAnswer - end:" << time.elapsed() << "ms"; |
161 | @@ -2593,6 +2670,14 @@ | |||
162 | 2593 | break; | 2670 | break; |
163 | 2594 | } | 2671 | } |
164 | 2595 | 2672 | ||
165 | 2673 | case Update::typeUpdateUserBlocked: { | ||
166 | 2674 | if (update.blocked()) { | ||
167 | 2675 | blockUser(update.userId()); | ||
168 | 2676 | } else { | ||
169 | 2677 | unblockUser(update.userId()); | ||
170 | 2678 | } | ||
171 | 2679 | } | ||
172 | 2680 | |||
173 | 2596 | case Update::typeUpdateNotifySettings: { | 2681 | case Update::typeUpdateNotifySettings: { |
174 | 2597 | NotifyPeer notifyPeer = update.peer(); | 2682 | NotifyPeer notifyPeer = update.peer(); |
175 | 2598 | PeerNotifySettings settings = update.notifySettings(); | 2683 | PeerNotifySettings settings = update.notifySettings(); |
176 | @@ -6319,7 +6404,6 @@ | |||
177 | 6319 | 6404 | ||
178 | 6320 | bool Data::muteDialog(qint32 dialogId, bool muted) { | 6405 | bool Data::muteDialog(qint32 dialogId, bool muted) { |
179 | 6321 | QSqlQuery query(mDbManager.database()); | 6406 | QSqlQuery query(mDbManager.database()); |
180 | 6322 | |||
181 | 6323 | query.prepare("UPDATE dialogs SET muted=:muted WHERE id=:id"); | 6407 | query.prepare("UPDATE dialogs SET muted=:muted WHERE id=:id"); |
182 | 6324 | query.bindValue(":id", dialogId); | 6408 | query.bindValue(":id", dialogId); |
183 | 6325 | query.bindValue(":muted", muted); | 6409 | query.bindValue(":muted", muted); |
184 | @@ -6334,7 +6418,6 @@ | |||
185 | 6334 | 6418 | ||
186 | 6335 | bool Data::muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted) { | 6419 | bool Data::muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted) { |
187 | 6336 | QSqlQuery query(mDbManager.database()); | 6420 | QSqlQuery query(mDbManager.database()); |
188 | 6337 | |||
189 | 6338 | QString condition; | 6421 | QString condition; |
190 | 6339 | switch (peerType) { | 6422 | switch (peerType) { |
191 | 6340 | case NotifyPeer::typeNotifyUsers: | 6423 | case NotifyPeer::typeNotifyUsers: |
192 | @@ -6350,7 +6433,7 @@ | |||
193 | 6350 | return false; | 6433 | return false; |
194 | 6351 | } | 6434 | } |
195 | 6352 | 6435 | ||
197 | 6353 | QString sql = QString("UPDATE dialogs SET muted=:muted").arg(condition); | 6436 | QString sql = QString("UPDATE dialogs SET muted=:muted").append(condition); |
198 | 6354 | query.prepare(sql); | 6437 | query.prepare(sql); |
199 | 6355 | query.bindValue(":muted", muted); | 6438 | query.bindValue(":muted", muted); |
200 | 6356 | if (!query.exec()) { | 6439 | if (!query.exec()) { |
201 | @@ -6358,7 +6441,6 @@ | |||
202 | 6358 | << "for dialogs" << query.lastError() << query.lastQuery(); | 6441 | << "for dialogs" << query.lastError() << query.lastQuery(); |
203 | 6359 | return false; | 6442 | return false; |
204 | 6360 | } | 6443 | } |
205 | 6361 | |||
206 | 6362 | return query.numRowsAffected() > 0; | 6444 | return query.numRowsAffected() > 0; |
207 | 6363 | } | 6445 | } |
208 | 6364 | 6446 | ||
209 | 6365 | 6447 | ||
210 | === modified file 'qmlplugin/data.h' | |||
211 | --- qmlplugin/data.h 2015-03-03 15:30:59 +0000 | |||
212 | +++ qmlplugin/data.h 2015-03-27 11:52:28 +0000 | |||
213 | @@ -191,7 +191,8 @@ | |||
214 | 191 | 191 | ||
215 | 192 | void setMutingInProgress(qint64 requestId, qint32 peerId, bool muting); | 192 | void setMutingInProgress(qint64 requestId, qint32 peerId, bool muting); |
216 | 193 | QMap<qint64, qint32> mChatsToClearHistory; | 193 | QMap<qint64, qint32> mChatsToClearHistory; |
218 | 194 | QMap<qint32, qint32> mChatsToDelete; | 194 | QMap<qint64, qint32> mChatsToDelete; |
219 | 195 | QMap<qint64, qint32> mBlockRequests; | ||
220 | 195 | 196 | ||
221 | 196 | public: | 197 | public: |
222 | 197 | 198 | ||
223 | @@ -201,6 +202,8 @@ | |||
224 | 201 | 202 | ||
225 | 202 | public Q_SLOTS: | 203 | public Q_SLOTS: |
226 | 203 | void setSecretChatMessageTTL(qint32 chatId, qint32 ttlSeconds); | 204 | void setSecretChatMessageTTL(qint32 chatId, qint32 ttlSeconds); |
227 | 205 | void blockUser(qint32 id); | ||
228 | 206 | void unblockUser(qint32 id); | ||
229 | 204 | 207 | ||
230 | 205 | protected: | 208 | protected: |
231 | 206 | void updateChats(const QList<Chat> &chats); | 209 | void updateChats(const QList<Chat> &chats); |
232 | @@ -221,6 +224,9 @@ | |||
233 | 221 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); | 224 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); |
234 | 222 | void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName); | 225 | void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName); |
235 | 223 | void dialogTitleUpdated(qint32 dialogId, const QString &title); | 226 | void dialogTitleUpdated(qint32 dialogId, const QString &title); |
236 | 227 | void usersBlocked(QList<qint32> ids); | ||
237 | 228 | void userBlocked(qint32 id); | ||
238 | 229 | void userUnblocked(qint32 id); | ||
239 | 224 | void dialogMuted(qint32 dialogId, bool muted); | 230 | void dialogMuted(qint32 dialogId, bool muted); |
240 | 225 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); | 231 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); |
241 | 226 | 232 | ||
242 | @@ -359,6 +365,10 @@ | |||
243 | 359 | void onMessagesGetFullChatAnswer(qint64 id, ChatFull chatFull, QList<Chat> chats, QList<User> users); | 365 | void onMessagesGetFullChatAnswer(qint64 id, ChatFull chatFull, QList<Chat> chats, QList<User> users); |
244 | 360 | void onContactsImportContactsAnswer(qint64 id, QList<ImportedContact> importedContacts, QList<qint64> retryContacts, QList<User> users); | 366 | void onContactsImportContactsAnswer(qint64 id, QList<ImportedContact> importedContacts, QList<qint64> retryContacts, QList<User> users); |
245 | 361 | void onContactsGetContactsAnswer(qint64 requestId, bool modified, const QList<Contact> &contacts, const QList<User> &users); | 367 | void onContactsGetContactsAnswer(qint64 requestId, bool modified, const QList<Contact> &contacts, const QList<User> &users); |
246 | 368 | void putBlockedUsers(const QList<qint32> ids, const bool replace); | ||
247 | 369 | void onGetBlockedContactsAnswer(qint64 requestId, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); | ||
248 | 370 | void onBlockContactAnswer(qint64 requestId, bool ok); | ||
249 | 371 | void onUnblockContactsAnswer(qint64 requestId, bool ok); | ||
250 | 362 | void onMessagesGetHistoryAnswer(qint64 requestId, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users); | 372 | void onMessagesGetHistoryAnswer(qint64 requestId, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users); |
251 | 363 | void onMessagesReadHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset); | 373 | void onMessagesReadHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset); |
252 | 364 | void onMessagesDeleteHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset); | 374 | void onMessagesDeleteHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset); |
253 | 365 | 375 | ||
254 | === modified file 'qmlplugin/dbmanager.cpp' | |||
255 | --- qmlplugin/dbmanager.cpp 2015-03-23 10:47:25 +0000 | |||
256 | +++ qmlplugin/dbmanager.cpp 2015-03-27 11:52:28 +0000 | |||
257 | @@ -42,9 +42,10 @@ | |||
258 | 42 | const qint32 VERSION_PROFILE_BIG_PHOTO = 11; | 42 | const qint32 VERSION_PROFILE_BIG_PHOTO = 11; |
259 | 43 | const qint32 VERSION_FORWARD_MESSAGES = 12; | 43 | const qint32 VERSION_FORWARD_MESSAGES = 12; |
260 | 44 | const qint32 VERSION_MEDIA_DOCUMENTS = 13; | 44 | const qint32 VERSION_MEDIA_DOCUMENTS = 13; |
261 | 45 | const qint32 VERSION_BLOCKED_USERS = 14; | ||
262 | 45 | 46 | ||
263 | 46 | // Update this line when creating new upgrade version. | 47 | // Update this line when creating new upgrade version. |
265 | 47 | const qint32 DATABASE_VERSION = VERSION_MEDIA_DOCUMENTS; | 48 | const qint32 DATABASE_VERSION = VERSION_BLOCKED_USERS; |
266 | 48 | 49 | ||
267 | 49 | 50 | ||
268 | 50 | DbManager::DbManager(QObject *parent) : | 51 | DbManager::DbManager(QObject *parent) : |
269 | @@ -169,6 +170,7 @@ | |||
270 | 169 | 170 | ||
271 | 170 | queries << Schema::CREATE_THUMBNAILS; | 171 | queries << Schema::CREATE_THUMBNAILS; |
272 | 171 | queries << Schema::CREATE_USERS; | 172 | queries << Schema::CREATE_USERS; |
273 | 173 | queries << Schema::CREATE_BLOCKED_USERS; | ||
274 | 172 | queries << UpgradeSecretChats::CREATE_SECRET_CHATS; | 174 | queries << UpgradeSecretChats::CREATE_SECRET_CHATS; |
275 | 173 | queries << Schema::CREATE_DIALOGS; | 175 | queries << Schema::CREATE_DIALOGS; |
276 | 174 | queries << Schema::CREATE_CHATS; | 176 | queries << Schema::CREATE_CHATS; |
277 | @@ -218,6 +220,7 @@ | |||
278 | 218 | queries << Schema::DROP_CHATS; | 220 | queries << Schema::DROP_CHATS; |
279 | 219 | queries << Schema::DROP_DIALOGS; | 221 | queries << Schema::DROP_DIALOGS; |
280 | 220 | queries << UpgradeSecretChats::DROP_SECRET_CHATS; | 222 | queries << UpgradeSecretChats::DROP_SECRET_CHATS; |
281 | 223 | queries << Schema::DROP_BLOCKED_USERS; | ||
282 | 221 | queries << Schema::DROP_USERS; | 224 | queries << Schema::DROP_USERS; |
283 | 222 | 225 | ||
284 | 223 | bool result = executeSqlQueries(queries); | 226 | bool result = executeSqlQueries(queries); |
285 | @@ -310,6 +313,9 @@ | |||
286 | 310 | if (!upgradeMediaDocuments()) break; | 313 | if (!upgradeMediaDocuments()) break; |
287 | 311 | case VERSION_MEDIA_DOCUMENTS: | 314 | case VERSION_MEDIA_DOCUMENTS: |
288 | 312 | version = VERSION_MEDIA_DOCUMENTS; | 315 | version = VERSION_MEDIA_DOCUMENTS; |
289 | 316 | if (!upgradeBlockedUsers()) break; | ||
290 | 317 | case VERSION_BLOCKED_USERS: | ||
291 | 318 | version = VERSION_BLOCKED_USERS; | ||
292 | 313 | 319 | ||
293 | 314 | // Upgrade cases go here. | 320 | // Upgrade cases go here. |
294 | 315 | } | 321 | } |
295 | @@ -509,6 +515,14 @@ | |||
296 | 509 | return result; | 515 | return result; |
297 | 510 | } | 516 | } |
298 | 511 | 517 | ||
299 | 518 | bool DbManager::upgradeBlockedUsers() { | ||
300 | 519 | qCDebug(LOG_DATABASE) << "Upgrading database: adding blocked users"; | ||
301 | 520 | |||
302 | 521 | QStringList queries; | ||
303 | 522 | queries << Schema::CREATE_BLOCKED_USERS; | ||
304 | 523 | return executeSqlQueries(queries); | ||
305 | 524 | } | ||
306 | 525 | |||
307 | 512 | bool DbManager::purgeButSecret() { | 526 | bool DbManager::purgeButSecret() { |
308 | 513 | qCDebug(LOG_DATABASE) << "Purging database but secret chats data..."; | 527 | qCDebug(LOG_DATABASE) << "Purging database but secret chats data..."; |
309 | 514 | 528 | ||
310 | 515 | 529 | ||
311 | === modified file 'qmlplugin/dbmanager.h' | |||
312 | --- qmlplugin/dbmanager.h 2015-02-25 21:25:07 +0000 | |||
313 | +++ qmlplugin/dbmanager.h 2015-03-27 11:52:28 +0000 | |||
314 | @@ -67,6 +67,7 @@ | |||
315 | 67 | bool upgradeProfilesBigPhotos(); | 67 | bool upgradeProfilesBigPhotos(); |
316 | 68 | bool upgradeForwardMessages(); | 68 | bool upgradeForwardMessages(); |
317 | 69 | bool upgradeMediaDocuments(); | 69 | bool upgradeMediaDocuments(); |
318 | 70 | bool upgradeBlockedUsers(); | ||
319 | 70 | 71 | ||
320 | 71 | private: | 72 | private: |
321 | 72 | QString mDatabasePath; | 73 | QString mDatabasePath; |
322 | 73 | 74 | ||
323 | === modified file 'qmlplugin/dbschema.h' | |||
324 | --- qmlplugin/dbschema.h 2015-03-10 15:32:48 +0000 | |||
325 | +++ qmlplugin/dbschema.h 2015-03-27 11:52:28 +0000 | |||
326 | @@ -259,6 +259,12 @@ | |||
327 | 259 | 259 | ||
328 | 260 | const QString DROP_MESSAGE_ACTIONS("DROP TABLE IF EXISTS messageActions"); | 260 | const QString DROP_MESSAGE_ACTIONS("DROP TABLE IF EXISTS messageActions"); |
329 | 261 | 261 | ||
330 | 262 | const QString CREATE_BLOCKED_USERS("CREATE TABLE blockedUsers(\n" | ||
331 | 263 | " uid INTEGER PRIMARY KEY\n" | ||
332 | 264 | ")"); | ||
333 | 265 | |||
334 | 266 | const QString DROP_BLOCKED_USERS("DROP TABLE IF EXISTS blockedUsers"); | ||
335 | 267 | |||
336 | 262 | } | 268 | } |
337 | 263 | 269 | ||
338 | 264 | namespace MessageActionsRemovePhotoId { | 270 | namespace MessageActionsRemovePhotoId { |
339 | 265 | 271 | ||
340 | === added file 'qmlplugin/models/blockedusersmodel.cpp' | |||
341 | --- qmlplugin/models/blockedusersmodel.cpp 1970-01-01 00:00:00 +0000 | |||
342 | +++ qmlplugin/models/blockedusersmodel.cpp 2015-03-27 11:52:28 +0000 | |||
343 | @@ -0,0 +1,74 @@ | |||
344 | 1 | /* | ||
345 | 2 | * Copyright 2015 Canonical Ltd. | ||
346 | 3 | * | ||
347 | 4 | * This program is free software; you can redistribute it and/or modify | ||
348 | 5 | * it under the terms of the GNU General Public License as published by | ||
349 | 6 | * the Free Software Foundation; version 3. | ||
350 | 7 | * | ||
351 | 8 | * This program is distributed in the hope that it will be useful, | ||
352 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
353 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
354 | 11 | * GNU General Public License for more details. | ||
355 | 12 | * | ||
356 | 13 | * You should have received a copy of the GNU General Public License | ||
357 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
358 | 15 | */ | ||
359 | 16 | |||
360 | 17 | #include "blockedusersmodel.h" | ||
361 | 18 | |||
362 | 19 | #include "types/tluser.h" | ||
363 | 20 | #include "types/tlinputpeer.h" | ||
364 | 21 | |||
365 | 22 | BlockedUsersModel::BlockedUsersModel(QObject *parent) : | ||
366 | 23 | Model(parent), mTelegramClient(NULL) { | ||
367 | 24 | } | ||
368 | 25 | |||
369 | 26 | BlockedUsersModel::~BlockedUsersModel() { | ||
370 | 27 | disconnect(mTelegramClient); | ||
371 | 28 | mTelegramClient = NULL; | ||
372 | 29 | } | ||
373 | 30 | |||
374 | 31 | void BlockedUsersModel::setup(TelegramClient *telegramClient) { | ||
375 | 32 | Q_ASSERT(telegramClient != NULL); | ||
376 | 33 | |||
377 | 34 | if (mTelegramClient == NULL) { | ||
378 | 35 | mTelegramClient = telegramClient; | ||
379 | 36 | connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)), | ||
380 | 37 | this, SLOT(refresh(QList<qint32>))); | ||
381 | 38 | connect(mTelegramClient, SIGNAL(userBlocked(qint32)), | ||
382 | 39 | this, SLOT(userBlocked(qint32))); | ||
383 | 40 | connect(mTelegramClient, SIGNAL(userUnblocked(qint32)), | ||
384 | 41 | this, SLOT(userUnblocked(qint32))); | ||
385 | 42 | } | ||
386 | 43 | refresh(); | ||
387 | 44 | } | ||
388 | 45 | |||
389 | 46 | void BlockedUsersModel::refresh(QList<qint32> ids) { | ||
390 | 47 | if (mTelegramClient == NULL) return; | ||
391 | 48 | mQueryString = QString( | ||
392 | 49 | "SELECT id, type, " | ||
393 | 50 | " (SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS photo, " | ||
394 | 51 | " (firstName || \" \" || lastName) AS name, " | ||
395 | 52 | " online, lastSeenOnline " | ||
396 | 53 | "FROM users JOIN blockedUsers ON users.id = blockedUsers.uid"); | ||
397 | 54 | Model::refresh(); | ||
398 | 55 | } | ||
399 | 56 | |||
400 | 57 | void BlockedUsersModel::userBlocked(qint32 id) { | ||
401 | 58 | refresh(); | ||
402 | 59 | } | ||
403 | 60 | |||
404 | 61 | void BlockedUsersModel::userUnblocked(qint32 id) { | ||
405 | 62 | refresh(); | ||
406 | 63 | } | ||
407 | 64 | |||
408 | 65 | QHash<int, QByteArray> BlockedUsersModel::roleNames() const { | ||
409 | 66 | QHash<int, QByteArray> roles; | ||
410 | 67 | roles[IdRole] = "id"; | ||
411 | 68 | roles[TypeRole] = "type"; | ||
412 | 69 | roles[PhotoRole] = "photo"; | ||
413 | 70 | roles[NameRole] = "name"; | ||
414 | 71 | roles[OnlineRole] = "online"; | ||
415 | 72 | roles[LastSeenOnlineRole] = "lastSeenOnline"; | ||
416 | 73 | return roles; | ||
417 | 74 | } | ||
418 | 0 | 75 | ||
419 | === added file 'qmlplugin/models/blockedusersmodel.h' | |||
420 | --- qmlplugin/models/blockedusersmodel.h 1970-01-01 00:00:00 +0000 | |||
421 | +++ qmlplugin/models/blockedusersmodel.h 2015-03-27 11:52:28 +0000 | |||
422 | @@ -0,0 +1,56 @@ | |||
423 | 1 | /* | ||
424 | 2 | * Copyright 2014 Canonical Ltd. | ||
425 | 3 | * | ||
426 | 4 | * This program is free software; you can redistribute it and/or modify | ||
427 | 5 | * it under the terms of the GNU General Public License as published by | ||
428 | 6 | * the Free Software Foundation; version 3. | ||
429 | 7 | * | ||
430 | 8 | * This program is distributed in the hope that it will be useful, | ||
431 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
432 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
433 | 11 | * GNU General Public License for more details. | ||
434 | 12 | * | ||
435 | 13 | * You should have received a copy of the GNU General Public License | ||
436 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
437 | 15 | */ | ||
438 | 16 | |||
439 | 17 | #ifndef BLOCKED_USERS_MODEL_H | ||
440 | 18 | #define BLOCKED_USERS_MODEL_H | ||
441 | 19 | |||
442 | 20 | #include <QLoggingCategory> | ||
443 | 21 | |||
444 | 22 | #include "model.h" | ||
445 | 23 | #include "telegramclient.h" | ||
446 | 24 | |||
447 | 25 | class BlockedUsersModel : public Model | ||
448 | 26 | { | ||
449 | 27 | Q_OBJECT | ||
450 | 28 | Q_ENUMS(BlockedUsersRoles) | ||
451 | 29 | public: | ||
452 | 30 | |||
453 | 31 | enum BlockedUsersRoles { | ||
454 | 32 | IdRole = Qt::UserRole, | ||
455 | 33 | TypeRole, | ||
456 | 34 | PhotoRole, | ||
457 | 35 | NameRole, | ||
458 | 36 | OnlineRole, | ||
459 | 37 | LastSeenOnlineRole | ||
460 | 38 | }; | ||
461 | 39 | |||
462 | 40 | explicit BlockedUsersModel(QObject *parent = 0); | ||
463 | 41 | ~BlockedUsersModel(); | ||
464 | 42 | |||
465 | 43 | Q_INVOKABLE void setup(TelegramClient *telegramClient); | ||
466 | 44 | |||
467 | 45 | public Q_SLOTS: | ||
468 | 46 | void refresh(QList<qint32> ids = QList<qint32>()); | ||
469 | 47 | void userBlocked(qint32 id); | ||
470 | 48 | void userUnblocked(qint32 id); | ||
471 | 49 | |||
472 | 50 | private: | ||
473 | 51 | TelegramClient *mTelegramClient; | ||
474 | 52 | |||
475 | 53 | QHash<qint32, QByteArray> roleNames() const; | ||
476 | 54 | }; | ||
477 | 55 | |||
478 | 56 | #endif // BLOCKED_USERS_MODEL_H | ||
479 | 0 | 57 | ||
480 | === modified file 'qmlplugin/models/dialogmodel.cpp' | |||
481 | --- qmlplugin/models/dialogmodel.cpp 2015-02-04 22:29:48 +0000 | |||
482 | +++ qmlplugin/models/dialogmodel.cpp 2015-03-27 11:52:28 +0000 | |||
483 | @@ -25,6 +25,7 @@ | |||
484 | 25 | mChatId(0), | 25 | mChatId(0), |
485 | 26 | mPeerId(0), | 26 | mPeerId(0), |
486 | 27 | mPeerType((qint32) InputPeer::typeInputPeerContact), | 27 | mPeerType((qint32) InputPeer::typeInputPeerContact), |
487 | 28 | mAccessHash(0), | ||
488 | 28 | mWhoIsTyping(""), | 29 | mWhoIsTyping(""), |
489 | 29 | mIsTyping(false), | 30 | mIsTyping(false), |
490 | 30 | mIsSecret(false), | 31 | mIsSecret(false), |
491 | @@ -44,12 +45,13 @@ | |||
492 | 44 | setChatId(0); | 45 | setChatId(0); |
493 | 45 | setPeerId(0); | 46 | setPeerId(0); |
494 | 46 | setPeerType((qint32) InputPeer::typeInputPeerContact); | 47 | setPeerType((qint32) InputPeer::typeInputPeerContact); |
495 | 48 | setAccessHash(0); | ||
496 | 47 | setIsChat(false); | 49 | setIsChat(false); |
497 | 48 | setIsTyping(false); | 50 | setIsTyping(false); |
498 | 49 | setIsSecret(false); | 51 | setIsSecret(false); |
499 | 50 | setState(0); | 52 | setState(0); |
502 | 51 | setTitle(QString()); | 53 | setTitle(""); |
503 | 52 | setPhone(QString()); | 54 | setPhone(""); |
504 | 53 | setTtl(0); | 55 | setTtl(0); |
505 | 54 | } | 56 | } |
506 | 55 | 57 | ||
507 | @@ -76,9 +78,7 @@ | |||
508 | 76 | // TODO karni: hook up live state | 78 | // TODO karni: hook up live state |
509 | 77 | } | 79 | } |
510 | 78 | 80 | ||
514 | 79 | if (mTelegramClient != NULL) { | 81 | setChatId(chatId); |
512 | 80 | setChatId(chatId); | ||
513 | 81 | } | ||
515 | 82 | } | 82 | } |
516 | 83 | 83 | ||
517 | 84 | void DialogModel::onMessageReceived(const MessageItem &message) { | 84 | void DialogModel::onMessageReceived(const MessageItem &message) { |
518 | @@ -92,13 +92,10 @@ | |||
519 | 92 | } | 92 | } |
520 | 93 | 93 | ||
521 | 94 | void DialogModel::setChatId(qint32 chatId) { | 94 | void DialogModel::setChatId(qint32 chatId) { |
529 | 95 | if (mChatId != chatId) { | 95 | if (mChatId == chatId) return; |
530 | 96 | mChatId = chatId; | 96 | mChatId = chatId; |
531 | 97 | if (chatId != 0) { | 97 | refreshDialogDetails(chatId); |
532 | 98 | refreshDialogDetails(chatId); | 98 | Q_EMIT chatIdChanged(chatId); |
526 | 99 | } | ||
527 | 100 | Q_EMIT chatIdChanged(chatId); | ||
528 | 101 | } | ||
533 | 102 | } | 99 | } |
534 | 103 | 100 | ||
535 | 104 | qint32 DialogModel::getPeerId() const { | 101 | qint32 DialogModel::getPeerId() const { |
536 | @@ -106,10 +103,9 @@ | |||
537 | 106 | } | 103 | } |
538 | 107 | 104 | ||
539 | 108 | void DialogModel::setPeerId(qint32 peerId) { | 105 | void DialogModel::setPeerId(qint32 peerId) { |
544 | 109 | if (mPeerId != peerId) { | 106 | if (mPeerId == peerId) return; |
545 | 110 | mPeerId = peerId; | 107 | mPeerId = peerId; |
546 | 111 | Q_EMIT peerIdChanged(peerId); | 108 | Q_EMIT peerIdChanged(peerId); |
543 | 112 | } | ||
547 | 113 | } | 109 | } |
548 | 114 | 110 | ||
549 | 115 | qint32 DialogModel::getPeerType() const { | 111 | qint32 DialogModel::getPeerType() const { |
550 | @@ -117,10 +113,19 @@ | |||
551 | 117 | } | 113 | } |
552 | 118 | 114 | ||
553 | 119 | void DialogModel::setPeerType(qint32 peerType) { | 115 | void DialogModel::setPeerType(qint32 peerType) { |
558 | 120 | if (mPeerType != peerType) { | 116 | if (mPeerType == peerType) return; |
559 | 121 | mPeerType = peerType; | 117 | mPeerType = peerType; |
560 | 122 | Q_EMIT peerTypeChanged(peerType); | 118 | Q_EMIT peerTypeChanged(peerType); |
561 | 123 | } | 119 | } |
562 | 120 | |||
563 | 121 | qint64 DialogModel::getAccessHash() const { | ||
564 | 122 | return mAccessHash; | ||
565 | 123 | } | ||
566 | 124 | |||
567 | 125 | void DialogModel::setAccessHash(qint64 accessHash) { | ||
568 | 126 | if (mAccessHash == accessHash) return; | ||
569 | 127 | mAccessHash = accessHash; | ||
570 | 128 | Q_EMIT accessHashChanged(accessHash); | ||
571 | 124 | } | 129 | } |
572 | 125 | 130 | ||
573 | 126 | bool DialogModel::getIsChat() const { | 131 | bool DialogModel::getIsChat() const { |
574 | @@ -128,10 +133,9 @@ | |||
575 | 128 | } | 133 | } |
576 | 129 | 134 | ||
577 | 130 | void DialogModel::setIsChat(bool isChat) { | 135 | void DialogModel::setIsChat(bool isChat) { |
582 | 131 | if (mIsChat != isChat) { | 136 | if (mIsChat == isChat) return; |
583 | 132 | mIsChat = isChat; | 137 | mIsChat = isChat; |
584 | 133 | Q_EMIT isChatChanged(isChat); | 138 | Q_EMIT isChatChanged(isChat); |
581 | 134 | } | ||
585 | 135 | } | 139 | } |
586 | 136 | 140 | ||
587 | 137 | QString DialogModel::getWhoIsTyping() const { | 141 | QString DialogModel::getWhoIsTyping() const { |
588 | @@ -139,10 +143,9 @@ | |||
589 | 139 | } | 143 | } |
590 | 140 | 144 | ||
591 | 141 | void DialogModel::setWhoIsTyping(QString whoIsTyping) { | 145 | void DialogModel::setWhoIsTyping(QString whoIsTyping) { |
596 | 142 | if (mWhoIsTyping != whoIsTyping) { | 146 | if (mWhoIsTyping == whoIsTyping) return; |
597 | 143 | mWhoIsTyping = whoIsTyping; | 147 | mWhoIsTyping = whoIsTyping; |
598 | 144 | Q_EMIT whoIsTypingChanged(whoIsTyping); | 148 | Q_EMIT whoIsTypingChanged(whoIsTyping); |
595 | 145 | } | ||
599 | 146 | } | 149 | } |
600 | 147 | 150 | ||
601 | 148 | bool DialogModel::getIsTyping() const { | 151 | bool DialogModel::getIsTyping() const { |
602 | @@ -160,10 +163,9 @@ | |||
603 | 160 | } | 163 | } |
604 | 161 | 164 | ||
605 | 162 | void DialogModel::setIsSecret(bool isSecret) { | 165 | void DialogModel::setIsSecret(bool isSecret) { |
610 | 163 | if (mIsSecret != isSecret) { | 166 | if (mIsSecret == isSecret) return; |
611 | 164 | mIsSecret = isSecret; | 167 | mIsSecret = isSecret; |
612 | 165 | Q_EMIT isSecretChanged(isSecret); | 168 | Q_EMIT isSecretChanged(isSecret); |
609 | 166 | } | ||
613 | 167 | } | 169 | } |
614 | 168 | 170 | ||
615 | 169 | qint32 DialogModel::getState() const { | 171 | qint32 DialogModel::getState() const { |
616 | @@ -171,10 +173,9 @@ | |||
617 | 171 | } | 173 | } |
618 | 172 | 174 | ||
619 | 173 | void DialogModel::setState(qint32 state) { | 175 | void DialogModel::setState(qint32 state) { |
624 | 174 | if (mState != state) { | 176 | if (mState == state) return; |
625 | 175 | mState = state; | 177 | mState = state; |
626 | 176 | Q_EMIT stateChanged(state); | 178 | Q_EMIT stateChanged(state); |
623 | 177 | } | ||
627 | 178 | } | 179 | } |
628 | 179 | 180 | ||
629 | 180 | QString DialogModel::getTitle() const { | 181 | QString DialogModel::getTitle() const { |
630 | @@ -182,10 +183,9 @@ | |||
631 | 182 | } | 183 | } |
632 | 183 | 184 | ||
633 | 184 | void DialogModel::setTitle(const QString &title) { | 185 | void DialogModel::setTitle(const QString &title) { |
638 | 185 | if (mTitle != title) { | 186 | if (mTitle == title) return; |
639 | 186 | mTitle = title; | 187 | mTitle = title; |
640 | 187 | Q_EMIT titleChanged(title); | 188 | Q_EMIT titleChanged(title); |
637 | 188 | } | ||
641 | 189 | } | 189 | } |
642 | 190 | 190 | ||
643 | 191 | QString DialogModel::getPhone() const { | 191 | QString DialogModel::getPhone() const { |
644 | @@ -193,10 +193,9 @@ | |||
645 | 193 | } | 193 | } |
646 | 194 | 194 | ||
647 | 195 | void DialogModel::setPhone(QString phone) { | 195 | void DialogModel::setPhone(QString phone) { |
652 | 196 | if (mPhone != phone) { | 196 | if (mPhone == phone) return; |
653 | 197 | mPhone = phone; | 197 | mPhone = phone; |
654 | 198 | Q_EMIT phoneChanged(phone); | 198 | Q_EMIT phoneChanged(phone); |
651 | 199 | } | ||
655 | 200 | } | 199 | } |
656 | 201 | 200 | ||
657 | 202 | qint32 DialogModel::getTtl() const { | 201 | qint32 DialogModel::getTtl() const { |
658 | @@ -204,10 +203,9 @@ | |||
659 | 204 | } | 203 | } |
660 | 205 | 204 | ||
661 | 206 | void DialogModel::setTtl(qint32 ttl) { | 205 | void DialogModel::setTtl(qint32 ttl) { |
666 | 207 | if (mTtl != ttl) { | 206 | if (mTtl == ttl) return; |
667 | 208 | mTtl = ttl; | 207 | mTtl = ttl; |
668 | 209 | Q_EMIT ttlChanged(ttl); | 208 | Q_EMIT ttlChanged(ttl); |
665 | 210 | } | ||
669 | 211 | } | 209 | } |
670 | 212 | 210 | ||
671 | 213 | void DialogModel::refreshDialogDetails(qint32 chatId) { | 211 | void DialogModel::refreshDialogDetails(qint32 chatId) { |
672 | @@ -215,9 +213,12 @@ | |||
673 | 215 | qCDebug(TG_PLUGIN_LOGIC) << "Querying dialog details" << chatId; | 213 | qCDebug(TG_PLUGIN_LOGIC) << "Querying dialog details" << chatId; |
674 | 216 | 214 | ||
675 | 217 | QSqlQuery query; | 215 | QSqlQuery query; |
679 | 218 | query.prepare(QString("SELECT id, isChat, name, thumbnail, members, userOnline, " | 216 | query.prepare(QString("SELECT dialogsView.id, isChat, name, dialogsView.thumbnail, members, userOnline, " |
680 | 219 | "lastSeenOnline, peerId, peerType, date, isSecret, state, ttl " | 217 | "dialogsView.lastSeenOnline, peerId, peerType, date, isSecret, state, ttl, " |
681 | 220 | "FROM dialogsView WHERE id = %1").arg(QString::number(chatId))); | 218 | "coalesce(users.type, 0) as type, coalesce(users.accessHash, 0) as accessHash " |
682 | 219 | "FROM dialogsView " | ||
683 | 220 | " LEFT JOIN users ON dialogsView.id = users.id " | ||
684 | 221 | "WHERE dialogsView.id = %1").arg(QString::number(chatId))); | ||
685 | 221 | 222 | ||
686 | 222 | // query.bindValue(":chatId", chatId); // no worky? | 223 | // query.bindValue(":chatId", chatId); // no worky? |
687 | 223 | 224 | ||
688 | @@ -243,14 +244,14 @@ | |||
689 | 243 | } | 244 | } |
690 | 244 | 245 | ||
691 | 245 | setIsChat(false); | 246 | setIsChat(false); |
692 | 246 | |||
693 | 247 | setIsSecret(false); | 247 | setIsSecret(false); |
694 | 248 | |||
695 | 249 | qint32 userType = query.value("type").toInt(); | 248 | qint32 userType = query.value("type").toInt(); |
696 | 250 | setPeerType(Tools::toInputPeerType((User::UserType) userType)); | 249 | setPeerType(Tools::toInputPeerType((User::UserType) userType)); |
697 | 251 | |||
698 | 252 | setPeerId(chatId); | 250 | setPeerId(chatId); |
700 | 253 | 251 | qint64 accessHash = query.value("accessHash").toLongLong(); | |
701 | 252 | if (accessHash != 0) { | ||
702 | 253 | setAccessHash(accessHash); | ||
703 | 254 | } | ||
704 | 254 | setState(0); | 255 | setState(0); |
705 | 255 | 256 | ||
706 | 256 | QString firstName; | 257 | QString firstName; |
707 | @@ -276,24 +277,22 @@ | |||
708 | 276 | 277 | ||
709 | 277 | bool isChat = query.value("isChat").toBool(); | 278 | bool isChat = query.value("isChat").toBool(); |
710 | 278 | setIsChat(isChat); | 279 | setIsChat(isChat); |
711 | 279 | |||
712 | 280 | bool isSecret = query.value("isSecret").toBool(); | 280 | bool isSecret = query.value("isSecret").toBool(); |
713 | 281 | setIsSecret(isSecret); | 281 | setIsSecret(isSecret); |
714 | 282 | |||
715 | 283 | if (isSecret) { | 282 | if (isSecret) { |
716 | 284 | qint32 ttl = query.value("ttl").toInt(); | 283 | qint32 ttl = query.value("ttl").toInt(); |
717 | 285 | setTtl(ttl); | 284 | setTtl(ttl); |
718 | 286 | } | 285 | } |
719 | 287 | |||
720 | 288 | qint32 userType = query.value("peerType").toInt(); | 286 | qint32 userType = query.value("peerType").toInt(); |
721 | 289 | setPeerType(Tools::toInputPeerType((User::UserType) userType)); | 287 | setPeerType(Tools::toInputPeerType((User::UserType) userType)); |
722 | 290 | |||
723 | 291 | qint32 peerId = query.value("peerId").toInt(); | 288 | qint32 peerId = query.value("peerId").toInt(); |
726 | 292 | setPeerId(isSecret ? peerId : chatId); // *sigh* | 289 | setPeerId(isSecret ? peerId : chatId); |
727 | 293 | 290 | qint64 accessHash = query.value("accessHash").toLongLong(); | |
728 | 291 | if (accessHash != 0) { | ||
729 | 292 | setAccessHash(accessHash); | ||
730 | 293 | } | ||
731 | 294 | qint32 state = query.value("state").toInt(); | 294 | qint32 state = query.value("state").toInt(); |
732 | 295 | setState(state); | 295 | setState(state); |
733 | 296 | |||
734 | 297 | QString title = query.value("name").toString(); | 296 | QString title = query.value("name").toString(); |
735 | 298 | setTitle(title); | 297 | setTitle(title); |
736 | 299 | 298 | ||
737 | 300 | 299 | ||
738 | === modified file 'qmlplugin/models/dialogmodel.h' | |||
739 | --- qmlplugin/models/dialogmodel.h 2015-02-04 19:01:38 +0000 | |||
740 | +++ qmlplugin/models/dialogmodel.h 2015-03-27 11:52:28 +0000 | |||
741 | @@ -32,6 +32,7 @@ | |||
742 | 32 | Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged) | 32 | Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged) |
743 | 33 | Q_PROPERTY(qint32 peerId READ getPeerId NOTIFY peerIdChanged) | 33 | Q_PROPERTY(qint32 peerId READ getPeerId NOTIFY peerIdChanged) |
744 | 34 | Q_PROPERTY(qint32 peerType READ getPeerType NOTIFY peerTypeChanged) | 34 | Q_PROPERTY(qint32 peerType READ getPeerType NOTIFY peerTypeChanged) |
745 | 35 | Q_PROPERTY(qint64 accessHash READ getAccessHash NOTIFY accessHashChanged) | ||
746 | 35 | Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged) | 36 | Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged) |
747 | 36 | Q_PROPERTY(QString whoIsTyping READ getWhoIsTyping NOTIFY whoIsTypingChanged) | 37 | Q_PROPERTY(QString whoIsTyping READ getWhoIsTyping NOTIFY whoIsTypingChanged) |
748 | 37 | Q_PROPERTY(bool isTyping READ getIsTyping NOTIFY isTypingChanged) | 38 | Q_PROPERTY(bool isTyping READ getIsTyping NOTIFY isTypingChanged) |
749 | @@ -57,6 +58,9 @@ | |||
750 | 57 | qint32 getPeerType() const; | 58 | qint32 getPeerType() const; |
751 | 58 | void setPeerType(qint32 classType); | 59 | void setPeerType(qint32 classType); |
752 | 59 | 60 | ||
753 | 61 | qint64 getAccessHash() const; | ||
754 | 62 | void setAccessHash(qint64 accessHash); | ||
755 | 63 | |||
756 | 60 | bool getIsChat() const; | 64 | bool getIsChat() const; |
757 | 61 | void setIsChat(bool isChat); | 65 | void setIsChat(bool isChat); |
758 | 62 | 66 | ||
759 | @@ -95,6 +99,7 @@ | |||
760 | 95 | void chatIdChanged(qint32 chatId); | 99 | void chatIdChanged(qint32 chatId); |
761 | 96 | void peerIdChanged(qint32 peerId); | 100 | void peerIdChanged(qint32 peerId); |
762 | 97 | void peerTypeChanged(qint32 peerType); | 101 | void peerTypeChanged(qint32 peerType); |
763 | 102 | void accessHashChanged(qint64 accessHash); | ||
764 | 98 | void peerChanged(qint32 peerId, qint32 peerType); | 103 | void peerChanged(qint32 peerId, qint32 peerType); |
765 | 99 | void isChatChanged(bool isChat); | 104 | void isChatChanged(bool isChat); |
766 | 100 | void whoIsTypingChanged(QString who); | 105 | void whoIsTypingChanged(QString who); |
767 | @@ -111,6 +116,7 @@ | |||
768 | 111 | qint32 mChatId; | 116 | qint32 mChatId; |
769 | 112 | qint32 mPeerId; | 117 | qint32 mPeerId; |
770 | 113 | qint32 mPeerType; | 118 | qint32 mPeerType; |
771 | 119 | qint64 mAccessHash; | ||
772 | 114 | bool mIsChat; | 120 | bool mIsChat; |
773 | 115 | bool mIsTyping; | 121 | bool mIsTyping; |
774 | 116 | QString mWhoIsTyping; | 122 | QString mWhoIsTyping; |
775 | 117 | 123 | ||
776 | === modified file 'qmlplugin/models/groupmodel.cpp' | |||
777 | --- qmlplugin/models/groupmodel.cpp 2015-02-16 18:07:13 +0000 | |||
778 | +++ qmlplugin/models/groupmodel.cpp 2015-03-27 11:52:28 +0000 | |||
779 | @@ -40,9 +40,7 @@ | |||
780 | 40 | this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool))); | 40 | this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool))); |
781 | 41 | } | 41 | } |
782 | 42 | 42 | ||
786 | 43 | if (mTelegramClient != NULL) { | 43 | setChatId(chatId); |
784 | 44 | setChatId(chatId); | ||
785 | 45 | } | ||
787 | 46 | } | 44 | } |
788 | 47 | 45 | ||
789 | 48 | qint32 GroupModel::getChatId() const { | 46 | qint32 GroupModel::getChatId() const { |
790 | 49 | 47 | ||
791 | === modified file 'qmlplugin/models/profilemodel.cpp' | |||
792 | --- qmlplugin/models/profilemodel.cpp 2015-02-18 17:53:54 +0000 | |||
793 | +++ qmlplugin/models/profilemodel.cpp 2015-03-27 11:52:28 +0000 | |||
794 | @@ -1,220 +1,389 @@ | |||
795 | 1 | /* | ||
796 | 2 | * Copyright 2015 Canonical Ltd. | ||
797 | 3 | * | ||
798 | 4 | * This program is free software; you can redistribute it and/or modify | ||
799 | 5 | * it under the terms of the GNU General Public License as published by | ||
800 | 6 | * the Free Software Foundation; version 3. | ||
801 | 7 | * | ||
802 | 8 | * This program is distributed in the hope that it will be useful, | ||
803 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
804 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
805 | 11 | * GNU General Public License for more details. | ||
806 | 12 | * | ||
807 | 13 | * You should have received a copy of the GNU General Public License | ||
808 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
809 | 15 | */ | ||
810 | 16 | |||
811 | 1 | #include "profilemodel.h" | 17 | #include "profilemodel.h" |
825 | 2 | 18 | #include "tools.h" | |
826 | 3 | Q_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL, "tg.models.profilemodel") | 19 | |
827 | 4 | 20 | ProfileModel::ProfileModel(QObject *parent) : QObject(parent), | |
828 | 5 | ProfileModel::ProfileModel(QObject *parent) : | 21 | mTelegramClient(NULL), mDialogId(0), mUserId(0), mChatId(0), mIsSecret(true), |
829 | 6 | QObject(parent), | 22 | mThumbnail(""), mPhoto(""), mTitle(""), mFirstName(""), mLastName(""), |
830 | 7 | mTelegramClient(0), | 23 | mPhone(""), mHasPhone(false), mLastSeen(0), mIsOnline(false), |
831 | 8 | mUserId(0), | 24 | mIsMuted(false), mIsBlocked(false) { |
819 | 9 | mFirstName(""), | ||
820 | 10 | mLastName(""), | ||
821 | 11 | mThumbnail(""), | ||
822 | 12 | mBigPhoto(""), | ||
823 | 13 | mLastSeenOnline(0), | ||
824 | 14 | mOnline(false) { | ||
832 | 15 | } | 25 | } |
833 | 16 | 26 | ||
834 | 17 | ProfileModel::~ProfileModel() { | 27 | ProfileModel::~ProfileModel() { |
835 | 28 | disconnect(mTelegramClient); | ||
836 | 18 | mTelegramClient = 0; | 29 | mTelegramClient = 0; |
837 | 19 | } | 30 | } |
838 | 20 | 31 | ||
855 | 21 | void ProfileModel::reset() { | 32 | void ProfileModel::setup(TelegramClient *telegramClient, qint32 dialogId) { |
856 | 22 | mTelegramClient = 0, | 33 | Q_ASSERT(telegramClient != NULL); |
857 | 23 | setUserId(0), | 34 | |
858 | 24 | setFirstName(""); | 35 | if (mTelegramClient == NULL) { |
843 | 25 | setLastName(""); | ||
844 | 26 | setThumbnail(""); | ||
845 | 27 | setBigPhoto(""); | ||
846 | 28 | setLastSeenOnline(0); | ||
847 | 29 | setOnline(false); | ||
848 | 30 | } | ||
849 | 31 | |||
850 | 32 | void ProfileModel::setup(TelegramClient *telegramClient, qint32 userId) { | ||
851 | 33 | |||
852 | 34 | Q_ASSERT(telegramClient); | ||
853 | 35 | |||
854 | 36 | if (!mTelegramClient) { | ||
859 | 37 | mTelegramClient = telegramClient; | 36 | mTelegramClient = telegramClient; |
944 | 38 | connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)), SLOT(onContactNameUpdated(qint32,QString,QString))); | 37 | |
945 | 39 | connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)), SLOT(onContactThumbnailUpdated(qint32,QString))); | 38 | connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)), |
946 | 40 | connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)), SLOT(onContactBigPhotoUpdated(qint32,QString))); | 39 | this, SLOT(contactNameUpdated(qint32,QString,QString))); |
947 | 41 | connect(mTelegramClient, SIGNAL(contactStatusUpdated(qint32,bool,qint32)), SLOT(onContactStatusUpdated(qint32,bool,qint32))); | 40 | |
948 | 42 | } | 41 | connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)), |
949 | 43 | 42 | this, SLOT(thumbnailChanged(qint32,QString))); | |
950 | 44 | if (mTelegramClient) { | 43 | connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)), |
951 | 45 | setUserId(userId); | 44 | this, SLOT(photoChanged(qint32,QString))); |
952 | 46 | } | 45 | |
953 | 47 | } | 46 | connect(mTelegramClient, SIGNAL(dialogMuted(qint32,bool)), |
954 | 48 | 47 | this, SLOT(dialogMuted(qint32,bool))); | |
955 | 49 | void ProfileModel::refresh(qint32 userId) { | 48 | connect(mTelegramClient, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), |
956 | 50 | 49 | this, SLOT(dialogsMuted(NotifyPeer::NotifyPeerType,bool))); | |
957 | 51 | if (userId != mUserId) { | 50 | |
958 | 52 | return; | 51 | connect(mTelegramClient, SIGNAL(userBlocked(qint32)), |
959 | 53 | } | 52 | this, SLOT(userBlocked(qint32))); |
960 | 54 | 53 | connect(mTelegramClient, SIGNAL(userUnblocked(qint32)), | |
961 | 55 | QSqlQuery query; | 54 | this, SLOT(userUnblocked(qint32))); |
962 | 56 | query.prepare("SELECT firstName, lastName, phone, lastSeenOnline, online, " | 55 | connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)), |
963 | 57 | "(SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS thumbnail, " | 56 | this, SLOT(usersBlocked(QList<qint32>))); |
964 | 58 | "(SELECT localPath FROM fileLocations WHERE rowid=bigPhoto) AS bigPhoto " | 57 | } |
965 | 59 | "FROM users " | 58 | |
966 | 60 | "WHERE id=:id"); | 59 | setDialogId(dialogId); |
967 | 61 | query.bindValue(":id", userId); | 60 | } |
968 | 62 | if (!query.exec()) { | 61 | |
969 | 63 | qCCritical(TG_MODELS_PROFILEMODEL) << "Could not get profile data for user" << userId | 62 | void ProfileModel::downloadPhoto() { |
970 | 64 | << query.lastError() << query.lastQuery(); | 63 | qCDebug(TG_PLUGIN_LOGIC) << "downloading profile photo"; |
971 | 65 | return; | 64 | mTelegramClient->downloadUserBigPhoto(mUserId); |
972 | 66 | } | 65 | } |
973 | 67 | 66 | ||
974 | 68 | if (!query.next()) { | 67 | qint32 ProfileModel::getDialogId() const { |
975 | 69 | qCCritical(TG_MODELS_PROFILEMODEL) << "Could not find a register related to user" << userId; | 68 | return mDialogId; |
976 | 70 | return; | 69 | } |
977 | 71 | } | 70 | |
978 | 72 | 71 | void ProfileModel::setDialogId(qint32 dialogId) { | |
979 | 73 | setFirstName(query.value("firstName").toString()); | 72 | if (mDialogId == dialogId) return; |
980 | 74 | setLastName(query.value("lastName").toString()); | 73 | mDialogId = dialogId; |
981 | 75 | setPhone(query.value("phone").toString()); | 74 | refreshProfile(dialogId); |
982 | 76 | setThumbnail(query.value("thumbnail").toString()); | 75 | Q_EMIT dialogIdChanged(dialogId); |
983 | 77 | setBigPhoto(query.value("bigPhoto").toString()); | 76 | |
984 | 78 | setLastSeenOnline(query.value("lastSeenOnline").toInt()); | 77 | // TBD We'll probably want to call getFullUser and getFullChat (for chat members) here. |
985 | 79 | setOnline(query.value("online").toBool()); | 78 | } |
986 | 80 | 79 | ||
987 | 81 | Q_EMIT refreshed(); | 80 | qint32 ProfileModel::getUserId() const { |
904 | 82 | } | ||
905 | 83 | |||
906 | 84 | void ProfileModel::onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName) { | ||
907 | 85 | |||
908 | 86 | if (mUserId != userId) { | ||
909 | 87 | return; | ||
910 | 88 | } | ||
911 | 89 | |||
912 | 90 | setFirstName(firstName); | ||
913 | 91 | setLastName(lastName); | ||
914 | 92 | } | ||
915 | 93 | |||
916 | 94 | void ProfileModel::onContactThumbnailUpdated(qint32 userId, const QString &thumbnail) { | ||
917 | 95 | |||
918 | 96 | if (mUserId != userId) { | ||
919 | 97 | return; | ||
920 | 98 | } | ||
921 | 99 | setThumbnail(thumbnail); | ||
922 | 100 | } | ||
923 | 101 | |||
924 | 102 | void ProfileModel::onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto) { | ||
925 | 103 | |||
926 | 104 | if (mUserId != userId) { | ||
927 | 105 | return; | ||
928 | 106 | } | ||
929 | 107 | |||
930 | 108 | setBigPhoto(bigPhoto); | ||
931 | 109 | } | ||
932 | 110 | |||
933 | 111 | void ProfileModel::onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline) { | ||
934 | 112 | |||
935 | 113 | if (mUserId != userId) { | ||
936 | 114 | return; | ||
937 | 115 | } | ||
938 | 116 | |||
939 | 117 | setOnline(online); | ||
940 | 118 | setLastSeenOnline(lastSeenOnline); | ||
941 | 119 | } | ||
942 | 120 | |||
943 | 121 | qint32 ProfileModel::userId() const { | ||
988 | 122 | return mUserId; | 81 | return mUserId; |
989 | 123 | } | 82 | } |
990 | 124 | 83 | ||
991 | 125 | void ProfileModel::setUserId(qint32 userId) { | 84 | void ProfileModel::setUserId(qint32 userId) { |
1002 | 126 | if (mUserId != userId) { | 85 | if (mUserId == userId) return; |
1003 | 127 | mUserId = userId; | 86 | mUserId = userId; |
1004 | 128 | if (userId) { | 87 | Q_EMIT userIdChanged(userId); |
1005 | 129 | refresh(userId); | 88 | } |
1006 | 130 | } | 89 | |
1007 | 131 | Q_EMIT userIdChanged(userId); | 90 | qint32 ProfileModel::getChatId() const { |
1008 | 132 | } | 91 | return mChatId; |
1009 | 133 | } | 92 | } |
1010 | 134 | 93 | ||
1011 | 135 | QString ProfileModel::firstName() const { | 94 | void ProfileModel::setChatId(qint32 chatId) { |
1012 | 95 | if (mChatId == chatId) return; | ||
1013 | 96 | mChatId = chatId; | ||
1014 | 97 | Q_EMIT chatIdChanged(chatId); | ||
1015 | 98 | } | ||
1016 | 99 | |||
1017 | 100 | void ProfileModel::setUserType(qint32 userType) { | ||
1018 | 101 | if (mUserType == userType) return; | ||
1019 | 102 | mUserType = userType; | ||
1020 | 103 | Q_EMIT userTypeChanged(userType); | ||
1021 | 104 | |||
1022 | 105 | Q_EMIT existsChanged(getExists()); | ||
1023 | 106 | } | ||
1024 | 107 | |||
1025 | 108 | bool ProfileModel::getIsSecret() const { | ||
1026 | 109 | return mIsSecret; | ||
1027 | 110 | } | ||
1028 | 111 | |||
1029 | 112 | bool ProfileModel::getExists() const { | ||
1030 | 113 | return ((User::UserType)mUserType) != User::typeUserDeleted; | ||
1031 | 114 | } | ||
1032 | 115 | |||
1033 | 116 | void ProfileModel::setIsSecret(bool isSecret) { | ||
1034 | 117 | if (mIsSecret == isSecret) return; | ||
1035 | 118 | mIsSecret = isSecret; | ||
1036 | 119 | Q_EMIT isSecretChanged(isSecret); | ||
1037 | 120 | } | ||
1038 | 121 | |||
1039 | 122 | QString ProfileModel::getThumbnail() const { | ||
1040 | 123 | return mThumbnail; | ||
1041 | 124 | } | ||
1042 | 125 | |||
1043 | 126 | void ProfileModel::setThumbnail(const QString &thumbnail) { | ||
1044 | 127 | if (mThumbnail == thumbnail) return; | ||
1045 | 128 | mThumbnail = thumbnail; | ||
1046 | 129 | Q_EMIT thumbnailChanged(thumbnail); | ||
1047 | 130 | } | ||
1048 | 131 | |||
1049 | 132 | QString ProfileModel::getPhoto() const { | ||
1050 | 133 | return mPhoto; | ||
1051 | 134 | } | ||
1052 | 135 | |||
1053 | 136 | void ProfileModel::setPhoto(const QString &photo) { | ||
1054 | 137 | if (mPhoto == photo) return; | ||
1055 | 138 | mPhoto = photo; | ||
1056 | 139 | Q_EMIT photoChanged(photo); | ||
1057 | 140 | } | ||
1058 | 141 | |||
1059 | 142 | QString ProfileModel::getTitle() const { | ||
1060 | 143 | return mTitle; | ||
1061 | 144 | } | ||
1062 | 145 | |||
1063 | 146 | void ProfileModel::setTitle(const QString &title) { | ||
1064 | 147 | if (mTitle == title) return; | ||
1065 | 148 | mTitle = title; | ||
1066 | 149 | Q_EMIT titleChanged(title); | ||
1067 | 150 | } | ||
1068 | 151 | |||
1069 | 152 | QString ProfileModel::getFirstName() const { | ||
1070 | 136 | return mFirstName; | 153 | return mFirstName; |
1071 | 137 | } | 154 | } |
1072 | 138 | 155 | ||
1082 | 139 | void ProfileModel::setFirstName(const QString &firstName) { | 156 | QString ProfileModel::getLastName() const { |
1074 | 140 | if (mFirstName != firstName) { | ||
1075 | 141 | mFirstName = firstName; | ||
1076 | 142 | Q_EMIT firstNameChanged(firstName); | ||
1077 | 143 | Q_EMIT fullNameChanged(fullName()); | ||
1078 | 144 | } | ||
1079 | 145 | } | ||
1080 | 146 | |||
1081 | 147 | QString ProfileModel::lastName() const { | ||
1083 | 148 | return mLastName; | 157 | return mLastName; |
1084 | 149 | } | 158 | } |
1085 | 150 | 159 | ||
1103 | 151 | void ProfileModel::setLastName(const QString &lastName) { | 160 | QString ProfileModel::getPhone() const { |
1087 | 152 | if (mLastName != lastName) { | ||
1088 | 153 | mLastName = lastName; | ||
1089 | 154 | Q_EMIT lastNameChanged(lastName); | ||
1090 | 155 | Q_EMIT fullNameChanged(fullName()); | ||
1091 | 156 | } | ||
1092 | 157 | } | ||
1093 | 158 | |||
1094 | 159 | QString ProfileModel::fullName() const { | ||
1095 | 160 | QString fullName = mFirstName; | ||
1096 | 161 | if (!mLastName.isEmpty()) { | ||
1097 | 162 | fullName += " " + mLastName; | ||
1098 | 163 | } | ||
1099 | 164 | return fullName; | ||
1100 | 165 | } | ||
1101 | 166 | |||
1102 | 167 | QString ProfileModel::phone() const { | ||
1104 | 168 | return mPhone; | 161 | return mPhone; |
1105 | 169 | } | 162 | } |
1106 | 170 | 163 | ||
1107 | 171 | void ProfileModel::setPhone(const QString &phone) { | 164 | void ProfileModel::setPhone(const QString &phone) { |
1156 | 172 | if (mPhone != phone) { | 165 | if (mPhone == phone) return; |
1157 | 173 | mPhone = phone; | 166 | mPhone = phone; |
1158 | 174 | Q_EMIT phoneChanged(phone); | 167 | mHasPhone = mPhone.length() > 0; |
1159 | 175 | } | 168 | Q_EMIT phoneChanged(phone); |
1160 | 176 | } | 169 | Q_EMIT hasPhoneChanged(mHasPhone); |
1161 | 177 | 170 | } | |
1162 | 178 | QString ProfileModel::thumbnail() const { | 171 | |
1163 | 179 | return mThumbnail; | 172 | bool ProfileModel::getHasPhone() const { |
1164 | 180 | } | 173 | return mHasPhone; |
1165 | 181 | 174 | } | |
1166 | 182 | void ProfileModel::setThumbnail(const QString &thumbnail) { | 175 | |
1167 | 183 | if (mThumbnail != thumbnail) { | 176 | qint32 ProfileModel::getLastSeen() const { |
1168 | 184 | mThumbnail = thumbnail; | 177 | return mLastSeen; |
1169 | 185 | Q_EMIT thumbnailChanged(thumbnail); | 178 | } |
1170 | 186 | } | 179 | |
1171 | 187 | } | 180 | void ProfileModel::setLastSeen(qint32 lastSeen) { |
1172 | 188 | 181 | if (mLastSeen == lastSeen) return; | |
1173 | 189 | QString ProfileModel::bigPhoto() const { | 182 | mLastSeen = lastSeen; |
1174 | 190 | return mBigPhoto; | 183 | Q_EMIT lastSeenChanged(lastSeen); |
1175 | 191 | } | 184 | } |
1176 | 192 | 185 | ||
1177 | 193 | void ProfileModel::setBigPhoto(const QString &bigPhoto) { | 186 | bool ProfileModel::getIsOnline() const { |
1178 | 194 | if (mBigPhoto != bigPhoto) { | 187 | return mIsOnline; |
1179 | 195 | mBigPhoto = bigPhoto; | 188 | } |
1180 | 196 | Q_EMIT bigPhotoChanged(bigPhoto); | 189 | |
1181 | 197 | } | 190 | void ProfileModel::setIsOnline(bool isOnline) { |
1182 | 198 | } | 191 | if (mIsOnline == isOnline) return; |
1183 | 199 | 192 | mIsOnline = isOnline; | |
1184 | 200 | qint32 ProfileModel::lastSeenOnline() const { | 193 | Q_EMIT isOnlineChanged(isOnline); |
1185 | 201 | return mLastSeenOnline; | 194 | } |
1186 | 202 | } | 195 | |
1187 | 203 | 196 | bool ProfileModel::getIsMuted() const { | |
1188 | 204 | void ProfileModel::setLastSeenOnline(qint32 lastSeenOnline) { | 197 | return mIsMuted; |
1189 | 205 | if (mLastSeenOnline != lastSeenOnline) { | 198 | } |
1190 | 206 | mLastSeenOnline = lastSeenOnline; | 199 | |
1191 | 207 | Q_EMIT lastSeenOnlineChanged(lastSeenOnline); | 200 | void ProfileModel::setIsMuted(bool isMuted) { |
1192 | 208 | } | 201 | if (mIsMuted == isMuted) return; |
1193 | 209 | } | 202 | qCDebug(TG_PLUGIN_LOGIC) << "setIsMuted"; |
1194 | 210 | 203 | mIsMuted = isMuted; | |
1195 | 211 | bool ProfileModel::online() const { | 204 | Q_EMIT isMutedChanged(isMuted); |
1196 | 212 | return mOnline; | 205 | } |
1197 | 213 | } | 206 | |
1198 | 214 | 207 | void ProfileModel::setIsBlocked(bool isBlocked) { | |
1199 | 215 | void ProfileModel::setOnline(bool online) { | 208 | if (mIsBlocked == isBlocked) return; |
1200 | 216 | if (mOnline != online) { | 209 | qCDebug(TG_PLUGIN_LOGIC) << "setIsBlocked"; |
1201 | 217 | mOnline = online; | 210 | mIsBlocked = isBlocked; |
1202 | 218 | Q_EMIT onlineChanged(online); | 211 | Q_EMIT isBlockedChanged(isBlocked); |
1203 | 219 | } | 212 | } |
1204 | 213 | |||
1205 | 214 | bool ProfileModel::getIsBlocked() const { | ||
1206 | 215 | return mIsBlocked; | ||
1207 | 216 | } | ||
1208 | 217 | |||
1209 | 218 | void ProfileModel::resetProfile() { | ||
1210 | 219 | mDialogId = 0; | ||
1211 | 220 | setChatId(0); | ||
1212 | 221 | setUserId(0); | ||
1213 | 222 | |||
1214 | 223 | setThumbnail(""); | ||
1215 | 224 | setPhoto(""); | ||
1216 | 225 | setTitle(""); | ||
1217 | 226 | mFirstName = ""; | ||
1218 | 227 | mLastName = ""; | ||
1219 | 228 | |||
1220 | 229 | setLastSeen(0); | ||
1221 | 230 | setIsOnline(false); | ||
1222 | 231 | setIsMuted(false); | ||
1223 | 232 | setIsBlocked(false); | ||
1224 | 233 | } | ||
1225 | 234 | |||
1226 | 235 | QString formatFullName(const QString &firstName, const QString &lastName) { | ||
1227 | 236 | QString full(firstName); | ||
1228 | 237 | if (full.length() > 0) { | ||
1229 | 238 | full = full.append(" "); | ||
1230 | 239 | } | ||
1231 | 240 | return full.append(lastName); | ||
1232 | 241 | } | ||
1233 | 242 | |||
1234 | 243 | void ProfileModel::refreshUserProfile() { | ||
1235 | 244 | QSqlQuery query; | ||
1236 | 245 | query.prepare(QString( | ||
1237 | 246 | "SELECT " | ||
1238 | 247 | " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = thumbnail) as thumbnail, " | ||
1239 | 248 | " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = bigPhoto) AS photo, " | ||
1240 | 249 | " users.id, phone, firstName, lastName, lastSeenOnline, online, " | ||
1241 | 250 | " type, accessHash, " | ||
1242 | 251 | " coalesce(dialogs.muted, 0) as muted, " | ||
1243 | 252 | " coalesce(blockedUsers.uid, 0) as blocked " | ||
1244 | 253 | "FROM users " | ||
1245 | 254 | " LEFT JOIN dialogs ON users.id = dialogs.id " | ||
1246 | 255 | " LEFT JOIN blockedUsers ON users.id = blockedUsers.uid " | ||
1247 | 256 | "WHERE users.id = :id")); | ||
1248 | 257 | query.bindValue(":id", mUserId); | ||
1249 | 258 | |||
1250 | 259 | if (!query.exec()) { | ||
1251 | 260 | qCCritical(TG_PLUGIN_LOGIC) << "Failed to query user details!" | ||
1252 | 261 | << query.lastError() << query.lastQuery(); | ||
1253 | 262 | resetProfile(); | ||
1254 | 263 | return; | ||
1255 | 264 | } else if (query.next()) { | ||
1256 | 265 | qint32 userType = query.value("type").toInt(); | ||
1257 | 266 | setUserType(userType); | ||
1258 | 267 | mAccessHash = query.value("accessHash").toLongLong(); | ||
1259 | 268 | |||
1260 | 269 | QString thumbnail = query.value("thumbnail").toString(); | ||
1261 | 270 | setThumbnail(thumbnail); | ||
1262 | 271 | QString photo = query.value("photo").toString(); | ||
1263 | 272 | setPhoto(photo); | ||
1264 | 273 | mFirstName = query.value("firstName").toString(); | ||
1265 | 274 | mLastName = query.value("lastName").toString(); | ||
1266 | 275 | QString title = formatFullName(mFirstName, mLastName); | ||
1267 | 276 | setTitle(title); | ||
1268 | 277 | QString phone = query.value("phone").toString(); | ||
1269 | 278 | setPhone(phone); | ||
1270 | 279 | qint32 lastSeen = query.value("lastSeenOnline").toInt(); | ||
1271 | 280 | setLastSeen(lastSeen); | ||
1272 | 281 | bool isOnline = query.value("online").toBool(); | ||
1273 | 282 | setIsOnline(isOnline); | ||
1274 | 283 | bool isMuted = query.value("muted").toBool(); | ||
1275 | 284 | setIsMuted(isMuted); | ||
1276 | 285 | bool isBlocked = query.value("blocked").toInt() != 0; | ||
1277 | 286 | setIsBlocked(isBlocked); | ||
1278 | 287 | |||
1279 | 288 | /* | ||
1280 | 289 | // TODO replace getBlockedContacts with getFullUser | ||
1281 | 290 | InputUser::InputUserType inputUserType = Tools::toInputUserType(mUserType); | ||
1282 | 291 | InputUser inputUser(inputUserType); | ||
1283 | 292 | inputUser.setUserId(mUserId); | ||
1284 | 293 | if (mAccessHash != 0) { | ||
1285 | 294 | inputUser.setAccessHash(mAccessHash); | ||
1286 | 295 | } | ||
1287 | 296 | mTelegramClient->getFullUser(inputUser); | ||
1288 | 297 | */ | ||
1289 | 298 | mTelegramClient->getBlockedContacts(); | ||
1290 | 299 | } | ||
1291 | 300 | } | ||
1292 | 301 | |||
1293 | 302 | void ProfileModel::refreshGroupProfile() { | ||
1294 | 303 | // TODO: Merge groupmodel into this class. | ||
1295 | 304 | } | ||
1296 | 305 | |||
1297 | 306 | void ProfileModel::refreshProfile(qint32 dialogId) { | ||
1298 | 307 | if (mDialogId != dialogId) return; | ||
1299 | 308 | qCDebug(TG_PLUGIN_LOGIC) << "Refreshing profile for dialog:" << dialogId; | ||
1300 | 309 | |||
1301 | 310 | QSqlQuery query; | ||
1302 | 311 | query.prepare(QString("SELECT isChat, isSecret, peerId FROM dialogsView WHERE id = :id")); | ||
1303 | 312 | query.bindValue(":id", dialogId); | ||
1304 | 313 | |||
1305 | 314 | if (!query.exec()) { | ||
1306 | 315 | qCCritical(TG_PLUGIN_LOGIC) << "Failed to query profile type!" | ||
1307 | 316 | << query.lastError() << query.lastQuery(); | ||
1308 | 317 | resetProfile(); | ||
1309 | 318 | return; | ||
1310 | 319 | } | ||
1311 | 320 | |||
1312 | 321 | bool isChat = false; | ||
1313 | 322 | if (query.next()) { | ||
1314 | 323 | isChat = query.value("isChat").toBool(); | ||
1315 | 324 | if (isChat) { | ||
1316 | 325 | setChatId(dialogId); | ||
1317 | 326 | } else { | ||
1318 | 327 | bool isSecret = query.value("isSecret").toBool(); | ||
1319 | 328 | setIsSecret(isSecret); | ||
1320 | 329 | setUserId(isSecret ? query.value("peerId").toInt() : dialogId); | ||
1321 | 330 | } | ||
1322 | 331 | } else { | ||
1323 | 332 | setUserId(dialogId); | ||
1324 | 333 | } | ||
1325 | 334 | |||
1326 | 335 | if (isChat) { | ||
1327 | 336 | refreshGroupProfile(); | ||
1328 | 337 | } else { | ||
1329 | 338 | refreshUserProfile(); | ||
1330 | 339 | } | ||
1331 | 340 | } | ||
1332 | 341 | |||
1333 | 342 | void ProfileModel::contactNameUpdated(qint32 userId, QString firstName, QString lastName) { | ||
1334 | 343 | if (mUserId != userId) return; | ||
1335 | 344 | |||
1336 | 345 | mFirstName = firstName; | ||
1337 | 346 | mLastName = lastName; | ||
1338 | 347 | if (lastName.length() == 0) { | ||
1339 | 348 | setTitle(firstName); | ||
1340 | 349 | } else { | ||
1341 | 350 | setTitle(firstName.append(" ").append(lastName)); | ||
1342 | 351 | } | ||
1343 | 352 | } | ||
1344 | 353 | |||
1345 | 354 | void ProfileModel::thumbnailChanged(qint32 dialogId, QString thumbnail) { | ||
1346 | 355 | if (mDialogId != dialogId) return; | ||
1347 | 356 | setThumbnail(thumbnail); | ||
1348 | 357 | } | ||
1349 | 358 | |||
1350 | 359 | void ProfileModel::photoChanged(qint32 dialogId, QString photo) { | ||
1351 | 360 | if (mDialogId != dialogId) return; | ||
1352 | 361 | setPhoto(photo); | ||
1353 | 362 | } | ||
1354 | 363 | |||
1355 | 364 | void ProfileModel::dialogMuted(qint32 dialogId, bool muted) { | ||
1356 | 365 | if (mDialogId != dialogId) return; | ||
1357 | 366 | setIsMuted(muted); | ||
1358 | 367 | } | ||
1359 | 368 | |||
1360 | 369 | void ProfileModel::dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted) { | ||
1361 | 370 | if (notifyType == NotifyPeer::typeNotifyAll || | ||
1362 | 371 | notifyType == NotifyPeer::typeNotifyChats) { | ||
1363 | 372 | setIsMuted(muted); | ||
1364 | 373 | } | ||
1365 | 374 | } | ||
1366 | 375 | |||
1367 | 376 | void ProfileModel::usersBlocked(QList<qint32> ids) { | ||
1368 | 377 | bool isBlocked = ids.indexOf(mUserId) != -1; | ||
1369 | 378 | setIsBlocked(isBlocked); | ||
1370 | 379 | } | ||
1371 | 380 | |||
1372 | 381 | void ProfileModel::userBlocked(qint32 uid) { | ||
1373 | 382 | if (mUserId != uid) return; | ||
1374 | 383 | setIsBlocked(true); | ||
1375 | 384 | } | ||
1376 | 385 | |||
1377 | 386 | void ProfileModel::userUnblocked(qint32 uid) { | ||
1378 | 387 | if (mUserId != uid) return; | ||
1379 | 388 | setIsBlocked(false); | ||
1380 | 220 | } | 389 | } |
1381 | 221 | 390 | ||
1382 | === modified file 'qmlplugin/models/profilemodel.h' | |||
1383 | --- qmlplugin/models/profilemodel.h 2015-02-18 17:53:54 +0000 | |||
1384 | +++ qmlplugin/models/profilemodel.h 2015-03-27 11:52:28 +0000 | |||
1385 | @@ -1,84 +1,169 @@ | |||
1388 | 1 | #ifndef PROFILEMODEL_H | 1 | /* |
1389 | 2 | #define PROFILEMODEL_H | 2 | * Copyright 2015 Canonical Ltd. |
1390 | 3 | * | ||
1391 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1392 | 5 | * it under the terms of the GNU General Public License as published by | ||
1393 | 6 | * the Free Software Foundation; version 3. | ||
1394 | 7 | * | ||
1395 | 8 | * This program is distributed in the hope that it will be useful, | ||
1396 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1397 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1398 | 11 | * GNU General Public License for more details. | ||
1399 | 12 | * | ||
1400 | 13 | * You should have received a copy of the GNU General Public License | ||
1401 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1402 | 15 | */ | ||
1403 | 16 | |||
1404 | 17 | #ifndef PROFILE_MODEL_H | ||
1405 | 18 | #define PROFILE_MODEL_H | ||
1406 | 3 | 19 | ||
1407 | 4 | #include <QObject> | 20 | #include <QObject> |
1409 | 5 | #include <QLoggingCategory> | 21 | #include <QString> |
1410 | 22 | |||
1411 | 6 | #include "telegramclient.h" | 23 | #include "telegramclient.h" |
1415 | 7 | 24 | #include "dbmanager.h" | |
1413 | 8 | |||
1414 | 9 | Q_DECLARE_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL) | ||
1416 | 10 | 25 | ||
1417 | 11 | class ProfileModel : public QObject | 26 | class ProfileModel : public QObject |
1418 | 12 | { | 27 | { |
1419 | 13 | Q_OBJECT | 28 | Q_OBJECT |
1429 | 14 | Q_PROPERTY(qint32 userId READ userId NOTIFY userIdChanged) | 29 | Q_PROPERTY(qint32 dialogId READ getDialogId WRITE setDialogId NOTIFY dialogIdChanged) |
1430 | 15 | Q_PROPERTY(QString firstName READ firstName NOTIFY firstNameChanged) | 30 | Q_PROPERTY(qint32 userId READ getUserId NOTIFY userIdChanged) |
1431 | 16 | Q_PROPERTY(QString lastName READ lastName NOTIFY lastNameChanged) | 31 | Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged) |
1432 | 17 | Q_PROPERTY(QString fullName READ fullName NOTIFY fullNameChanged) | 32 | Q_PROPERTY(bool isSecret READ getIsSecret NOTIFY isSecretChanged) |
1433 | 18 | Q_PROPERTY(QString phone READ phone NOTIFY phoneChanged) | 33 | Q_PROPERTY(bool exists READ getExists NOTIFY existsChanged) |
1434 | 19 | Q_PROPERTY(QString thumbnail READ thumbnail NOTIFY thumbnailChanged) | 34 | |
1435 | 20 | Q_PROPERTY(QString bigPhoto READ bigPhoto NOTIFY bigPhotoChanged) | 35 | Q_PROPERTY(QString thumbnail READ getThumbnail NOTIFY thumbnailChanged) |
1436 | 21 | Q_PROPERTY(qint32 lastSeenOnline READ lastSeenOnline NOTIFY lastSeenOnlineChanged) | 36 | Q_PROPERTY(QString photo READ getPhoto NOTIFY photoChanged) |
1437 | 22 | Q_PROPERTY(bool online READ online NOTIFY onlineChanged) | 37 | Q_PROPERTY(QString title READ getTitle NOTIFY titleChanged) |
1438 | 38 | Q_PROPERTY(QString firstName READ getFirstName) | ||
1439 | 39 | Q_PROPERTY(QString lastName READ getLastName) | ||
1440 | 40 | Q_PROPERTY(QString phone READ getPhone NOTIFY phoneChanged) | ||
1441 | 41 | Q_PROPERTY(bool hasPhone READ getHasPhone NOTIFY phoneChanged) | ||
1442 | 42 | |||
1443 | 43 | // Q_PROPERTY(QString memberCount READ getMemberCount NOTIFY memberCountChanged) | ||
1444 | 44 | // Q_PROPERTY(qint32 onlineCount READ getOnlineCount NOTIFY onlineCountChanged) | ||
1445 | 45 | |||
1446 | 46 | Q_PROPERTY(qint32 lastSeen READ getLastSeen NOTIFY lastSeenChanged) | ||
1447 | 47 | Q_PROPERTY(bool isOnline READ getIsOnline NOTIFY isOnlineChanged) | ||
1448 | 48 | |||
1449 | 49 | Q_PROPERTY(bool isMuted READ getIsMuted NOTIFY isMutedChanged) | ||
1450 | 50 | Q_PROPERTY(bool isBlocked READ getIsBlocked NOTIFY isBlockedChanged) | ||
1451 | 23 | 51 | ||
1452 | 24 | public: | 52 | public: |
1453 | 25 | explicit ProfileModel(QObject *parent = 0); | 53 | explicit ProfileModel(QObject *parent = 0); |
1454 | 26 | ~ProfileModel(); | 54 | ~ProfileModel(); |
1455 | 27 | 55 | ||
1502 | 28 | Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 userId); | 56 | Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 dialogId); |
1503 | 29 | void reset(); | 57 | Q_INVOKABLE void downloadPhoto(); |
1504 | 30 | 58 | void resetProfile(); | |
1505 | 31 | QString fullName() const; | 59 | |
1506 | 32 | 60 | void setDialogId(qint32 dialogId); | |
1507 | 33 | virtual qint32 userId() const; | 61 | qint32 getDialogId() const; |
1508 | 34 | virtual void setUserId(qint32 userId); | 62 | qint32 getUserId() const; |
1509 | 35 | virtual QString firstName() const; | 63 | qint32 getChatId() const; |
1510 | 36 | virtual void setFirstName(const QString &firstName); | 64 | bool getIsSecret() const; |
1511 | 37 | virtual QString lastName() const; | 65 | bool getExists() const; |
1512 | 38 | virtual void setLastName(const QString &lastName); | 66 | |
1513 | 39 | virtual QString phone() const; | 67 | QString getThumbnail() const; |
1514 | 40 | virtual void setPhone(const QString &phone); | 68 | QString getPhoto() const; |
1515 | 41 | virtual QString thumbnail() const; | 69 | QString getTitle() const; |
1516 | 42 | virtual void setThumbnail(const QString &thumbnail); | 70 | QString getFirstName() const; |
1517 | 43 | virtual QString bigPhoto() const; | 71 | QString getLastName() const; |
1518 | 44 | virtual void setBigPhoto(const QString &bigPhoto); | 72 | QString getPhone() const; |
1519 | 45 | virtual qint32 lastSeenOnline() const; | 73 | bool getHasPhone() const; |
1520 | 46 | virtual void setLastSeenOnline(qint32 lastSeenOnline); | 74 | |
1521 | 47 | virtual bool online() const; | 75 | // qint32 getMemberCount() const; |
1522 | 48 | virtual void setOnline(bool online); | 76 | // qint32 getOnlineCount() const; |
1523 | 49 | 77 | ||
1524 | 50 | Q_SIGNALS: | 78 | qint32 getLastSeen() const; |
1525 | 51 | void refreshed(); | 79 | bool getIsOnline() const; |
1526 | 52 | 80 | ||
1527 | 53 | void userIdChanged(qint32); | 81 | bool getIsMuted() const; |
1528 | 54 | void firstNameChanged(QString); | 82 | bool getIsBlocked() const; |
1529 | 55 | void lastNameChanged(QString); | 83 | |
1530 | 56 | void fullNameChanged(QString); | 84 | public Q_SLOTS: |
1531 | 57 | void phoneChanged(QString); | 85 | void refreshProfile(qint32 dialogId); |
1532 | 58 | void thumbnailChanged(QString); | 86 | |
1533 | 59 | void bigPhotoChanged(QString); | 87 | void contactNameUpdated(qint32 userId, QString firstName, QString lastName); |
1534 | 60 | void lastSeenOnlineChanged(qint32); | 88 | void thumbnailChanged(qint32 dialogId, QString thumbnail); |
1535 | 61 | void onlineChanged(bool); | 89 | void photoChanged(qint32 dialogId, QString photo); |
1536 | 62 | 90 | void dialogMuted(qint32 dialogId, bool muted); | |
1537 | 63 | protected Q_SLOTS: | 91 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); |
1538 | 64 | void refresh(qint32 userId); | 92 | void usersBlocked(QList<qint32> ids); |
1539 | 65 | 93 | void userBlocked(qint32 uid); | |
1540 | 66 | void onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName); | 94 | void userUnblocked(qint32 uid); |
1541 | 67 | void onContactThumbnailUpdated(qint32 userId, const QString &thumbnail); | 95 | |
1542 | 68 | void onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto); | 96 | Q_SIGNALS: |
1543 | 69 | void onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline); | 97 | void profileDetailsRefreshed(); |
1544 | 70 | 98 | ||
1545 | 71 | protected: | 99 | private: |
1546 | 72 | TelegramClient *mTelegramClient; | 100 | void setUserId(qint32 userId); |
1547 | 73 | 101 | void setChatId(qint32 chatId); | |
1548 | 102 | void setUserType(qint32 type); | ||
1549 | 103 | void setIsSecret(bool isSecret); | ||
1550 | 104 | |||
1551 | 105 | void setThumbnail(const QString &thumbnail); | ||
1552 | 106 | void setPhoto(const QString &photo); | ||
1553 | 107 | void setTitle(const QString &title); | ||
1554 | 108 | void setPhone(const QString &phone); | ||
1555 | 109 | |||
1556 | 110 | void setLastSeen(qint32 lastSeen); | ||
1557 | 111 | void setIsOnline(bool isOnline); | ||
1558 | 112 | |||
1559 | 113 | void setIsMuted(bool isMuted); | ||
1560 | 114 | void setIsBlocked(bool isBlocked); | ||
1561 | 115 | |||
1562 | 116 | void refreshUserProfile(); | ||
1563 | 117 | void refreshGroupProfile(); | ||
1564 | 118 | |||
1565 | 119 | Q_SIGNALS: | ||
1566 | 120 | void profileUpdated(qint32 dialogId); | ||
1567 | 121 | |||
1568 | 122 | void dialogIdChanged(qint32 dialogId); | ||
1569 | 123 | void userIdChanged(qint32 userId); | ||
1570 | 124 | void chatIdChanged(qint32 chatId); | ||
1571 | 125 | void userTypeChanged(qint32 userType); | ||
1572 | 126 | void isSecretChanged(bool isSecret); | ||
1573 | 127 | void existsChanged(bool exists); | ||
1574 | 128 | |||
1575 | 129 | void thumbnailChanged(QString thumbnail); | ||
1576 | 130 | void photoChanged(QString photo); | ||
1577 | 131 | void titleChanged(QString title); | ||
1578 | 132 | void phoneChanged(QString phone); | ||
1579 | 133 | void hasPhoneChanged(bool hasPhone); | ||
1580 | 134 | |||
1581 | 135 | void lastSeenChanged(qint32 lastSeen); | ||
1582 | 136 | void isOnlineChanged(bool isOnline); | ||
1583 | 137 | |||
1584 | 138 | void isMutedChanged(bool isMuted); | ||
1585 | 139 | void isBlockedChanged(bool isBlocked); | ||
1586 | 140 | |||
1587 | 141 | private: | ||
1588 | 142 | TelegramClient* mTelegramClient; | ||
1589 | 143 | |||
1590 | 144 | qint32 mDialogId; | ||
1591 | 74 | qint32 mUserId; | 145 | qint32 mUserId; |
1592 | 146 | qint32 mChatId; | ||
1593 | 147 | qint32 mUserType; | ||
1594 | 148 | qint64 mAccessHash; | ||
1595 | 149 | bool mIsSecret; | ||
1596 | 150 | |||
1597 | 151 | QString mThumbnail; | ||
1598 | 152 | QString mPhoto; | ||
1599 | 153 | QString mTitle; | ||
1600 | 75 | QString mFirstName; | 154 | QString mFirstName; |
1601 | 76 | QString mLastName; | 155 | QString mLastName; |
1602 | 77 | QString mPhone; | 156 | QString mPhone; |
1607 | 78 | QString mThumbnail; | 157 | bool mHasPhone; |
1608 | 79 | QString mBigPhoto; | 158 | |
1609 | 80 | qint32 mLastSeenOnline; | 159 | // qint32 mMemberCount; |
1610 | 81 | bool mOnline; | 160 | // qint32 mOnlineCount; |
1611 | 161 | |||
1612 | 162 | qint32 mLastSeen; | ||
1613 | 163 | bool mIsOnline; | ||
1614 | 164 | |||
1615 | 165 | bool mIsMuted; | ||
1616 | 166 | bool mIsBlocked; | ||
1617 | 82 | }; | 167 | }; |
1618 | 83 | 168 | ||
1620 | 84 | #endif // PROFILEMODEL_H | 169 | #endif |
1621 | 85 | 170 | ||
1622 | === modified file 'qmlplugin/rawapiclient.cpp' | |||
1623 | --- qmlplugin/rawapiclient.cpp 2015-02-26 21:10:13 +0000 | |||
1624 | +++ qmlplugin/rawapiclient.cpp 2015-03-27 11:52:28 +0000 | |||
1625 | @@ -250,6 +250,18 @@ | |||
1626 | 250 | Q_ARG(QList<InputContact>, contactsList), Q_ARG(bool, replace)); | 250 | Q_ARG(QList<InputContact>, contactsList), Q_ARG(bool, replace)); |
1627 | 251 | } | 251 | } |
1628 | 252 | 252 | ||
1629 | 253 | void RawApiClient::getBlockedContacts() { | ||
1630 | 254 | QMetaObject::invokeMethod(mTelegramService, "getBlockedContacts", Qt::QueuedConnection); | ||
1631 | 255 | } | ||
1632 | 256 | |||
1633 | 257 | void RawApiClient::blockContact(TLInputPeer *peer) { | ||
1634 | 258 | QMetaObject::invokeMethod(mTelegramService, "blockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer)); | ||
1635 | 259 | } | ||
1636 | 260 | |||
1637 | 261 | void RawApiClient::unblockContact(TLInputPeer *peer) { | ||
1638 | 262 | QMetaObject::invokeMethod(mTelegramService, "unblockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer)); | ||
1639 | 263 | } | ||
1640 | 264 | |||
1641 | 253 | // Working with messages | 265 | // Working with messages |
1642 | 254 | void RawApiClient::messagesSendMessage(TLInputPeer *peer, const QString &message) { | 266 | void RawApiClient::messagesSendMessage(TLInputPeer *peer, const QString &message) { |
1643 | 255 | QMetaObject::invokeMethod(mTelegramService, "messagesSendMessage", Qt::QueuedConnection, | 267 | QMetaObject::invokeMethod(mTelegramService, "messagesSendMessage", Qt::QueuedConnection, |
1644 | @@ -313,7 +325,6 @@ | |||
1645 | 313 | } | 325 | } |
1646 | 314 | 326 | ||
1647 | 315 | void RawApiClient::messagesCreateChat(const QVariantList &users, const QString &title) { | 327 | void RawApiClient::messagesCreateChat(const QVariantList &users, const QString &title) { |
1648 | 316 | |||
1649 | 317 | QList<InputUser> groupUsers = toQList<InputUser>(users); | 328 | QList<InputUser> groupUsers = toQList<InputUser>(users); |
1650 | 318 | QMetaObject::invokeMethod(mTelegramService, "messagesCreateChat", Qt::QueuedConnection, | 329 | QMetaObject::invokeMethod(mTelegramService, "messagesCreateChat", Qt::QueuedConnection, |
1651 | 319 | Q_ARG(QList<InputUser>, groupUsers), Q_ARG(QString, title)); | 330 | Q_ARG(QList<InputUser>, groupUsers), Q_ARG(QString, title)); |
1652 | 320 | 331 | ||
1653 | === modified file 'qmlplugin/rawapiclient.h' | |||
1654 | --- qmlplugin/rawapiclient.h 2015-02-26 21:10:13 +0000 | |||
1655 | +++ qmlplugin/rawapiclient.h 2015-03-27 11:52:28 +0000 | |||
1656 | @@ -98,9 +98,13 @@ | |||
1657 | 98 | Q_INVOKABLE void accountRegisterDevice(const QString &token, const QString &appVersion = "", bool appSandbox = false); | 98 | Q_INVOKABLE void accountRegisterDevice(const QString &token, const QString &appVersion = "", bool appSandbox = false); |
1658 | 99 | Q_INVOKABLE void accountUnregisterDevice(const QString &token); | 99 | Q_INVOKABLE void accountUnregisterDevice(const QString &token); |
1659 | 100 | Q_INVOKABLE void accountUpdateProfile(const QString &firstName, const QString &lastName); | 100 | Q_INVOKABLE void accountUpdateProfile(const QString &firstName, const QString &lastName); |
1660 | 101 | |||
1661 | 101 | // Working with contacts | 102 | // Working with contacts |
1662 | 102 | Q_INVOKABLE void contactsGetContacts(); | 103 | Q_INVOKABLE void contactsGetContacts(); |
1663 | 103 | Q_INVOKABLE void contactsImportContacts(const QVariantList &contacts, bool replace = false); | 104 | Q_INVOKABLE void contactsImportContacts(const QVariantList &contacts, bool replace = false); |
1664 | 105 | Q_INVOKABLE void getBlockedContacts(); | ||
1665 | 106 | Q_INVOKABLE void blockContact(TLInputPeer *peer); | ||
1666 | 107 | Q_INVOKABLE void unblockContact(TLInputPeer *peer); | ||
1667 | 104 | 108 | ||
1668 | 105 | // Working with messages | 109 | // Working with messages |
1669 | 106 | Q_INVOKABLE void messagesSendMessage(TLInputPeer *peer, const QString &message); | 110 | Q_INVOKABLE void messagesSendMessage(TLInputPeer *peer, const QString &message); |
1670 | @@ -116,7 +120,6 @@ | |||
1671 | 116 | Q_INVOKABLE void messagesSetTyping(TLInputPeer *peer); | 120 | Q_INVOKABLE void messagesSetTyping(TLInputPeer *peer); |
1672 | 117 | Q_INVOKABLE void messagesSetEncryptedTyping(qint32 chatId, bool typing); | 121 | Q_INVOKABLE void messagesSetEncryptedTyping(qint32 chatId, bool typing); |
1673 | 118 | 122 | ||
1674 | 119 | |||
1675 | 120 | // Working with chats | 123 | // Working with chats |
1676 | 121 | Q_INVOKABLE void messagesCreateChat(const QVariantList &users, const QString &title); | 124 | Q_INVOKABLE void messagesCreateChat(const QVariantList &users, const QString &title); |
1677 | 122 | Q_INVOKABLE void messagesGetFullChat(qint32 chatId); | 125 | Q_INVOKABLE void messagesGetFullChat(qint32 chatId); |
1678 | 123 | 126 | ||
1679 | === modified file 'qmlplugin/rawapiservice.cpp' | |||
1680 | --- qmlplugin/rawapiservice.cpp 2015-03-02 21:17:11 +0000 | |||
1681 | +++ qmlplugin/rawapiservice.cpp 2015-03-27 11:52:28 +0000 | |||
1682 | @@ -83,6 +83,8 @@ | |||
1683 | 83 | 83 | ||
1684 | 84 | // Working with contacts | 84 | // Working with contacts |
1685 | 85 | connect(mTelegramLib, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); | 85 | connect(mTelegramLib, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); |
1686 | 86 | connect(mTelegramLib, SIGNAL(contactsBlockAnswer(qint64,bool)), this, SIGNAL(contactsBlockAnswer(qint64,bool))); | ||
1687 | 87 | connect(mTelegramLib, SIGNAL(contactsUnblockAnswer(qint64,bool)), this, SIGNAL(contactsUnblockAnswer(qint64,bool))); | ||
1688 | 86 | 88 | ||
1689 | 87 | // Working with updates signal-slot | 89 | // Working with updates signal-slot |
1690 | 88 | connect(mTelegramLib, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32))); | 90 | connect(mTelegramLib, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32))); |
1691 | 89 | 91 | ||
1692 | === modified file 'qmlplugin/rawapiservice.h' | |||
1693 | --- qmlplugin/rawapiservice.h 2015-03-02 21:17:11 +0000 | |||
1694 | +++ qmlplugin/rawapiservice.h 2015-03-27 11:52:28 +0000 | |||
1695 | @@ -150,6 +150,8 @@ | |||
1696 | 150 | // Working with blacklist | 150 | // Working with blacklist |
1697 | 151 | void contactsBlockAnswer(qint64 id, bool ok); | 151 | void contactsBlockAnswer(qint64 id, bool ok); |
1698 | 152 | void contactsUnblockAnswer(qint64 id, bool ok); | 152 | void contactsUnblockAnswer(qint64 id, bool ok); |
1699 | 153 | void contactsBlockResult(qint64 id, bool ok); | ||
1700 | 154 | void contactsUnblockResult(qint64 id, bool ok); | ||
1701 | 153 | void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); | 155 | void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); |
1702 | 154 | 156 | ||
1703 | 155 | // Working with messages | 157 | // Working with messages |
1704 | 156 | 158 | ||
1705 | === modified file 'qmlplugin/telegramclient.cpp' | |||
1706 | --- qmlplugin/telegramclient.cpp 2015-03-04 21:24:05 +0000 | |||
1707 | +++ qmlplugin/telegramclient.cpp 2015-03-27 11:52:28 +0000 | |||
1708 | @@ -59,6 +59,9 @@ | |||
1709 | 59 | connect(mTelegramService, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)), Qt::QueuedConnection); | 59 | connect(mTelegramService, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)), Qt::QueuedConnection); |
1710 | 60 | connect(mTelegramService, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)), Qt::QueuedConnection); | 60 | connect(mTelegramService, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)), Qt::QueuedConnection); |
1711 | 61 | connect(mTelegramService, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)), Qt::QueuedConnection); | 61 | connect(mTelegramService, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)), Qt::QueuedConnection); |
1712 | 62 | connect(mTelegramService, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>))); | ||
1713 | 63 | connect(mTelegramService, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32))); | ||
1714 | 64 | connect(mTelegramService, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32))); | ||
1715 | 62 | connect(mTelegramService, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)), Qt::QueuedConnection); | 65 | connect(mTelegramService, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)), Qt::QueuedConnection); |
1716 | 63 | connect(mTelegramService, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), Qt::QueuedConnection); | 66 | connect(mTelegramService, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), Qt::QueuedConnection); |
1717 | 64 | connect(mTelegramService, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)), Qt::QueuedConnection); | 67 | connect(mTelegramService, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)), Qt::QueuedConnection); |
1718 | 65 | 68 | ||
1719 | === modified file 'qmlplugin/telegramclient.h' | |||
1720 | --- qmlplugin/telegramclient.h 2015-03-04 21:10:13 +0000 | |||
1721 | +++ qmlplugin/telegramclient.h 2015-03-27 11:52:28 +0000 | |||
1722 | @@ -128,6 +128,9 @@ | |||
1723 | 128 | void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto); | 128 | void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto); |
1724 | 129 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); | 129 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); |
1725 | 130 | void dialogTitleUpdated(qint32 dialogId, const QString &title); | 130 | void dialogTitleUpdated(qint32 dialogId, const QString &title); |
1726 | 131 | void usersBlocked(QList<qint32> ids); | ||
1727 | 132 | void userBlocked(qint32 id); | ||
1728 | 133 | void userUnblocked(qint32 id); | ||
1729 | 131 | void dialogMuted(qint32 dialogId, bool muted); | 134 | void dialogMuted(qint32 dialogId, bool muted); |
1730 | 132 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); | 135 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); |
1731 | 133 | void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount); | 136 | void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount); |
1732 | 134 | 137 | ||
1733 | === modified file 'qmlplugin/telegramplugin.cpp' | |||
1734 | --- qmlplugin/telegramplugin.cpp 2015-02-18 17:53:54 +0000 | |||
1735 | +++ qmlplugin/telegramplugin.cpp 2015-03-27 11:52:28 +0000 | |||
1736 | @@ -49,8 +49,10 @@ | |||
1737 | 49 | #include "models/messagesmodel.h" | 49 | #include "models/messagesmodel.h" |
1738 | 50 | #include "models/contactsmodel.h" | 50 | #include "models/contactsmodel.h" |
1739 | 51 | #include "models/contactsproxy.h" | 51 | #include "models/contactsproxy.h" |
1740 | 52 | #include "models/profilemodel.h" | ||
1741 | 52 | #include "models/groupmodel.h" | 53 | #include "models/groupmodel.h" |
1742 | 53 | #include "models/groupmembersmodel.h" | 54 | #include "models/groupmembersmodel.h" |
1743 | 55 | #include "models/blockedusersmodel.h" | ||
1744 | 54 | #include "models/dialogsmodel.h" | 56 | #include "models/dialogsmodel.h" |
1745 | 55 | #include "models/dialogsproxy.h" | 57 | #include "models/dialogsproxy.h" |
1746 | 56 | #include "models/sortproxymodel.h" | 58 | #include "models/sortproxymodel.h" |
1747 | @@ -118,8 +120,10 @@ | |||
1748 | 118 | qmlRegisterType<ContactsModel>(uri, 0, 1, "ContactsModel"); | 120 | qmlRegisterType<ContactsModel>(uri, 0, 1, "ContactsModel"); |
1749 | 119 | qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel"); | 121 | qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel"); |
1750 | 120 | qmlRegisterType<ContactsProxy>(uri, 0, 1, "ContactsProxy"); | 122 | qmlRegisterType<ContactsProxy>(uri, 0, 1, "ContactsProxy"); |
1751 | 123 | qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel"); | ||
1752 | 121 | qmlRegisterType<GroupModel>(uri, 0, 1, "GroupModel"); | 124 | qmlRegisterType<GroupModel>(uri, 0, 1, "GroupModel"); |
1753 | 122 | qmlRegisterType<GroupMembersModel>(uri, 0, 1, "GroupMembersModel"); | 125 | qmlRegisterType<GroupMembersModel>(uri, 0, 1, "GroupMembersModel"); |
1754 | 126 | qmlRegisterType<BlockedUsersModel>(uri, 0, 1, "BlockedUsersModel"); | ||
1755 | 123 | qmlRegisterType<DialogItem>(uri, 0, 1, "DialogItem"); | 127 | qmlRegisterType<DialogItem>(uri, 0, 1, "DialogItem"); |
1756 | 124 | qmlRegisterType<MessageItem>(uri, 0, 1, "MessageItem"); | 128 | qmlRegisterType<MessageItem>(uri, 0, 1, "MessageItem"); |
1757 | 125 | qmlRegisterType<ContactItem>(uri, 0, 1, "ContactItem"); | 129 | qmlRegisterType<ContactItem>(uri, 0, 1, "ContactItem"); |
1758 | 126 | 130 | ||
1759 | === modified file 'qmlplugin/telegramservice.cpp' | |||
1760 | --- qmlplugin/telegramservice.cpp 2015-03-04 21:10:13 +0000 | |||
1761 | +++ qmlplugin/telegramservice.cpp 2015-03-27 11:52:28 +0000 | |||
1762 | @@ -46,6 +46,9 @@ | |||
1763 | 46 | connect(&mData, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString))); | 46 | connect(&mData, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString))); |
1764 | 47 | connect(&mData, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString))); | 47 | connect(&mData, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString))); |
1765 | 48 | connect(&mData, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString))); | 48 | connect(&mData, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString))); |
1766 | 49 | connect(&mData, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>))); | ||
1767 | 50 | connect(&mData, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32))); | ||
1768 | 51 | connect(&mData, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32))); | ||
1769 | 49 | connect(&mData, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool))); | 52 | connect(&mData, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool))); |
1770 | 50 | connect(&mData, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool))); | 53 | connect(&mData, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool))); |
1771 | 51 | connect(&mData, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem))); | 54 | connect(&mData, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem))); |
1772 | @@ -291,6 +294,18 @@ | |||
1773 | 291 | &mData, | 294 | &mData, |
1774 | 292 | SLOT(onContactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); | 295 | SLOT(onContactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); |
1775 | 293 | connect(mTelegramLib, | 296 | connect(mTelegramLib, |
1776 | 297 | SIGNAL(contactsGetBlockedAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>)), | ||
1777 | 298 | &mData, | ||
1778 | 299 | SLOT(onGetBlockedContactsAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>))); | ||
1779 | 300 | connect(mTelegramLib, | ||
1780 | 301 | SIGNAL(contactsBlockAnswer(qint64,bool)), | ||
1781 | 302 | &mData, | ||
1782 | 303 | SLOT(onBlockContactAnswer(qint64,bool))); | ||
1783 | 304 | connect(mTelegramLib, | ||
1784 | 305 | SIGNAL(contactsUnblockAnswer(qint64,bool)), | ||
1785 | 306 | &mData, | ||
1786 | 307 | SLOT(onUnblockContactsAnswer(qint64,bool))); | ||
1787 | 308 | connect(mTelegramLib, | ||
1788 | 294 | SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool)), | 309 | SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool)), |
1789 | 295 | &mData, | 310 | &mData, |
1790 | 296 | SLOT(onAccountUpdateNotifySettingsAnswer(qint64,bool))); | 311 | SLOT(onAccountUpdateNotifySettingsAnswer(qint64,bool))); |
1791 | @@ -409,6 +424,26 @@ | |||
1792 | 409 | return RawApiService::contactsImportContacts(contacts); | 424 | return RawApiService::contactsImportContacts(contacts); |
1793 | 410 | } | 425 | } |
1794 | 411 | 426 | ||
1795 | 427 | void TelegramService::getBlockedContacts() { | ||
1796 | 428 | mTelegramLib->contactsGetBlocked(0, 200); | ||
1797 | 429 | } | ||
1798 | 430 | |||
1799 | 431 | void TelegramService::blockContact(InputPeer peer) { | ||
1800 | 432 | const ContactItem &contactItem = mData.getUser(peer.userId()); | ||
1801 | 433 | InputUser inputUser = Tools::toInputUser(contactItem); | ||
1802 | 434 | |||
1803 | 435 | qint64 requestId = mTelegramLib->contactsBlock(inputUser); | ||
1804 | 436 | mData.mBlockRequests.insert(requestId, peer.userId()); | ||
1805 | 437 | } | ||
1806 | 438 | |||
1807 | 439 | void TelegramService::unblockContact(InputPeer peer) { | ||
1808 | 440 | const ContactItem &contactItem = mData.getUser(peer.userId()); | ||
1809 | 441 | InputUser inputUser = Tools::toInputUser(contactItem); | ||
1810 | 442 | |||
1811 | 443 | qint64 requestId = mTelegramLib->contactsUnblock(inputUser); | ||
1812 | 444 | mData.mBlockRequests.insert(requestId, peer.userId()); | ||
1813 | 445 | } | ||
1814 | 446 | |||
1815 | 412 | qint64 TelegramService::messagesReadHistory(InputPeer inputPeer, qint32 maxId, qint32 offset, bool readContents) { | 447 | qint64 TelegramService::messagesReadHistory(InputPeer inputPeer, qint32 maxId, qint32 offset, bool readContents) { |
1816 | 413 | 448 | ||
1817 | 414 | // if peer is foreign, get access hash from db | 449 | // if peer is foreign, get access hash from db |
1818 | 415 | 450 | ||
1819 | === modified file 'qmlplugin/telegramservice.h' | |||
1820 | --- qmlplugin/telegramservice.h 2015-03-04 21:24:05 +0000 | |||
1821 | +++ qmlplugin/telegramservice.h 2015-03-27 11:52:28 +0000 | |||
1822 | @@ -55,6 +55,11 @@ | |||
1823 | 55 | qint64 uploadProfilePhoto(const QString &filePath, const QString &caption = "", double geoPointLat = 0, double geoPointLong = 0, double cropLeft = 0, double cropTop = 0, double cropWidth = 0); | 55 | qint64 uploadProfilePhoto(const QString &filePath, const QString &caption = "", double geoPointLat = 0, double geoPointLong = 0, double cropLeft = 0, double cropTop = 0, double cropWidth = 0); |
1824 | 56 | void getUser(qint32 userId); | 56 | void getUser(qint32 userId); |
1825 | 57 | qint64 addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber); | 57 | qint64 addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber); |
1826 | 58 | void getBlockedContacts(); | ||
1827 | 59 | void getBlockedContactsAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users); | ||
1828 | 60 | void blockContact(InputPeer peer); | ||
1829 | 61 | void unblockContact(InputPeer peer); | ||
1830 | 62 | |||
1831 | 58 | qint64 messagesReadHistory(InputPeer peer, qint32 maxId = 0, qint32 offset = 0, bool readContents = true); | 63 | qint64 messagesReadHistory(InputPeer peer, qint32 maxId = 0, qint32 offset = 0, bool readContents = true); |
1832 | 59 | qint64 deleteChatHistory(InputPeer inputPeer, qint32 offset = 0, bool deleteChat = false); | 64 | qint64 deleteChatHistory(InputPeer inputPeer, qint32 offset = 0, bool deleteChat = false); |
1833 | 60 | qint64 messagesSendMessage(InputPeer peer, const QString &message); | 65 | qint64 messagesSendMessage(InputPeer peer, const QString &message); |
1834 | @@ -123,6 +128,9 @@ | |||
1835 | 123 | void contactThumbnailUpdated(qint32 userId, const QString &thumbnail); | 128 | void contactThumbnailUpdated(qint32 userId, const QString &thumbnail); |
1836 | 124 | void contactBigPhotoUpdated(qint32 userId, const QString &bigPhoto); | 129 | void contactBigPhotoUpdated(qint32 userId, const QString &bigPhoto); |
1837 | 125 | void contactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline); | 130 | void contactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline); |
1838 | 131 | void usersBlocked(QList<qint32> ids); | ||
1839 | 132 | void userBlocked(qint32 id); | ||
1840 | 133 | void userUnblocked(qint32 id); | ||
1841 | 126 | void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto); | 134 | void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto); |
1842 | 127 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); | 135 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); |
1843 | 128 | void dialogTitleUpdated(qint32 dialogId, const QString &title); | 136 | void dialogTitleUpdated(qint32 dialogId, const QString &title); |
// TODO replace getBlockedContacts with getFullUser
Intentionally left. I think the lib doesn't yet support getFullUser / FullUser type, and we've sat on this feature long already, so let's get this going, we can revisit this part later.
// TODO: Merge groupmodel into this class.
This (and couple lines commented in the profilemodel are left for when I merge groupmodel into the profilemodel class.