summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-10-08 19:41:48 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-10-08 19:41:48 +0300
commit834cbb58d74215980165eab257538ba918a378cd (patch)
tree44db165eebc97d8a6a49e69a165f09d604138421
parent68f24bbe2000376776f640b33b569b8dbc87aedf (diff)
Telegram: marking remote message as read
-rw-r--r--protocols/Telegram/src/proto.h1
-rw-r--r--protocols/Telegram/src/server.cpp15
-rw-r--r--protocols/Telegram/src/utils.cpp19
3 files changed, 24 insertions, 11 deletions
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index e0f0ec1515..5801fb30dc 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -362,6 +362,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
MCONTACT GetRealContact(const TG_USER *pUser);
void RemoveFromClist(TG_USER *pUser);
+ void MarkRead(MCONTACT hContact, const CMStringA &szMaxId, bool bSent);
// Menus
HGENMENU hmiForward, hmiReaction;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index b39c997d5c..9237b3c341 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -873,17 +873,7 @@ void CTelegramProto::ProcessMarkRead(TD::updateChatReadInbox *pObj)
}
// make sure that all events with ids lower or equal than szMaxId are marked read
- for (MEVENT hEvent = db_event_firstUnread(pUser->hContact); hEvent; hEvent = db_event_next(pUser->hContact, hEvent)) {
- DB::EventInfo dbei(hEvent, false);
- if (!dbei || !dbei.szId)
- continue;
-
- if (dbei.szId > szMaxId)
- break;
-
- if (!dbei.markedRead())
- db_event_markRead(pUser->hContact, hEvent, true);
- }
+ MarkRead(pUser->hContact, szMaxId, true);
if (g_plugin.hasMessageState && pObj->unread_count_ == 0)
CallService(MS_MESSAGESTATE_UPDATE, GetRealContact(pUser), MRD_TYPE_READ);
@@ -1093,6 +1083,9 @@ void CTelegramProto::ProcessRemoteMarkRead(TD::updateChatReadOutbox *pObj)
return;
}
+ CMStringA szMaxId(msg2id(pUser->chatId, pObj->last_read_outbox_message_id_));
+ MarkRead(pUser->hContact, szMaxId, false);
+
CallService(MS_MESSAGESTATE_UPDATE, GetRealContact(pUser), MRD_TYPE_READ);
}
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp
index 0db0a430cd..627e11eda5 100644
--- a/protocols/Telegram/src/utils.cpp
+++ b/protocols/Telegram/src/utils.cpp
@@ -210,6 +210,25 @@ void CTelegramProto::RemoveFromClist(TG_USER *pUser)
}
}
+void CTelegramProto::MarkRead(MCONTACT hContact, const CMStringA &szMaxId, bool bSent)
+{
+ for (MEVENT hEvent = db_event_firstUnread(hContact); hEvent; hEvent = db_event_next(hContact, hEvent)) {
+ DB::EventInfo dbei(hEvent, false);
+ if (!dbei || !dbei.szId)
+ continue;
+
+ if (dbei.szId > szMaxId)
+ break;
+
+ bool isSent = (dbei.flags & DBEF_SENT) != 0;
+ if (isSent != bSent)
+ continue;
+
+ if (!dbei.markedRead())
+ db_event_markRead(hContact, hEvent, true);
+ }
+}
+
int CTelegramProto::GetDefaultMute(const TG_USER *pUser)
{
if (pUser->isGroupChat)