Merge lp:~libqtelegram-team/telegram-app/lib-fix-delays into lp:telegram-app/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
Reviewer Review Type Date Requested Status
Roberto Mier Escandon (community) Approve
Review via email: mp+260708@code.launchpad.net

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.

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Brilliant!!!
Tested and superquick

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'qmlplugin/data.cpp'
--- qmlplugin/data.cpp 2015-05-05 17:09:36 +0000
+++ qmlplugin/data.cpp 2015-06-01 13:36:23 +0000
@@ -33,7 +33,8 @@
33 mFilesAvgTime(0),33 mFilesAvgTime(0),
34 mFilesCount(0),34 mFilesCount(0),
35 mFilesTotalTime(0),35 mFilesTotalTime(0),
36 mLastUnreadCount(-1) {36 mLastUnreadCount(-1),
37 mBadgeUpdateTimer(0) {
3738
38 // Priorities for thumbnail sizes are m, b, s, a, x, c, y, d, w39 // Priorities for thumbnail sizes are m, b, s, a, x, c, y, d, w
39 mPhotoSmallPriorities.insert("m", 1);40 mPhotoSmallPriorities.insert("m", 1);
@@ -149,6 +150,7 @@
149 }150 }
150 }151 }
151152
153 qint32 newMessagesReceivedCount = 0;
152 Q_FOREACH (const Message &message, messages) {154 Q_FOREACH (const Message &message, messages) {
153155
154 qint32 dialogId = Tools::getBelongingDialogId(message);156 qint32 dialogId = Tools::getBelongingDialogId(message);
@@ -179,7 +181,11 @@
179 TelegramService *service = static_cast<TelegramService *>(mServiceRef);181 TelegramService *service = static_cast<TelegramService *>(mServiceRef);
180 service->messagesGetDialogs(0, dialogId, 1);182 service->messagesGetDialogs(0, dialogId, 1);
181 }183 }
184
185 newMessagesReceivedCount += (!message.out() && message.unread()) ? 1 : 0;
182 }186 }
187 Q_EMIT messagesReceived(newMessagesReceivedCount);
188 updateBadge();
183189
184 Q_FOREACH (const SecretChatMessage &secretChatMessage, secretChatMessages) {190 Q_FOREACH (const SecretChatMessage &secretChatMessage, secretChatMessages) {
185191
@@ -250,9 +256,10 @@
250 }256 }
251257
252 if (!isIntermediateState) {258 if (!isIntermediateState) {
253 surfaceUnreadCount();259 updateBadge();
254 }260 }
255261
262 Q_EMIT selfDestructMessages();
256 qCDebug(TG_PLUGIN_PROFILING) << "onUpdatesGetDifferenceAnswer - end:" << time.elapsed() << "ms";263 qCDebug(TG_PLUGIN_PROFILING) << "onUpdatesGetDifferenceAnswer - end:" << time.elapsed() << "ms";
257}264}
258265
@@ -1700,7 +1707,7 @@
1700 }1707 }
17011708
1702 Q_EMIT messagesAdded(messageItems, messageItems.count());1709 Q_EMIT messagesAdded(messageItems, messageItems.count());
17031710 Q_EMIT selfDestructMessages();
1704 qCDebug(TG_PLUGIN_PROFILING) << "onMessagesForwardMessagesAnswer - end";1711 qCDebug(TG_PLUGIN_PROFILING) << "onMessagesForwardMessagesAnswer - end";
1705}1712}
17061713
@@ -1803,6 +1810,8 @@
1803 mDbManager.finishTransaction();1810 mDbManager.finishTransaction();
18041811
1805 Q_EMIT messageAdded(messageItem);1812 Q_EMIT messageAdded(messageItem);
1813 Q_EMIT messagesReceived(1);
1814 Q_EMIT selfDestructMessages();
1806}1815}
18071816
1808void Data::onUpdateShort(const Update &update, qint32 date) {1817void Data::onUpdateShort(const Update &update, qint32 date) {
@@ -1899,6 +1908,7 @@
18991908
1900 MessageItem messageItem = getMessage(message.randomId());1909 MessageItem messageItem = getMessage(message.randomId());
1901 Q_EMIT outgoingMessageAdded(chatId, messageItem);1910 Q_EMIT outgoingMessageAdded(chatId, messageItem);
1911 Q_EMIT selfDestructMessages();
19021912
1903 // 'local' is the size for sent photos until having a server location and different sizes1913 // 'local' is the size for sent photos until having a server location and different sizes
1904 // if there is a mediaLocalPath and media type is photo ro video, emit photo updated signal. Same for video1914 // if there is a mediaLocalPath and media type is photo ro video, emit photo updated signal. Same for video
@@ -2518,7 +2528,8 @@
2518 service->messagesReceivedQueue(qts);2528 service->messagesReceivedQueue(qts);
25192529
2520 Q_EMIT messageAdded(messageItem);2530 Q_EMIT messageAdded(messageItem);
2521 surfaceUnreadCount();2531 updateBadge();
2532 Q_EMIT selfDestructMessages();
25222533
2523 qCDebug(TG_PLUGIN_PROFILING) << "onUpdateSecretChatMessage - end:" << time.elapsed() << "ms";2534 qCDebug(TG_PLUGIN_PROFILING) << "onUpdateSecretChatMessage - end:" << time.elapsed() << "ms";
2524}2535}
@@ -2655,6 +2666,7 @@
2655 qCCritical(TG_PLUGIN_LOGIC) << "Impossible insert new received message";2666 qCCritical(TG_PLUGIN_LOGIC) << "Impossible insert new received message";
2656 return false;2667 return false;
2657 }2668 }
2669 Q_EMIT messagesReceived(1);
26582670
2659 if (!executeAction(message)) {2671 if (!executeAction(message)) {
2660 mDbManager.rollbackTransaction();2672 mDbManager.rollbackTransaction();
@@ -2672,6 +2684,7 @@
26722684
2673 MessageItem messageItem = getMessage(message.id());2685 MessageItem messageItem = getMessage(message.id());
2674 Q_EMIT messageAdded(messageItem);2686 Q_EMIT messageAdded(messageItem);
2687 Q_EMIT selfDestructMessages();
26752688
2676 if (newDialog) {2689 if (newDialog) {
2677 // Ask telegram servers for info about this just created dialog where it will be included the phone number2690 // Ask telegram servers for info about this just created dialog where it will be included the phone number
@@ -2687,6 +2700,7 @@
2687 case Update::typeUpdateReadMessages: {2700 case Update::typeUpdateReadMessages: {
2688 if (markMessagesAsRead(update.messages())) {2701 if (markMessagesAsRead(update.messages())) {
2689 Q_EMIT messagesMarkedAsRead(update.messages());2702 Q_EMIT messagesMarkedAsRead(update.messages());
2703 Q_EMIT selfDestructMessages();
2690 }2704 }
26912705
2692 UpdatesState clientState = getState();2706 UpdatesState clientState = getState();
@@ -2893,7 +2907,7 @@
2893}2907}
28942908
2895bool Data::getProfilePhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) {2909bool Data::getProfilePhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) {
28962910
2897 if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) {2911 if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) {
2898 // Search in database if same location parameter are stored for thumbnail that2912 // Search in database if same location parameter are stored for thumbnail that
2899 // received ones. In that case don't download cos it's the same file2913 // received ones. In that case don't download cos it's the same file
@@ -2911,7 +2925,7 @@
2911}2925}
29122926
2913bool Data::downloadPhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) {2927bool Data::downloadPhotoFileFromServer(const FileLocation &serverLocation, qint32 id, bool isUser, bool isThumbnail) {
29142928 qCWarning(TG_PLUGIN_LOGIC) << "Data::downloadPhotoFileFromServer";
2915 if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) {2929 if (serverLocation.classType() != FileLocation::typeFileLocationUnavailable) {
2916 // create object with the data of the file to be downloaded2930 // create object with the data of the file to be downloaded
2917 TelegramService *service = static_cast<TelegramService *>(mServiceRef);2931 TelegramService *service = static_cast<TelegramService *>(mServiceRef);
@@ -3891,7 +3905,7 @@
3891 }3905 }
38923906
3893 if (!query.next()) {3907 if (!query.next()) {
3894 qCCritical(TG_PLUGIN_LOGIC) << "Message to update not found.";3908 qCDebug(TG_PLUGIN_LOGIC) << "Message to update not found.";
3895 return false;3909 return false;
3896 }3910 }
38973911
@@ -4925,11 +4939,7 @@
49254939
4926 mDbManager.finishTransaction();4940 mDbManager.finishTransaction();
49274941
4928 if (!message.out() && message.unread()) {4942 updateBadge();
4929 Q_EMIT messageReceived();
4930 }
4931
4932 surfaceUnreadCount();
49334943
4934 return true;4944 return true;
4935}4945}
@@ -5128,7 +5138,7 @@
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"));
5129 query.bindValue(":dialogId", chatId);5139 query.bindValue(":dialogId", chatId);
5130 if (query.exec()) {5140 if (query.exec()) {
5131 surfaceUnreadCount();5141 updateBadge();
5132 }5142 }
51335143
5134 Q_EMIT chatMarkedAsRead(chatId);5144 Q_EMIT chatMarkedAsRead(chatId);
@@ -5178,7 +5188,7 @@
51785188
5179 mDbManager.finishTransaction();5189 mDbManager.finishTransaction();
51805190
5181 surfaceUnreadCount();5191 updateBadge();
51825192
5183 return true;5193 return true;
5184}5194}
@@ -6647,7 +6657,23 @@
6647 return dialog;6657 return dialog;
6648}6658}
66496659
6650void Data::surfaceUnreadCount() {6660void Data::updateBadge() {
6661 if (mBadgeUpdateTimer != 0) {
6662 killTimer(mBadgeUpdateTimer);
6663 }
6664 mBadgeUpdateTimer = startTimer(200);
6665}
6666
6667void Data::timerEvent(QTimerEvent *e) {
6668 if(e->timerId() == mBadgeUpdateTimer) {
6669 killTimer(mBadgeUpdateTimer);
6670 mBadgeUpdateTimer = 0;
6671 onUpdateBadge();
6672 }
6673 QObject::timerEvent(e);
6674}
6675
6676void Data::onUpdateBadge() {
6651 QSqlQuery query;6677 QSqlQuery query;
6652 query.prepare(QString("SELECT SUM(unreadCount) AS unreadCount FROM dialogsView"));6678 query.prepare(QString("SELECT SUM(unreadCount) AS unreadCount FROM dialogsView"));
66536679
66546680
=== modified file 'qmlplugin/data.h'
--- qmlplugin/data.h 2015-05-05 17:09:36 +0000
+++ qmlplugin/data.h 2015-06-01 13:36:23 +0000
@@ -212,6 +212,8 @@
212 void updateChatPhoto(qint32 chatId, const Photo &photo);212 void updateChatPhoto(qint32 chatId, const Photo &photo);
213 void updateChatFull(const ChatFull &chatFull);213 void updateChatFull(const ChatFull &chatFull);
214214
215 void timerEvent(QTimerEvent *e);
216
215Q_SIGNALS:217Q_SIGNALS:
216 void userInfo(const ContactItem &user);218 void userInfo(const ContactItem &user);
217219
@@ -234,6 +236,7 @@
234 void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount);236 void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount);
235 void messageAdded(const MessageItem &message);237 void messageAdded(const MessageItem &message);
236 void outgoingMessageAdded(qint32 recipientId, const MessageItem &message);238 void outgoingMessageAdded(qint32 recipientId, const MessageItem &message);
239 void selfDestructMessages();
237 void messageUpdated(qint32 msgId, const MessageItem &message);240 void messageUpdated(qint32 msgId, const MessageItem &message);
238241
239 void chatMarkedAsRead(qint32 chatId);242 void chatMarkedAsRead(qint32 chatId);
@@ -247,7 +250,7 @@
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);
248251
249 void messageSent();252 void messageSent();
250 void messageReceived();253 void messagesReceived(qint32 count);
251254
252 void downloadingUpdated(qint32 id, bool downloading);255 void downloadingUpdated(qint32 id, bool downloading);
253 void downloadedPercentageUpdated(qint32 id, qint8 downloadedPercentage);256 void downloadedPercentageUpdated(qint32 id, qint8 downloadedPercentage);
@@ -271,6 +274,7 @@
271 DbManager mDbManager;274 DbManager mDbManager;
272275
273 qint32 mLastUnreadCount;276 qint32 mLastUnreadCount;
277 qint32 mBadgeUpdateTimer;
274278
275 // time mesurement map for file downloading. Correlates fileId with a QTime object for calculate total download time279 // time mesurement map for file downloading. Correlates fileId with a QTime object for calculate total download time
276 QMap<qint64, QTime *> mFileTimes;280 QMap<qint64, QTime *> mFileTimes;
@@ -346,7 +350,8 @@
346 bool muteDialog(qint32 dialogId, bool muted);350 bool muteDialog(qint32 dialogId, bool muted);
347 bool muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted);351 bool muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted);
348352
349 void surfaceUnreadCount();353 void updateBadge();
354 void onUpdateBadge();
350355
351 bool exists(qint32 id, bool isUser);356 bool exists(qint32 id, bool isUser);
352357
353358
=== modified file 'qmlplugin/models/dialogsmodel.cpp'
--- qmlplugin/models/dialogsmodel.cpp 2015-02-16 13:51:55 +0000
+++ qmlplugin/models/dialogsmodel.cpp 2015-06-01 13:36:23 +0000
@@ -28,6 +28,7 @@
28 mCanFetchMore(true),28 mCanFetchMore(true),
29 mState(Created),29 mState(Created),
30 mSecretDialogsCount(0),30 mSecretDialogsCount(0),
31 mTopMessagesTimer(0),
31 mTelegramClient(0) {32 mTelegramClient(0) {
32}33}
3334
@@ -420,41 +421,71 @@
420}421}
421422
422void DialogsModel::onMessageAdded(const MessageItem &message) {423void DialogsModel::onMessageAdded(const MessageItem &message) {
424 mTopMessages.insert(message.dialogId(), message);
423425
424 qint32 dialogId = message.dialogId();426 qint32 dialogId = message.dialogId();
425 qint32 pos = mDlgIdsMap.value(dialogId, -1);427 qint32 pos = mDlgIdsMap.value(dialogId, -1);
426
427 if (0 <= pos && pos < mDialogs.size()) {428 if (0 <= pos && pos < mDialogs.size()) {
428 DialogItem &dlg = mDialogs[pos];
429
430 if (!message.out()) {
431 dlg.setTyping(false);
432 }
433
434 //Remove previous top message id from mapping
435 MessageItem oldTopMessage = dlg.topMessage();
436 if (!oldTopMessage.isEmpty()) {
437 mTopMessageIdsMap.remove(oldTopMessage.id());
438 }
439
440 dlg.setTopMessage(message);
441 dlg.setDate(message.date());
442 mTopMessageIdsMap.insert(message.id(), dlg.id());
443
444 if (!message.out() && message.unread()) {429 if (!message.out() && message.unread()) {
430 DialogItem &dlg = mDialogs[pos];
445 dlg.setUnreadCount(dlg.unreadCount() + 1);431 dlg.setUnreadCount(dlg.unreadCount() + 1);
446 }432 }
447433 }
448 const QVector<qint32> changedRoles(QVector<qint32>() << UnreadCountRole << DateRole << TopMessageIdRole << TopMessageFromIdRole <<434
449 TopMessageFromFirstNameRole << TopMessageFromLastNameRole << TopMessageFromPhoneRole <<435 // Delay refreshing top messages while messages incoming.
450 TopMessageToIdRole << TopMessageOutRole << TopMessageUnreadRole << TopMessageSentRole <<436 if (mTopMessagesTimer != 0) {
451 TopMessageDateRole << TopMessageTextRole << TopMessageMediaTypeRole <<437 killTimer(mTopMessagesTimer);
452 TopMessageActionTitleRole << TopMessageActionTypeRole << TopMessageActionUserRole <<438 }
453 TypingRole << WhoIsTypingRole);439 mTopMessagesTimer = startTimer(200);
454 Q_EMIT dataChanged(index(pos), index(pos), changedRoles);440}
455 } else {441
456 qCWarning(TG_PLUGIN_LOGIC) << "onMessageAdded: dialog not found for new top message";442void DialogsModel::timerEvent(QTimerEvent *e) {
457 }443 if(e->timerId() == mTopMessagesTimer) {
444 killTimer(mTopMessagesTimer);
445 mTopMessagesTimer = 0;
446 onTopMessagesChanged();
447 }
448 QAbstractListModel::timerEvent(e);
449}
450
451void DialogsModel::onTopMessagesChanged() {
452 qCDebug(TG_PLUGIN_LOGIC) << "onTopMessagesChanged";
453
454 Q_FOREACH(const MessageItem &message, mTopMessages.values()) {
455
456 qint32 dialogId = message.dialogId();
457 qint32 pos = mDlgIdsMap.value(dialogId, -1);
458
459 if (0 <= pos && pos < mDialogs.size()) {
460 DialogItem &dlg = mDialogs[pos];
461
462 if (!message.out()) {
463 dlg.setTyping(false);
464 }
465
466 //Remove previous top message id from mapping
467 MessageItem oldTopMessage = dlg.topMessage();
468 if (!oldTopMessage.isEmpty()) {
469 mTopMessageIdsMap.remove(oldTopMessage.id());
470 }
471
472 dlg.setTopMessage(message);
473 dlg.setDate(message.date());
474 mTopMessageIdsMap.insert(message.id(), dlg.id());
475
476 const QVector<qint32> changedRoles(QVector<qint32>() << UnreadCountRole << DateRole << TopMessageIdRole << TopMessageFromIdRole <<
477 TopMessageFromFirstNameRole << TopMessageFromLastNameRole << TopMessageFromPhoneRole <<
478 TopMessageToIdRole << TopMessageOutRole << TopMessageUnreadRole << TopMessageSentRole <<
479 TopMessageDateRole << TopMessageTextRole << TopMessageMediaTypeRole <<
480 TopMessageActionTitleRole << TopMessageActionTypeRole << TopMessageActionUserRole <<
481 TypingRole << WhoIsTypingRole);
482 Q_EMIT dataChanged(index(pos), index(pos), changedRoles);
483 } else {
484 qCWarning(TG_PLUGIN_LOGIC) << "onMessageAdded: dialog not found for new top message";
485 }
486 }
487
488 mTopMessages.clear();
458}489}
459490
460void DialogsModel::onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount) {491void DialogsModel::onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount) {
461492
=== modified file 'qmlplugin/models/dialogsmodel.h'
--- qmlplugin/models/dialogsmodel.h 2015-02-16 13:51:55 +0000
+++ qmlplugin/models/dialogsmodel.h 2015-06-01 13:36:23 +0000
@@ -95,6 +95,9 @@
9595
96 Q_INVOKABLE void setTelegramClient(TelegramClient *telegramClient);96 Q_INVOKABLE void setTelegramClient(TelegramClient *telegramClient);
9797
98protected:
99 void timerEvent(QTimerEvent *e);
100
98private:101private:
99 QList<DialogItem> mDialogs;102 QList<DialogItem> mDialogs;
100 // correlates dialog->id() --> index in m_dialogs103 // correlates dialog->id() --> index in m_dialogs
@@ -106,6 +109,9 @@
106 ModelState mState;109 ModelState mState;
107 qint32 mSecretDialogsCount;110 qint32 mSecretDialogsCount;
108111
112 qint32 mTopMessagesTimer;
113 QMap<qint32, MessageItem> mTopMessages;
114
109 // reference to telegram client115 // reference to telegram client
110 TelegramClient *mTelegramClient;116 TelegramClient *mTelegramClient;
111117
@@ -129,9 +135,11 @@
129 void onMessageAdded(const MessageItem &message);135 void onMessageAdded(const MessageItem &message);
130 void onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount);136 void onMessagesAdded(const QList<MessageItem> &messages, qint32 totalCount);
131 void onOutgoingMessageAdded(qint32 recipientId, const MessageItem &message);137 void onOutgoingMessageAdded(qint32 recipientId, const MessageItem &message);
138 void onTopMessagesChanged();
132 void onMessageUpdated(qint32 msgId, const MessageItem &message);139 void onMessageUpdated(qint32 msgId, const MessageItem &message);
133 void onMessagesDeleted(const QList<qint32> msgIds);140 void onMessagesDeleted(const QList<qint32> msgIds);
134 void onMessagesMarkedAsRead(const QList<qint32> &msgIds);141 void onMessagesMarkedAsRead(const QList<qint32> &msgIds);
142
135 void onChatMarkedAsRead(qint32 dialogId);143 void onChatMarkedAsRead(qint32 dialogId);
136 void onChatHistoryDeleted(qint32 dialogId);144 void onChatHistoryDeleted(qint32 dialogId);
137 void onChatDeleted(qint32 dialogId);145 void onChatDeleted(qint32 dialogId);
138146
=== modified file 'qmlplugin/telegramclient.cpp'
--- qmlplugin/telegramclient.cpp 2015-04-02 13:13:41 +0000
+++ qmlplugin/telegramclient.cpp 2015-06-01 13:36:23 +0000
@@ -95,7 +95,7 @@
9595
96 connect(mTelegramService, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32)));96 connect(mTelegramService, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32)));
97 connect(mTelegramService, SIGNAL(messageSent()), SIGNAL(messageSent()));97 connect(mTelegramService, SIGNAL(messageSent()), SIGNAL(messageSent()));
98 connect(mTelegramService, SIGNAL(messageReceived()), SIGNAL(messageReceived()));98 connect(mTelegramService, SIGNAL(messagesReceived(qint32)), SIGNAL(messagesReceived(qint32)));
9999
100 // connect database signals100 // connect database signals
101 DbManager &dbManager = mTelegramService->data().dbManager();101 DbManager &dbManager = mTelegramService->data().dbManager();
102102
=== modified file 'qmlplugin/telegramclient.h'
--- qmlplugin/telegramclient.h 2015-04-02 13:13:41 +0000
+++ qmlplugin/telegramclient.h 2015-06-01 13:36:23 +0000
@@ -161,7 +161,7 @@
161161
162 void unreadCountChanged(qint32 unreadCount);162 void unreadCountChanged(qint32 unreadCount);
163 void messageSent();163 void messageSent();
164 void messageReceived();164 void messagesReceived(qint32 count);
165165
166 void userTyping(qint32 dialogId, const QString &whoIsTyping = QString());166 void userTyping(qint32 dialogId, const QString &whoIsTyping = QString());
167167
168168
=== modified file 'qmlplugin/telegramservice.cpp'
--- qmlplugin/telegramservice.cpp 2015-05-05 17:09:36 +0000
+++ qmlplugin/telegramservice.cpp 2015-06-01 13:36:23 +0000
@@ -68,7 +68,7 @@
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)));
69 connect(&mData, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32)));69 connect(&mData, SIGNAL(unreadCountChanged(qint32)), SIGNAL(unreadCountChanged(qint32)));
70 connect(&mData, SIGNAL(messageSent()), SIGNAL(messageSent()));70 connect(&mData, SIGNAL(messageSent()), SIGNAL(messageSent()));
71 connect(&mData, SIGNAL(messageReceived()), SIGNAL(messageReceived()));71 connect(&mData, SIGNAL(messagesReceived(qint32)), SIGNAL(messagesReceived(qint32)));
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)));
73 connect(&mData, SIGNAL(secretChatCreated(qint32)), SIGNAL(secretChatCreated(qint32)));73 connect(&mData, SIGNAL(secretChatCreated(qint32)), SIGNAL(secretChatCreated(qint32)));
74 connect(&mData, SIGNAL(secretChatDiscarded(qint32)), SIGNAL(secretChatDiscarded(qint32)));74 connect(&mData, SIGNAL(secretChatDiscarded(qint32)), SIGNAL(secretChatDiscarded(qint32)));
@@ -78,9 +78,7 @@
7878
79 mSelfDestructTimer.setSingleShot(true);79 mSelfDestructTimer.setSingleShot(true);
80 connect(&mSelfDestructTimer, SIGNAL(timeout()), this, SLOT(processSelfDestructMessages()));80 connect(&mSelfDestructTimer, SIGNAL(timeout()), this, SLOT(processSelfDestructMessages()));
81 connect(&mData, SIGNAL(messageAdded(MessageItem)), &mSelfDestructTimer, SIGNAL(timeout()));81 connect(&mData, SIGNAL(selfDestructMessages()), &mSelfDestructTimer, SIGNAL(timeout()));
82 connect(&mData, SIGNAL(messagesMarkedAsRead(QList<qint32>)),&mSelfDestructTimer, SIGNAL(timeout()));
83 connect(&mData, SIGNAL(outgoingMessageAdded(qint32,MessageItem)), &mSelfDestructTimer, SIGNAL(timeout()));
84 connect(this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool)), &mSelfDestructTimer, SIGNAL(timeout()));82 connect(this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool)), &mSelfDestructTimer, SIGNAL(timeout()));
85}83}
8684
@@ -128,7 +126,7 @@
128 }126 }
129127
130 mTelegramLib->init();128 mTelegramLib->init();
131 mSelfDestructTimer.start();129 QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection);
132}130}
133131
134void TelegramService::shutdown() {132void TelegramService::shutdown() {
@@ -162,7 +160,7 @@
162160
163void TelegramService::onWoken() {161void TelegramService::onWoken() {
164 mTelegramLib->updatesGetState();162 mTelegramLib->updatesGetState();
165 mSelfDestructTimer.start();163 QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection);
166 updateUserProfiles();164 updateUserProfiles();
167 Q_EMIT woken();165 Q_EMIT woken();
168}166}
@@ -944,6 +942,10 @@
944}942}
945943
946void TelegramService::processSelfDestructMessages() {944void TelegramService::processSelfDestructMessages() {
945 QTime time;
946 time.start();
947 qCDebug(TG_PLUGIN_LOGIC) << "processSelfDestructMessages";
948
947 QSqlQuery query;949 QSqlQuery query;
948950
949 // Purge expired messages.951 // Purge expired messages.
@@ -965,6 +967,9 @@
965 if (query.exec() && query.next()) {967 if (query.exec() && query.next()) {
966 if (query.value("expires").isNull()) {968 if (query.value("expires").isNull()) {
967 qCDebug(TG_PLUGIN_LOGIC) << "TTL: all expired messages deleted";969 qCDebug(TG_PLUGIN_LOGIC) << "TTL: all expired messages deleted";
970 if (mSelfDestructTimer.isActive()) {
971 QMetaObject::invokeMethod(&mSelfDestructTimer, "stop", Qt::QueuedConnection);
972 }
968 return;973 return;
969 }974 }
970975
@@ -972,14 +977,17 @@
972 if (nextInSeconds > 0) {977 if (nextInSeconds > 0) {
973 qCDebug(TG_PLUGIN_LOGIC) << "TTL: next message in" << nextInSeconds << "s";978 qCDebug(TG_PLUGIN_LOGIC) << "TTL: next message in" << nextInSeconds << "s";
974 if (mSelfDestructTimer.isActive()) {979 if (mSelfDestructTimer.isActive()) {
975 mSelfDestructTimer.stop();980 QMetaObject::invokeMethod(&mSelfDestructTimer, "stop", Qt::QueuedConnection);
976 }981 }
977 mSelfDestructTimer.start(1000*nextInSeconds);982 QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection,
983 Q_ARG(qint32, 1000*nextInSeconds));
978 } else {984 } else {
979 // We already have an expired message.985 // We already have an expired message.
980 mSelfDestructTimer.start(500);986 QMetaObject::invokeMethod(&mSelfDestructTimer, "start", Qt::QueuedConnection,
987 Q_ARG(qint32, 500));
981 }988 }
982 }989 }
990 qCDebug(TG_PLUGIN_PROFILING) << "processSelfDestructMessages - end:" << time.elapsed() << "ms";
983}991}
984992
985void TelegramService::createCrashFile() {993void TelegramService::createCrashFile() {
986994
=== modified file 'qmlplugin/telegramservice.h'
--- qmlplugin/telegramservice.h 2015-03-26 17:16:20 +0000
+++ qmlplugin/telegramservice.h 2015-06-01 13:36:23 +0000
@@ -162,7 +162,7 @@
162162
163 void unreadCountChanged(qint32 unreadCount);163 void unreadCountChanged(qint32 unreadCount);
164 void messageSent();164 void messageSent();
165 void messageReceived();165 void messagesReceived(qint32 count);
166166
167 void userTyping(qint32 dialogId, const QString &whoIsTyping = QString());167 void userTyping(qint32 dialogId, const QString &whoIsTyping = QString());
168168

Subscribers

People subscribed via source and target branches

to all changes: