diff options
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r-- | protocols/Telegram/src/mt_proto.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/protocols/Telegram/src/mt_proto.h b/protocols/Telegram/src/mt_proto.h index 5426ffaf6f..7aa85b722b 100644 --- a/protocols/Telegram/src/mt_proto.h +++ b/protocols/Telegram/src/mt_proto.h @@ -123,6 +123,7 @@ class CMTProto : public PROTO<CMTProto> void ProcessChat(TD::updateNewChat *pObj); void ProcessChatPosition(TD::updateChatPosition *pObj); void ProcessGroups(TD::updateChatFilters *pObj); + void ProcessMarkRead(TD::updateChatReadInbox *pObj); void ProcessMessage(TD::updateNewMessage *pObj); void ProcessStatus(TD::updateUserStatus *pObj); void ProcessUser(TD::updateUser *pObj); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 2dccbc0281..c3c54b3065 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -120,6 +120,10 @@ void CMTProto::ProcessResponse(td::ClientManager::Response response) ProcessChatPosition((TD::updateChatPosition *)response.object.get()); break; + case TD::updateChatReadInbox::ID: + ProcessMarkRead((TD::updateChatReadInbox *)response.object.get()); + break; + case TD::updateNewChat::ID: ProcessChat((TD::updateNewChat *)response.object.get()); break; @@ -268,6 +272,38 @@ void CMTProto::ProcessGroups(TD::updateChatFilters *pObj) } } +void CMTProto::ProcessMarkRead(TD::updateChatReadInbox *pObj) +{ + auto *pUser = FindUser(pObj->chat_id_); + if (pUser == nullptr) { + debugLogA("message from unknown chat/user, ignored"); + return; + } + + char szId[100]; + _i64toa(pObj->last_read_inbox_message_id_, szId, 10); + MEVENT hLastRead = db_event_getById(m_szModuleName, szId); + if (hLastRead == 0) { + debugLogA("unknown event, ignored"); + return; + } + + bool bExit = false; + for (MEVENT hEvent = db_event_firstUnread(pUser->hContact); hEvent; hEvent = db_event_next(pUser->hContact, hEvent)) { + if (bExit) + break; + + bExit = (hEvent == hLastRead); + + DBEVENTINFO dbei = {}; + if (db_event_get(hEvent, &dbei)) + continue; + + if (!dbei.markedRead()) + db_event_markRead(pUser->hContact, hEvent); + } +} + void CMTProto::ProcessMessage(TD::updateNewMessage *pObj) { auto &pMessage = pObj->message_; |