summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/src/server.cpp')
-rw-r--r--protocols/Telegram/src/server.cpp36
1 files changed, 36 insertions, 0 deletions
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_;