summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-01-05 18:17:38 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-01-05 18:17:38 +0300
commit6febd24a8d4c6a552efc5d0c3a792d7e47effdb3 (patch)
tree4dfc7f9fefa62d48e7c04c1acac004396d7d90bb /protocols/Telegram/src
parentee8c388aef77da6d8a7ea900cfba8661faefb30b (diff)
Telegram: remote marked read notifications
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/mt_proto.h1
-rw-r--r--protocols/Telegram/src/server.cpp36
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_;