diff --git a/autogenerated/clientsyncmanager.cpp b/autogenerated/clientsyncmanager.cpp index 470fad7..7e8fd7d 100644 --- a/autogenerated/clientsyncmanager.cpp +++ b/autogenerated/clientsyncmanager.cpp @@ -5,42 +5,37 @@ void ClientSyncManager::syncUpdate(Update* u, UpdatesState* clientstate) { - if(u->constructorId() == TLTypes::UpdateNewMessage) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateDeleteMessages) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateUserPhoto) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateContactRegistered) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateNewAuthorization) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateNewEncryptedMessage) - ClientSyncManager::syncQts(u->qts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateEncryption) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateEncryptedMessagesRead) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateChatParticipantAdd) - ClientSyncManager::syncDate(u->date(), clientstate); - else if(u->constructorId() == TLTypes::UpdateReadHistoryInbox) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateReadHistoryOutbox) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateWebPage) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateReadMessagesContents) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateChannelTooLong) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateNewChannelMessage) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateDeleteChannelMessages) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateEditChannelMessage) - ClientSyncManager::syncPts(u->pts(), clientstate); - else if(u->constructorId() == TLTypes::UpdateEditMessage) - ClientSyncManager::syncPts(u->pts(), clientstate); + switch(u->constructorId()) { + case TLTypes::UpdateNewMessage: + case TLTypes::UpdateDeleteMessages: + case TLTypes::UpdateReadHistoryInbox: + case TLTypes::UpdateReadHistoryOutbox: + case TLTypes::UpdateWebPage: + case TLTypes::UpdateReadMessagesContents: + case TLTypes::UpdateChannelTooLong: + case TLTypes::UpdateEditMessage: + ClientSyncManager::syncPts(u->pts(), clientstate); + break; + case TLTypes::UpdateUserPhoto: + case TLTypes::UpdateContactRegistered: + case TLTypes::UpdateNewAuthorization: + case TLTypes::UpdateEncryption: + case TLTypes::UpdateEncryptedMessagesRead: + case TLTypes::UpdateChatParticipantAdd: + ClientSyncManager::syncDate(u->date(), clientstate); + break; + case TLTypes::UpdateNewChannelMessage: + ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->messageUpdatenewchannelmessage()->toId()->channelId())); + break; + case TLTypes::UpdateEditChannelMessage: + ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->message()->toId()->channelId())); + break; + case TLTypes::UpdateDeleteChannelMessages: + ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->channelId())); + break; + default: + break; + } } void ClientSyncManager::syncUpdates(Updates* u, UpdatesState* clientstate) @@ -77,7 +72,7 @@ void ClientSyncManager::syncUpdates(Updates* u, UpdatesState* clientstate) void ClientSyncManager::syncState(UpdatesState* serverstate) { UpdatesState* clientstate = TelegramConfig_clientState; - + ClientSyncManager::syncPts(serverstate->pts(), clientstate); ClientSyncManager::syncQts(serverstate->qts(), clientstate); ClientSyncManager::syncDate(serverstate->date(), clientstate); @@ -93,6 +88,14 @@ void ClientSyncManager::syncPts(TLInt pts, UpdatesState* clientstate) clientstate->setPts(pts); } +void ClientSyncManager::syncPts(TLInt pts, Dialog *dialog) +{ + if(pts <= dialog->pts()) + return; + + dialog->setPts(pts); +} + void ClientSyncManager::syncQts(TLInt qts, UpdatesState* clientstate) { if(qts <= clientstate->qts()) diff --git a/autogenerated/clientsyncmanager.h b/autogenerated/clientsyncmanager.h index 39d5902..abeaff5 100644 --- a/autogenerated/clientsyncmanager.h +++ b/autogenerated/clientsyncmanager.h @@ -5,6 +5,7 @@ // DO NOT EDIT!!! #include "../config/telegramconfig.h" +#include "../cache/telegramcache.h" #include "tltypes.h" #include "types/updatesstate.h" #include @@ -21,6 +22,7 @@ class ClientSyncManager: public QObject static void syncState(UpdatesState* serverstate); private: static void syncPts(TLInt pts, UpdatesState* clientstate); + static void syncPts(TLInt pts, Dialog* dialog); static void syncQts(TLInt qts, UpdatesState* clientstate); static void syncDate(TLInt date, UpdatesState* clientstate); static void syncSeq(TLInt seq, UpdatesState* clientstate); diff --git a/cache/telegramcache.cpp b/cache/telegramcache.cpp index 1ead9d1..8553305 100644 --- a/cache/telegramcache.cpp +++ b/cache/telegramcache.cpp @@ -484,7 +484,9 @@ void TelegramCache::onChannelTooLong(Update *update) if(!chat) return; - this->_fetcher->getChannelDifference(chat, update->pts()); + Dialog* dialog = this->dialog(update->channelId()); + + this->_fetcher->getChannelDifference(chat, dialog ? dialog->pts() : update->pts()); } void TelegramCache::onUserPhoto(Update *update) diff --git a/models/abstract/telegrammodel.h b/models/abstract/telegrammodel.h index 0be532f..bfa61f3 100644 --- a/models/abstract/telegrammodel.h +++ b/models/abstract/telegrammodel.h @@ -8,7 +8,7 @@ #define Emit_DataChangedRoles(i, roles) emit dataChanged(this->index(i, 0), this->index(i, 0), QVector() << roles) #define Emit_DataChangedRangeRoles(first, last, roles) emit dataChanged(this->index(first, 0), this->index(last, 0), QVector() << roles) -#define Safe_MoveIdx(srcidx, destidx) (((destidx >= srcidx) && (destidx <= (srcidx + 1))) ? (destidx + 1) : destidx) +#define Safe_MoveIdx(srcidx, destidx) (destidx > (srcidx + 1) ? (destidx + 1) : destidx) class TelegramModel : public QAbstractListModel { diff --git a/models/dialogsmodel.cpp b/models/dialogsmodel.cpp index c884f7e..db4d45f 100644 --- a/models/dialogsmodel.cpp +++ b/models/dialogsmodel.cpp @@ -396,10 +396,13 @@ void DialogsModel::onDialogNewMessage(Dialog *dialog) Emit_DataChanged(idx); int newidx = this->insertionPoint(dialog); - if(idx == newidx) + if (newidx == idx || newidx == (idx + 1)) { return; + } - this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx)); + if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) { + return; + } this->_dialogs.move(idx, newidx); this->endMoveRows(); } @@ -423,10 +426,13 @@ void DialogsModel::onDialogNewDraftMessage(Dialog *dialog) Emit_DataChanged(idx); int newidx = this->insertionPoint(dialog); - if(idx == newidx) + if (newidx == idx || newidx == (idx + 1)) { return; + } - this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx)); + if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) { + return; + } this->_dialogs.move(idx, newidx); this->endMoveRows(); } @@ -441,11 +447,14 @@ void DialogsModel::onDialogDeleteMessage(Dialog *dialog) Emit_DataChanged(idx); int newidx = this->insertionPoint(dialog, idx); - if(idx == newidx) + if (newidx == idx || newidx == (idx + 1)) { return; + } - this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx)); - this->_dialogs.move(idx, newidx - 1); + if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) { + return; + } + this->_dialogs.move(idx, newidx); this->endMoveRows(); } diff --git a/mtproto/dc/dcsession.cpp b/mtproto/dc/dcsession.cpp index 882bdb1..6582221 100644 --- a/mtproto/dc/dcsession.cpp +++ b/mtproto/dc/dcsession.cpp @@ -48,6 +48,10 @@ void DCSession::repeatRequests() MTProtoRequest *DCSession::sendEncrypted(MTProtoStream *mtstream) { + if (!this->_dc) { + return NULL; + } + MTProtoRequest* req = new MTProtoRequest(this->_dc->config()); req->setSessionId(this->_sessionid); req->setBody(mtstream); // Take ownership diff --git a/objects/notifications/telegramnotifications.cpp b/objects/notifications/telegramnotifications.cpp index 42567d1..40eb00c 100644 --- a/objects/notifications/telegramnotifications.cpp +++ b/objects/notifications/telegramnotifications.cpp @@ -56,11 +56,12 @@ void TelegramNotifications::onLoginCompleted() { connect(UpdateHandler_instance, &MTProtoUpdateHandler::newSingleMessage, this, &TelegramNotifications::onIncomingMessage, Qt::UniqueConnection); connect(TelegramCache_instance, &TelegramCache::readHistory, this, &TelegramNotifications::onReadHistory, Qt::UniqueConnection); + connect(TelegramCache_instance, &TelegramCache::dialogUnreadCountChanged, this, &TelegramNotifications::onReadHistory, Qt::UniqueConnection); } void TelegramNotifications::onIncomingMessage(Message *message, TLLong sessionid) { - if(UpdateHandler_syncing || !DCSessionManager_OwnSession(sessionid)) + if(UpdateHandler_syncing/* || !DCSessionManager_OwnSession(sessionid)*/) return; if(this->_mute || !this->_telegram || message->isOut() || (message->constructorId() != TLTypes::Message)) @@ -73,6 +74,10 @@ void TelegramNotifications::onIncomingMessage(Message *message, TLLong sessionid PeerNotifySettings* notifysettings = dialog->notifySettings(); + if (!notifysettings) { + return; + } + if(!message->isMentioned() && (notifysettings->isSilent() || (notifysettings->muteUntil() > 0))) return; @@ -91,5 +96,7 @@ void TelegramNotifications::onReadHistory(Dialog *dialog) if((dialog->topMessage() - dialog->readInboxMaxId()) > 0) return; - emit dismissNotification(dialog); + if (dialog->unreadCount() == 0) { + emit dismissNotification(dialog); + } }