From ec3b265c976a31d23447843a31f129375b212049 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 4 May 2024 14:16:53 +0300 Subject: Discord: fetching actual history for very large chats --- protocols/Discord/src/dispatch.cpp | 13 +++++++++++++ protocols/Discord/src/proto.h | 1 + 2 files changed, 14 insertions(+) diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index bcac245361..0ba56aa29b 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -36,6 +36,7 @@ static handlers[] = // these structures must me sorted alphabetically { L"CHANNEL_DELETE", &CDiscordProto::OnCommandChannelDeleted }, { L"CHANNEL_RECIPIENT_ADD", &CDiscordProto::OnCommandChannelUserAdded }, { L"CHANNEL_RECIPIENT_REMOVE", &CDiscordProto::OnCommandChannelUserLeft }, + { L"CHANNEL_UNREAD_UPDATE", &CDiscordProto::OnCommandChannelUnreadUpdate }, { L"CHANNEL_UPDATE", &CDiscordProto::OnCommandChannelUpdated }, { L"GUILD_CREATE", &CDiscordProto::OnCommandGuildCreated }, @@ -152,6 +153,18 @@ void CDiscordProto::OnCommandChannelUserLeft(const JSONNode &pRoot) Chat_Event(&gce); } +void CDiscordProto::OnCommandChannelUnreadUpdate(const JSONNode &pRoot) +{ + auto *pGuild = FindGuild(::getId(pRoot["guild_id"])); + if (pGuild == nullptr) + return; + + for (auto &it : pRoot["channel_unread_updates"]) + if (auto *pChannel = FindUserByChannel(::getId(it["id"]))) + if (pChannel->lastMsgId < ::getId(it["last_message_id"])) + RetrieveHistory(pChannel, MSG_AFTER, pChannel->lastMsgId, 99); +} + void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot) { CDiscordUser *pUser = FindUserByChannel(::getId(pRoot["id"])); diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 57d7094476..8c6e045b5c 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -483,6 +483,7 @@ public: void OnCommandCallUpdated(const JSONNode &json); void OnCommandChannelCreated(const JSONNode &json); void OnCommandChannelDeleted(const JSONNode &json); + void OnCommandChannelUnreadUpdate(const JSONNode &json); void OnCommandChannelUpdated(const JSONNode &json); void OnCommandChannelUserAdded(const JSONNode &json); void OnCommandChannelUserLeft(const JSONNode &json); -- cgit v1.2.3