Merge lp:~libqtelegram-team/telegram-app/lib-fix-delays into lp:telegram-app/trunk
- lib-fix-delays
- Merge into trunk
Proposed by
Michał Karnicki
Status: | Merged |
---|---|
Approved by: | Roberto Mier Escandon |
Approved revision: | 95 |
Merged at revision: | 94 |
Proposed branch: | lp:~libqtelegram-team/telegram-app/lib-fix-delays |
Merge into: | lp:telegram-app/trunk |
Diff against target: |
506 lines (+135/-57) 8 files modified
qmlplugin/data.cpp (+41/-15) qmlplugin/data.h (+7/-2) qmlplugin/models/dialogsmodel.cpp (+59/-28) qmlplugin/models/dialogsmodel.h (+8/-0) qmlplugin/telegramclient.cpp (+1/-1) qmlplugin/telegramclient.h (+1/-1) qmlplugin/telegramservice.cpp (+17/-9) qmlplugin/telegramservice.h (+1/-1) |
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/lib-fix-delays |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Mier Escandon (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
Requires: lp:~libqtelegram-team/libqtelegram/app-fix-delays
Collapse in time updates to unread badge.
Collapse in time updates to user metrics.
Be smarter about updating dialog top messages.
Intentionally proposed to trunk.
To post a comment you must log in.
- 95. By Michał Karnicki
-
Rename method.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'qmlplugin/data.cpp' | |||
2 | --- qmlplugin/data.cpp 2015-05-05 17:09:36 +0000 | |||
3 | +++ qmlplugin/data.cpp 2015-06-01 13:36:23 +0000 | |||
4 | @@ -33,7 +33,8 @@ | |||
5 | 33 | mFilesAvgTime(0), | 33 | mFilesAvgTime(0), |
6 | 34 | mFilesCount(0), | 34 | mFilesCount(0), |
7 | 35 | mFilesTotalTime(0), | 35 | mFilesTotalTime(0), |
9 | 36 | mLastUnreadCount(-1) { | 36 | mLastUnreadCount(-1), |
10 | 37 | mBadgeUpdateTimer(0) { | ||
11 | 37 | 38 | ||
12 | 38 | // Priorities for thumbnail sizes are m, b, s, a, x, c, y, d, w | 39 | // Priorities for thumbnail sizes are m, b, s, a, x, c, y, d, w |
13 | 39 | mPhotoSmallPriorities.insert("m", 1); | 40 | mPhotoSmallPriorities.insert("m", 1); |
14 | @@ -149,6 +150,7 @@ | |||
15 | 149 | } | 150 | } |
16 | 150 | } | 151 | } |
17 | 151 | 152 | ||
18 | 153 | qint32 newMessagesReceivedCount = 0; | ||
19 | 152 | Q_FOREACH (const Message &message, messages) { | 154 | Q_FOREACH (const Message &message, messages) { |
20 | 153 | 155 | ||
21 | 154 | qint32 dialogId = Tools::getBelongingDialogId(message); | 156 | qint32 dialogId = Tools::getBelongingDialogId(message); |
22 | @@ -179,7 +181,11 @@ | |||
23 | 179 | TelegramService *service = static_cast<TelegramService *>(mServiceRef); | 181 | TelegramService *service = static_cast<TelegramService *>(mServiceRef); |
24 | 180 | service->messagesGetDialogs(0, dialogId, 1); | 182 | service->messagesGetDialogs(0, dialogId, 1); |
25 | 181 | } | 183 | } |
26 | 184 | |||
27 | 185 | newMessagesReceivedCount += (!message.out() && message.unread()) ? 1 : 0; | ||
28 | 182 | } | 186 | } |
29 | 187 | Q_EMIT messagesReceived(newMessagesReceivedCount); | ||
30 | 188 | updateBadge(); | ||
31 | 183 | 189 | ||
32 | 184 | Q_FOREACH (const SecretChatMessage &secretChatMessage, secretChatMessages) { | 190 | Q_FOREACH (const SecretChatMessage &secretChatMessage, secretChatMessages) { |
33 | 185 | 191 | ||
34 | @@ -250,9 +256,10 @@ | |||
35 | 250 | } | 256 | } |
36 | 251 | 257 | ||
37 | 252 | if (!isIntermediateState) { | 258 | if (!isIntermediateState) { |
39 | 253 | surfaceUnreadCount(); | 259 | updateBadge(); |
40 | 254 | } | 260 | } |
41 | 255 | 261 | ||
42 | 262 | Q_EMIT selfDestructMessages(); | ||
43 | 256 | qCDebug(TG_PLUGIN_PROFILING) << "onUpdatesGetDifferenceAnswer - end:" << time.elapsed() << "ms"; | 263 | qCDebug(TG_PLUGIN_PROFILING) << "onUpdatesGetDifferenceAnswer - end:" << time.elapsed() << "ms"; |
44 | 257 | } | 264 | } |
45 | 258 | 265 | ||
46 | @@ -1700,7 +1707,7 @@ | |||
47 | 1700 | } | 1707 | } |
48 | 1701 | 1708 | ||
49 | 1702 | Q_EMIT messagesAdded(messageItems, messageItems.count()); | 1709 | Q_EMIT messagesAdded(messageItems, messageItems.count()); |
51 | 1703 | 1710 | Q_EMIT selfDestructMessages(); | |
52 | 1704 | qCDebug(TG_PLUGIN_PROFILING) << "onMessagesForwardMessagesAnswer - end"; | 1711 | qCDebug(TG_PLUGIN_PROFILING) << "onMessagesForwardMessagesAnswer - end"; |
53 | 1705 | } | 1712 | } |
54 | 1706 | 1713 | ||
55 | @@ -1803,6 +1810,8 @@ | |||
56 | 1803 | mDbManager.finishTransaction(); | 1810 | mDbManager.finishTransaction(); |
57 | 1804 | 1811 | ||
58 | 1805 | Q_EMIT messageAdded(messageItem); | 1812 | Q_EMIT messageAdded(messageItem); |
59 | 1813 | Q_EMIT messagesReceived(1); | ||
60 | 1814 | Q_EMIT selfDestructMessages(); | ||
61 | 1806 | } | 1815 | } |
62 | 1807 | 1816 | ||
63 | 1808 | void Data::onUpdateShort(const Update &update, qint32 date) { | 1817 | void Data::onUpdateShort(const Update &update, qint32 date) { |
64 | @@ -1899,6 +1908,7 @@ | |||
65 | 1899 | 1908 | ||
66 | 1900 | MessageItem messageItem = getMessage(message.randomId()); | 1909 | MessageItem messageItem = getMessage(message.randomId()); |
67 | 1901 | Q_EMIT outgoingMessageAdded(chatId, messageItem); | 1910 | Q_EMIT outgoingMessageAdded(chatId, messageItem); |
68 | 1911 | Q_EMIT selfDestructMessages(); | ||
69 | 1902 | 1912 | ||
70 | 1903 | // 'local' is the size for sent photos until having a server location and different sizes | 1913 | // 'local' is the size for sent photos until having a server location and different sizes |
71 | 1904 | // if there is a mediaLocalPath and media type is photo ro video, emit photo updated signal. Same for video | 1914 | // if there is a mediaLocalPath and media type is photo ro video, emit photo updated signal. Same for video |
72 | @@ -2518,7 +2528,8 @@ | |||
73 | 2518 | service->messagesReceivedQueue(qts); | 2528 | service->messagesReceivedQueue(qts); |
74 | 2519 | 2529 | ||
75 | 2520 | Q_EMIT messageAdded(messageItem); | 2530 | Q_EMIT messageAdded(messageItem); |
77 | 2521 | surfaceUnreadCount(); | 2531 | updateBadge(); |
78 | 2532 | Q_EMIT selfDestructMessages(); | ||
79 | 2522 | 2533 | ||
80 | 2523 | qCDebug(TG_PLUGIN_PROFILING) << "onUpdateSecretChatMessage - end:" << time.elapsed() << "ms"; | 2534 | qCDebug(TG_PLUGIN_PROFILING) << "onUpdateSecretChatMessage - end:" << time.elapsed() << "ms"; |
81 | 2524 | } | 2535 | } |
82 | @@ -2655,6 +2666,7 @@ | |||
83 | 2655 | qCCritical(TG_PLUGIN_LOGIC) << "Impossible insert new received message"; | 2666 | qCCritical(TG_PLUGIN_LOGIC) << "Impossible insert new received message"; |
84 | 2656 | return false; | 2667 | return false; |
85 | 2657 | } | 2668 | } |
86 | 2669 | Q_EMIT messagesReceived(1); | ||
87 | 2658 | 2670 | ||
88 | 2659 | if (!executeAction(message)) { | 2671 | if (!executeAction(message)) { |
89 | 2660 | mDbManager.rollbackTransaction(); | 2672 | mDbManager.rollbackTransaction(); |
90 | @@ -2672,6 +2684,7 @@ | |||
91 | 2672 | 2684 | ||
92 | 2673 | MessageItem messageItem = getMessage(message.id()); | 2685 | MessageItem messageItem = getMessage(message.id()); |
93 | 2674 | Q_EMIT messageAdded(messageItem); | 2686 | Q_EMIT messageAdded(messageItem); |
94 | 2687 | Q_EMIT selfDestructMessages(); | ||
95 | 2675 | 2688 | ||
96 | 2676 | if (newDialog) { | 2689 | if (newDialog) { |
97 | 2677 | // Ask telegram servers for info about this just created dialog where it will be included the phone number | 2690 | // Ask telegram servers for info about this just created dialog where it will be included the phone number |
98 | @@ -2687,6 +2700,7 @@ | |||
99 | 2687 | case Update::typeUpdateReadMessages: { | 2700 | case Update::typeUpdateReadMessages: { |
100 | 2688 | if (markMessagesAsRead(update.messages())) { | 2701 | if (markMessagesAsRead(update.messages())) { |
101 | 2689 | Q_EMIT messagesMarkedAsRead(update.messages()); | 2702 | Q_EMIT messagesMarkedAsRead(update.messages()); |
102 | 2703 | Q_EMIT selfDestructMessages(); | ||
103 | 2690 | } | 2704 | } |
104 | 2691 | 2705 | ||
105 | 2692 | UpdatesState clientState = getState(); | 2706 | UpdatesState clientState = getState(); |
106 | @@ -2893,7 +2907,7 @@ | |||
107 | 2893 | } | 2907 | } |
108 | 2894 | 2908 | ||
109 | 2895 | bool Data::getProfilePhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) { | 2909 | bool Data::getProfilePhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) { |
111 | 2896 | 2910 | ||
112 | 2897 | if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) { | 2911 | if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) { |
113 | 2898 | // Search in database if same location parameter are stored for thumbnail that | 2912 | // Search in database if same location parameter are stored for thumbnail that |
114 | 2899 | // received ones. In that case don't download cos it's the same file | 2913 | // received ones. In that case don't download cos it's the same file |
115 | @@ -2911,7 +2925,7 @@ | |||
116 | 2911 | } | 2925 | } |
117 | 2912 | 2926 | ||
118 | 2913 | bool Data::downloadPhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) { | 2927 | bool Data::downloadPhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) { |
120 | 2914 | 2928 | qCWarning(TG_PLUGIN_LOGIC) << "Data::downloadPhotoFileFromServer"; | |
121 | 2915 | if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) { | 2929 | if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) { |
122 | 2916 | // create object with the data of the file to be downloaded | 2930 | // create object with the data of the file to be downloaded |
123 | 2917 | TelegramService *service = static_cast<TelegramService *>(mServiceRef); | 2931 | TelegramService *service = static_cast<TelegramService *>(mServiceRef); |
124 | @@ -3891,7 +3905,7 @@ | |||
125 | 3891 | } | 3905 | } |
126 | 3892 | 3906 | ||
127 | 3893 | if (!query.next()) { | 3907 | if (!query.next()) { |
129 | 3894 | qCCritical(TG_PLUGIN_LOGIC) << "Message to update not found."; | 3908 | qCDebug(TG_PLUGIN_LOGIC) << "Message to update not found."; |
130 | 3895 | return false; | 3909 | return false; |
131 | 3896 | } | 3910 | } |
132 | 3897 | 3911 | ||
133 | @@ -4925,11 +4939,7 @@ | |||
134 | 4925 | 4939 | ||
135 | 4926 | mDbManager.finishTransaction(); | 4940 | mDbManager.finishTransaction(); |
136 | 4927 | 4941 | ||
142 | 4928 | if (!message.out() && message.unread()) { | 4942 | updateBadge(); |
138 | 4929 | Q_EMIT messageReceived(); | ||
139 | 4930 | } | ||
140 | 4931 | |||
141 | 4932 | surfaceUnreadCount(); | ||
143 | 4933 | 4943 | ||
144 | 4934 | return true; | 4944 | return true; |
145 | 4935 | } | 4945 | } |
146 | @@ -5128,7 +5138,7 @@ | |||
147 | 5128 | query.prepare(("UPDATE messages SET unread = 0 WHERE dialogId=:dialogId AND out = 0 AND unread = 1")); | 5138 | query.prepare(("UPDATE messages SET unread = 0 WHERE dialogId=:dialogId AND out = 0 AND unread = 1")); |
148 | 5129 | query.bindValue(":dialogId", chatId); | 5139 | query.bindValue(":dialogId", chatId); |
149 | 5130 | if (query.exec()) { | 5140 | if (query.exec()) { |
151 | 5131 | surfaceUnreadCount(); | 5141 | updateBadge(); |
152 | 5132 | } | 5142 | } |
153 | 5133 | 5143 | ||
154 | 5134 | Q_EMIT chatMarkedAsRead(chatId); | 5144 | Q_EMIT chatMarkedAsRead(chatId); |
155 | @@ -5178,7 +5188,7 @@ | |||
156 | 5178 | 5188 | ||
157 | 5179 | mDbManager.finishTransaction(); | 5189 | mDbManager.finishTransaction(); |
158 | 5180 | 5190 | ||
160 | 5181 | surfaceUnreadCount(); | 5191 | updateBadge(); |
161 | 5182 | 5192 | ||
162 | 5183 | return true; | 5193 | return true; |
163 | 5184 | } | 5194 | } |
164 | @@ -6647,7 +6657,23 @@ | |||
165 | 6647 | return dialog; | 6657 | return dialog; |
166 | 6648 | } | 6658 | } |
167 | 6649 | 6659 | ||
169 | 6650 | void Data::surfaceUnreadCount() { | 6660 | void Data::updateBadge() { |
170 | 6661 | if (mBadgeUpdateTimer != 0) { | ||
171 | 6662 | killTimer(mBadgeUpdateTimer); | ||
172 | 6663 | } | ||
173 | 6664 | mBadgeUpdateTimer = startTimer(200); | ||
174 | 6665 | } | ||
175 | 6666 | |||
176 | 6667 | void Data::timerEvent(QTimerEvent *e) { | ||
177 | 6668 | if(e->timerId() == mBadgeUpdateTimer) { | ||
178 | 6669 | killTimer(mBadgeUpdateTimer); | ||
179 | 6670 | mBadgeUpdateTimer = 0; | ||
180 | 6671 | onUpdateBadge(); | ||
181 | 6672 | } | ||
182 | 6673 | QObject::timerEvent(e); | ||
183 | 6674 | } | ||
184 | 6675 | |||
185 | 6676 | void Data::onUpdateBadge() { | ||
186 | 6651 | QSqlQuery query; | 6677 | QSqlQuery query; |
187 | 6652 | query.prepare(QString("SELECT SUM(unreadCount) AS unreadCount FROM dialogsView")); | 6678 | query.prepare(QString("SELECT SUM(unreadCount) AS unreadCount FROM dialogsView")); |
188 | 6653 | 6679 | ||
189 | 6654 | 6680 | ||
190 | === modified file 'qmlplugin/data.h' | |||
191 | --- qmlplugin/data.h 2015-05-05 17:09:36 +0000 | |||
192 | +++ qmlplugin/data.h 2015-06-01 13:36:23 +0000 | |||
193 | @@ -212,6 +212,8 @@ | |||
194 | 212 | void updateChatPhoto(qint32 chatId, const Photo &photo); | 212 | void updateChatPhoto(qint32 chatId, const Photo &photo); |
195 | 213 | void updateChatFull(const ChatFull &chatFull); | 213 | void updateChatFull(const ChatFull &chatFull); |
196 | 214 | 214 | ||
197 | 215 | void timerEvent(QTimerEvent *e); | ||
198 | 216 | |||
199 | 215 | Q_SIGNALS: | 217 | Q_SIGNALS: |
200 | 216 | void userInfo(const ContactItem &user); | 218 | void userInfo(const ContactItem &user); |
201 | 217 | 219 | ||
202 | @@ -234,6 +236,7 @@ | |||
203 | 234 | void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount); | 236 | void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount); |
204 | 235 | void messageAdded(const MessageItem &message); | 237 | void messageAdded(const MessageItem &message); |
205 | 236 | void outgoingMessageAdded(qint32 recipientId, const MessageItem &message); | 238 | void outgoingMessageAdded(qint32 recipientId, const MessageItem &message); |
206 | 239 | void selfDestructMessages(); | ||
207 | 237 | void messageUpdated(qint32 msgId, const MessageItem &message); | 240 | void messageUpdated(qint32 msgId, const MessageItem &message); |
208 | 238 | 241 | ||
209 | 239 | void chatMarkedAsRead(qint32 chatId); | 242 | void chatMarkedAsRead(qint32 chatId); |
210 | @@ -247,7 +250,7 @@ | |||
211 | 247 | void messageDocumentUpdated(qint32 msgId, const QString &documentLocalPath, const QString &fileName = "", qint32 size = 0); | 250 | void messageDocumentUpdated(qint32 msgId, const QString &documentLocalPath, const QString &fileName = "", qint32 size = 0); |
212 | 248 | 251 | ||
213 | 249 | void messageSent(); | 252 | void messageSent(); |
215 | 250 | void messageReceived(); | 253 | void messagesReceived(qint32 count); |
216 | 251 | 254 | ||
217 | 252 | void downloadingUpdated(qint32 id, bool downloading); | 255 | void downloadingUpdated(qint32 id, bool downloading); |
218 | 253 | void downloadedPercentageUpdated(qint32 id, qint8 downloadedPercentage); | 256 | void downloadedPercentageUpdated(qint32 id, qint8 downloadedPercentage); |
219 | @@ -271,6 +274,7 @@ | |||
220 | 271 | DbManager mDbManager; | 274 | DbManager mDbManager; |
221 | 272 | 275 | ||
222 | 273 | qint32 mLastUnreadCount; | 276 | qint32 mLastUnreadCount; |
223 | 277 | qint32 mBadgeUpdateTimer; | ||
224 | 274 | 278 | ||
225 | 275 | // time mesurement map for file downloading. Correlates fileId with a QTime object for calculate total download time | 279 | // time mesurement map for file downloading. Correlates fileId with a QTime object for calculate total download time |
226 | 276 | QMap<qint64, QTime *> mFileTimes; | 280 | QMap<qint64, QTime *> mFileTimes; |
227 | @@ -346,7 +350,8 @@ | |||
228 | 346 | bool muteDialog(qint32 dialogId, bool muted); | 350 | bool muteDialog(qint32 dialogId, bool muted); |
229 | 347 | bool muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted); | 351 | bool muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted); |
230 | 348 | 352 | ||
232 | 349 | void surfaceUnreadCount(); | 353 | void updateBadge(); |
233 | 354 | void onUpdateBadge(); | ||
234 | 350 | 355 | ||
235 | 351 | bool exists(qint32 id, bool isUser); | 356 | bool exists(qint32 id, bool isUser); |
236 | 352 | 357 | ||
237 | 353 | 358 | ||
238 | === modified file 'qmlplugin/models/dialogsmodel.cpp' | |||
239 | --- qmlplugin/models/dialogsmodel.cpp 2015-02-16 13:51:55 +0000 | |||
240 | +++ qmlplugin/models/dialogsmodel.cpp 2015-06-01 13:36:23 +0000 | |||
241 | @@ -28,6 +28,7 @@ | |||
242 | 28 | mCanFetchMore(true), | 28 | mCanFetchMore(true), |
243 | 29 | mState(Created), | 29 | mState(Created), |
244 | 30 | mSecretDialogsCount(0), | 30 | mSecretDialogsCount(0), |
245 | 31 | mTopMessagesTimer(0), | ||
246 | 31 | mTelegramClient(0) { | 32 | mTelegramClient(0) { |
247 | 32 | } | 33 | } |
248 | 33 | 34 | ||
249 | @@ -420,41 +421,71 @@ | |||
250 | 420 | } | 421 | } |
251 | 421 | 422 | ||
252 | 422 | void DialogsModel::onMessageAdded(const MessageItem &message) { | 423 | void DialogsModel::onMessageAdded(const MessageItem &message) { |
253 | 424 | mTopMessages.insert(message.dialogId(), message); | ||
254 | 423 | 425 | ||
255 | 424 | qint32 dialogId = message.dialogId(); | 426 | qint32 dialogId = message.dialogId(); |
256 | 425 | qint32 pos = mDlgIdsMap.value(dialogId, -1); | 427 | qint32 pos = mDlgIdsMap.value(dialogId, -1); |
257 | 426 | |||
258 | 427 | if (0 <= pos && pos < mDialogs.size()) { | 428 | if (0 <= pos && pos < mDialogs.size()) { |
259 | 428 | DialogItem &dlg = mDialogs[pos]; | ||
260 | 429 | |||
261 | 430 | if (!message.out()) { | ||
262 | 431 | dlg.setTyping(false); | ||
263 | 432 | } | ||
264 | 433 | |||
265 | 434 | //Remove previous top message id from mapping | ||
266 | 435 | MessageItem oldTopMessage = dlg.topMessage(); | ||
267 | 436 | if (!oldTopMessage.isEmpty()) { | ||
268 | 437 | mTopMessageIdsMap.remove(oldTopMessage.id()); | ||
269 | 438 | } | ||
270 | 439 | |||
271 | 440 | dlg.setTopMessage(message); | ||
272 | 441 | dlg.setDate(message.date()); | ||
273 | 442 | mTopMessageIdsMap.insert(message.id(), dlg.id()); | ||
274 | 443 | |||
275 | 444 | if (!message.out() && message.unread()) { | 429 | if (!message.out() && message.unread()) { |
276 | 430 | DialogItem &dlg = mDialogs[pos]; | ||
277 | 445 | dlg.setUnreadCount(dlg.unreadCount() + 1); | 431 | dlg.setUnreadCount(dlg.unreadCount() + 1); |
278 | 446 | } | 432 | } |
290 | 447 | 433 | } | |
291 | 448 | const QVector<qint32> changedRoles(QVector<qint32>() << UnreadCountRole << DateRole << TopMessageIdRole << TopMessageFromIdRole << | 434 | |
292 | 449 | TopMessageFromFirstNameRole << TopMessageFromLastNameRole << TopMessageFromPhoneRole << | 435 | // Delay refreshing top messages while messages incoming. |
293 | 450 | TopMessageToIdRole << TopMessageOutRole << TopMessageUnreadRole << TopMessageSentRole << | 436 | if (mTopMessagesTimer != 0) { |
294 | 451 | TopMessageDateRole << TopMessageTextRole << TopMessageMediaTypeRole << | 437 | killTimer(mTopMessagesTimer); |
295 | 452 | TopMessageActionTitleRole << TopMessageActionTypeRole << TopMessageActionUserRole << | 438 | } |
296 | 453 | TypingRole << WhoIsTypingRole); | 439 | mTopMessagesTimer = startTimer(200); |
297 | 454 | Q_EMIT dataChanged(index(pos), index(pos), changedRoles); | 440 | } |
298 | 455 | } else { | 441 | |
299 | 456 | qCWarning(TG_PLUGIN_LOGIC) << "onMessageAdded: dialog not found for new top message"; | 442 | void DialogsModel::timerEvent(QTimerEvent *e) { |
300 | 457 | } | 443 | if(e->timerId() == mTopMessagesTimer) { |
301 | 444 | killTimer(mTopMessagesTimer); | ||
302 | 445 | mTopMessagesTimer = 0; | ||
303 | 446 | onTopMessagesChanged(); | ||
304 | 447 | } | ||
305 | 448 | QAbstractListModel::timerEvent(e); | ||
306 | 449 | } | ||
307 | 450 | |||
308 | 451 | void DialogsModel::onTopMessagesChanged() { | ||
309 | 452 | qCDebug(TG_PLUGIN_LOGIC) << "onTopMessagesChanged"; | ||
310 | 453 | |||
311 | 454 | Q_FOREACH(const MessageItem &message, mTopMessages.values()) { | ||
312 | 455 | |||
313 | 456 | qint32 dialogId = message.dialogId(); | ||
314 | 457 | qint32 pos = mDlgIdsMap.value(dialogId, -1); | ||
315 | 458 | |||
316 | 459 | if (0 <= pos && pos < mDialogs.size()) { | ||
317 | 460 | DialogItem &dlg = mDialogs[pos]; | ||
318 | 461 | |||
319 | 462 | if (!message.out()) { | ||
320 | 463 | dlg.setTyping(false); | ||
321 | 464 | } | ||
322 | 465 | |||
323 | 466 | //Remove previous top message id from mapping | ||
324 | 467 | MessageItem oldTopMessage = dlg.topMessage(); | ||
325 | 468 | if (!oldTopMessage.isEmpty()) { | ||
326 | 469 | mTopMessageIdsMap.remove(oldTopMessage.id()); | ||
327 | 470 | } | ||
328 | 471 | |||
329 | 472 | dlg.setTopMessage(message); | ||
330 | 473 | dlg.setDate(message.date()); | ||
331 | 474 | mTopMessageIdsMap.insert(message.id(), dlg.id()); | ||
332 | 475 | |||
333 | 476 | const QVector<qint32> changedRoles(QVector<qint32>() << UnreadCountRole << DateRole << TopMessageIdRole << TopMessageFromIdRole << | ||
334 | 477 | TopMessageFromFirstNameRole << TopMessageFromLastNameRole << TopMessageFromPhoneRole << | ||
335 | 478 | TopMessageToIdRole << TopMessageOutRole << TopMessageUnreadRole << TopMessageSentRole << | ||
336 | 479 | TopMessageDateRole << TopMessageTextRole << TopMessageMediaTypeRole << | ||
337 | 480 | TopMessageActionTitleRole << TopMessageActionTypeRole << TopMessageActionUserRole << | ||
338 | 481 | TypingRole << WhoIsTypingRole); | ||
339 | 482 | Q_EMIT dataChanged(index(pos), index(pos), changedRoles); | ||
340 | 483 | } else { | ||
341 | 484 | qCWarning(TG_PLUGIN_LOGIC) << "onMessageAdded: dialog not found for new top message"; | ||
342 | 485 | } | ||
343 | 486 | } | ||
344 | 487 | |||
345 | 488 | mTopMessages.clear(); | ||
346 | 458 | } | 489 | } |
347 | 459 | 490 | ||
348 | 460 | void DialogsModel::onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount) { | 491 | void DialogsModel::onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount) { |
349 | 461 | 492 | ||
350 | === modified file 'qmlplugin/models/dialogsmodel.h' | |||
351 | --- qmlplugin/models/dialogsmodel.h 2015-02-16 13:51:55 +0000 | |||
352 | +++ qmlplugin/models/dialogsmodel.h 2015-06-01 13:36:23 +0000 | |||
353 | @@ -95,6 +95,9 @@ | |||
354 | 95 | 95 | ||
355 | 96 | Q_INVOKABLE void setTelegramClient(TelegramClient *telegramClient); | 96 | Q_INVOKABLE void setTelegramClient(TelegramClient *telegramClient); |
356 | 97 | 97 | ||
357 | 98 | protected: | ||
358 | 99 | void timerEvent(QTimerEvent *e); | ||
359 | 100 | |||
360 | 98 | private: | 101 | private: |
361 | 99 | QList<DialogItem> mDialogs; | 102 | QList<DialogItem> mDialogs; |
362 | 100 | // correlates dialog->id() --> index in m_dialogs | 103 | // correlates dialog->id() --> index in m_dialogs |
363 | @@ -106,6 +109,9 @@ | |||
364 | 106 | ModelState mState; | 109 | ModelState mState; |
365 | 107 | qint32 mSecretDialogsCount; | 110 | qint32 mSecretDialogsCount; |
366 | 108 | 111 | ||
367 | 112 | qint32 mTopMessagesTimer; | ||
368 | 113 | QMap<qint32, MessageItem> mTopMessages; | ||
369 | 114 | |||
370 | 109 | // reference to telegram client | 115 | // reference to telegram client |
371 | 110 | TelegramClient *mTelegramClient; | 116 | TelegramClient *mTelegramClient; |
372 | 111 | 117 | ||
373 | @@ -129,9 +135,11 @@ | |||
374 | 129 | void onMessageAdded(const MessageItem &message); | 135 | void onMessageAdded(const MessageItem &message); |
375 | 130 | void onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount); | 136 | void onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount); |
376 | 131 | void onOutgoingMessageAdded(qint32 recipientId, const MessageItem &message); | 137 | void onOutgoingMessageAdded(qint32 recipientId, const MessageItem &message); |
377 | 138 | void onTopMessagesChanged(); | ||
378 | 132 | void onMessageUpdated(qint32 msgId, const MessageItem &message); | 139 | void onMessageUpdated(qint32 msgId, const MessageItem &message); |
379 | 133 | void onMessagesDeleted(const QList<qint32> msgIds); | 140 | void onMessagesDeleted(const QList<qint32> msgIds); |
380 | 134 | void onMessagesMarkedAsRead(const QList<qint32> &msgIds); | 141 | void onMessagesMarkedAsRead(const QList<qint32> &msgIds); |
381 | 142 | |||
382 | 135 | void onChatMarkedAsRead(qint32 dialogId); | 143 | void onChatMarkedAsRead(qint32 dialogId); |
383 | 136 | void onChatHistoryDeleted(qint32 dialogId); | 144 | void onChatHistoryDeleted(qint32 dialogId); |
384 | 137 | void onChatDeleted(qint32 dialogId); | 145 | void onChatDeleted(qint32 dialogId); |
385 | 138 | 146 | ||
386 | === modified file 'qmlplugin/telegramclient.cpp' | |||
387 | --- qmlplugin/telegramclient.cpp 2015-04-02 13:13:41 +0000 | |||
388 | +++ qmlplugin/telegramclient.cpp 2015-06-01 13:36:23 +0000 | |||
389 | @@ -95,7 +95,7 @@ | |||
390 | 95 | 95 | ||
391 | 96 | connect(mTelegramService, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32))); | 96 | connect(mTelegramService, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32))); |
392 | 97 | connect(mTelegramService, SIGNAL(messageSent()), SIGNAL(messageSent())); | 97 | connect(mTelegramService, SIGNAL(messageSent()), SIGNAL(messageSent())); |
394 | 98 | connect(mTelegramService, SIGNAL(messageReceived()), SIGNAL(messageReceived())); | 98 | connect(mTelegramService, SIGNAL(messagesReceived(qint32)), SIGNAL(messagesReceived(qint32))); |
395 | 99 | 99 | ||
396 | 100 | // connect database signals | 100 | // connect database signals |
397 | 101 | DbManager &dbManager = mTelegramService->data().dbManager(); | 101 | DbManager &dbManager = mTelegramService->data().dbManager(); |
398 | 102 | 102 | ||
399 | === modified file 'qmlplugin/telegramclient.h' | |||
400 | --- qmlplugin/telegramclient.h 2015-04-02 13:13:41 +0000 | |||
401 | +++ qmlplugin/telegramclient.h 2015-06-01 13:36:23 +0000 | |||
402 | @@ -161,7 +161,7 @@ | |||
403 | 161 | 161 | ||
404 | 162 | void unreadCountChanged(qint32 unreadCount); | 162 | void unreadCountChanged(qint32 unreadCount); |
405 | 163 | void messageSent(); | 163 | void messageSent(); |
407 | 164 | void messageReceived(); | 164 | void messagesReceived(qint32 count); |
408 | 165 | 165 | ||
409 | 166 | void userTyping(qint32 dialogId, const QString &whoIsTyping = QString()); | 166 | void userTyping(qint32 dialogId, const QString &whoIsTyping = QString()); |
410 | 167 | 167 | ||
411 | 168 | 168 | ||
412 | === modified file 'qmlplugin/telegramservice.cpp' | |||
413 | --- qmlplugin/telegramservice.cpp 2015-05-05 17:09:36 +0000 | |||
414 | +++ qmlplugin/telegramservice.cpp 2015-06-01 13:36:23 +0000 | |||
415 | @@ -68,7 +68,7 @@ | |||
416 | 68 | connect(&mData, SIGNAL(dialogsAdded(QList<DialogItem>,qint32)), SIGNAL(dialogsAdded(QList<DialogItem>,qint32))); | 68 | connect(&mData, SIGNAL(dialogsAdded(QList<DialogItem>,qint32)), SIGNAL(dialogsAdded(QList<DialogItem>,qint32))); |
417 | 69 | connect(&mData, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32))); | 69 | connect(&mData, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32))); |
418 | 70 | connect(&mData, SIGNAL(messageSent()), SIGNAL(messageSent())); | 70 | connect(&mData, SIGNAL(messageSent()), SIGNAL(messageSent())); |
420 | 71 | connect(&mData, SIGNAL(messageReceived()), SIGNAL(messageReceived())); | 71 | connect(&mData, SIGNAL(messagesReceived(qint32)), SIGNAL(messagesReceived(qint32))); |
421 | 72 | connect(&mData, SIGNAL(secretChatRequested(qint32,qint32,qint32,qint64)), SIGNAL(secretChatRequested(qint32,qint32,qint32,qint64))); | 72 | connect(&mData, SIGNAL(secretChatRequested(qint32,qint32,qint32,qint64)), SIGNAL(secretChatRequested(qint32,qint32,qint32,qint64))); |
422 | 73 | connect(&mData, SIGNAL(secretChatCreated(qint32)), SIGNAL(secretChatCreated(qint32))); | 73 | connect(&mData, SIGNAL(secretChatCreated(qint32)), SIGNAL(secretChatCreated(qint32))); |
423 | 74 | connect(&mData, SIGNAL(secretChatDiscarded(qint32)), SIGNAL(secretChatDiscarded(qint32))); | 74 | connect(&mData, SIGNAL(secretChatDiscarded(qint32)), SIGNAL(secretChatDiscarded(qint32))); |
424 | @@ -78,9 +78,7 @@ | |||
425 | 78 | 78 | ||
426 | 79 | mSelfDestructTimer.setSingleShot(true); | 79 | mSelfDestructTimer.setSingleShot(true); |
427 | 80 | connect(&mSelfDestructTimer, SIGNAL(timeout()), this, SLOT(processSelfDestructMessages())); | 80 | connect(&mSelfDestructTimer, SIGNAL(timeout()), this, SLOT(processSelfDestructMessages())); |
431 | 81 | connect(&mData, SIGNAL(messageAdded(MessageItem)), &mSelfDestructTimer, SIGNAL(timeout())); | 81 | connect(&mData, SIGNAL(selfDestructMessages()), &mSelfDestructTimer, SIGNAL(timeout())); |
429 | 82 | connect(&mData, SIGNAL(messagesMarkedAsRead(QList<qint32>)),&mSelfDestructTimer, SIGNAL(timeout())); | ||
430 | 83 | connect(&mData, SIGNAL(outgoingMessageAdded(qint32,MessageItem)), &mSelfDestructTimer, SIGNAL(timeout())); | ||
432 | 84 | connect(this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool)), &mSelfDestructTimer, SIGNAL(timeout())); | 82 | connect(this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool)), &mSelfDestructTimer, SIGNAL(timeout())); |
433 | 85 | } | 83 | } |
434 | 86 | 84 | ||
435 | @@ -128,7 +126,7 @@ | |||
436 | 128 | } | 126 | } |
437 | 129 | 127 | ||
438 | 130 | mTelegramLib->init(); | 128 | mTelegramLib->init(); |
440 | 131 | mSelfDestructTimer.start(); | 129 | QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection); |
441 | 132 | } | 130 | } |
442 | 133 | 131 | ||
443 | 134 | void TelegramService::shutdown() { | 132 | void TelegramService::shutdown() { |
444 | @@ -162,7 +160,7 @@ | |||
445 | 162 | 160 | ||
446 | 163 | void TelegramService::onWoken() { | 161 | void TelegramService::onWoken() { |
447 | 164 | mTelegramLib->updatesGetState(); | 162 | mTelegramLib->updatesGetState(); |
449 | 165 | mSelfDestructTimer.start(); | 163 | QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection); |
450 | 166 | updateUserProfiles(); | 164 | updateUserProfiles(); |
451 | 167 | Q_EMIT woken(); | 165 | Q_EMIT woken(); |
452 | 168 | } | 166 | } |
453 | @@ -944,6 +942,10 @@ | |||
454 | 944 | } | 942 | } |
455 | 945 | 943 | ||
456 | 946 | void TelegramService::processSelfDestructMessages() { | 944 | void TelegramService::processSelfDestructMessages() { |
457 | 945 | QTime time; | ||
458 | 946 | time.start(); | ||
459 | 947 | qCDebug(TG_PLUGIN_LOGIC) << "processSelfDestructMessages"; | ||
460 | 948 | |||
461 | 947 | QSqlQuery query; | 949 | QSqlQuery query; |
462 | 948 | 950 | ||
463 | 949 | // Purge expired messages. | 951 | // Purge expired messages. |
464 | @@ -965,6 +967,9 @@ | |||
465 | 965 | if (query.exec() && query.next()) { | 967 | if (query.exec() && query.next()) { |
466 | 966 | if (query.value("expires").isNull()) { | 968 | if (query.value("expires").isNull()) { |
467 | 967 | qCDebug(TG_PLUGIN_LOGIC) << "TTL: all expired messages deleted"; | 969 | qCDebug(TG_PLUGIN_LOGIC) << "TTL: all expired messages deleted"; |
468 | 970 | if (mSelfDestructTimer.isActive()) { | ||
469 | 971 | QMetaObject::invokeMethod(&mSelfDestructTimer, "stop", Qt::QueuedConnection); | ||
470 | 972 | } | ||
471 | 968 | return; | 973 | return; |
472 | 969 | } | 974 | } |
473 | 970 | 975 | ||
474 | @@ -972,14 +977,17 @@ | |||
475 | 972 | if (nextInSeconds > 0) { | 977 | if (nextInSeconds > 0) { |
476 | 973 | qCDebug(TG_PLUGIN_LOGIC) << "TTL: next message in" << nextInSeconds << "s"; | 978 | qCDebug(TG_PLUGIN_LOGIC) << "TTL: next message in" << nextInSeconds << "s"; |
477 | 974 | if (mSelfDestructTimer.isActive()) { | 979 | if (mSelfDestructTimer.isActive()) { |
479 | 975 | mSelfDestructTimer.stop(); | 980 | QMetaObject::invokeMethod(&mSelfDestructTimer, "stop", Qt::QueuedConnection); |
480 | 976 | } | 981 | } |
482 | 977 | mSelfDestructTimer.start(1000*nextInSeconds); | 982 | QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection, |
483 | 983 | Q_ARG(qint32, 1000*nextInSeconds)); | ||
484 | 978 | } else { | 984 | } else { |
485 | 979 | // We already have an expired message. | 985 | // We already have an expired message. |
487 | 980 | mSelfDestructTimer.start(500); | 986 | QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection, |
488 | 987 | Q_ARG(qint32, 500)); | ||
489 | 981 | } | 988 | } |
490 | 982 | } | 989 | } |
491 | 990 | qCDebug(TG_PLUGIN_PROFILING) << "processSelfDestructMessages - end:" << time.elapsed() << "ms"; | ||
492 | 983 | } | 991 | } |
493 | 984 | 992 | ||
494 | 985 | void TelegramService::createCrashFile() { | 993 | void TelegramService::createCrashFile() { |
495 | 986 | 994 | ||
496 | === modified file 'qmlplugin/telegramservice.h' | |||
497 | --- qmlplugin/telegramservice.h 2015-03-26 17:16:20 +0000 | |||
498 | +++ qmlplugin/telegramservice.h 2015-06-01 13:36:23 +0000 | |||
499 | @@ -162,7 +162,7 @@ | |||
500 | 162 | 162 | ||
501 | 163 | void unreadCountChanged(qint32 unreadCount); | 163 | void unreadCountChanged(qint32 unreadCount); |
502 | 164 | void messageSent(); | 164 | void messageSent(); |
504 | 165 | void messageReceived(); | 165 | void messagesReceived(qint32 count); |
505 | 166 | 166 | ||
506 | 167 | void userTyping(qint32 dialogId, const QString &whoIsTyping = QString()); | 167 | void userTyping(qint32 dialogId, const QString &whoIsTyping = QString()); |
507 | 168 | 168 |
Brilliant!!!
Tested and superquick