summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-04 14:16:53 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-04 14:16:53 +0300
commitec3b265c976a31d23447843a31f129375b212049 (patch)
tree5415c73fe9342844800c8d3ee757d64027687dfd
parent083417981721437390d3ec9939a7595034287498 (diff)
Discord: fetching actual history for very large chats
-rw-r--r--protocols/Discord/src/dispatch.cpp13
-rw-r--r--protocols/Discord/src/proto.h1
2 files changed, 14 insertions, 0 deletions
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);