summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/dispatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord/src/dispatch.cpp')
-rw-r--r--protocols/Discord/src/dispatch.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index e28f6f70d2..1f4f9b3993 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -30,6 +30,7 @@ static handlers[] = // these structures must me sorted alphabetically
{
{ L"CHANNEL_CREATE", &CDiscordProto::OnCommandChannelCreated },
{ L"CHANNEL_DELETE", &CDiscordProto::OnCommandChannelDeleted },
+ { L"CHANNEL_UPDATE", &CDiscordProto::OnCommandChannelUpdated },
{ L"GUILD_CREATE", &CDiscordProto::OnCommandGuildCreate },
{ L"GUILD_DELETE", &CDiscordProto::OnCommandGuildDelete },
@@ -89,6 +90,25 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot)
}
}
+void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot)
+{
+ CDiscordUser *pUser = FindUserByChannel(::getId(pRoot["id"]));
+ if (pUser == NULL)
+ return;
+
+ pUser->lastMessageId = ::getId(pRoot["last_message_id"]);
+
+ CMStringW wszTopic = pRoot["topic"].as_mstring();
+ if (!wszTopic.IsEmpty()) {
+ Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, wszTopic);
+
+ GCDEST gcd = { m_szModuleName, pUser->wszUsername, GC_EVENT_TOPIC };
+ GCEVENT gce = { &gcd };
+ gce.ptszText = wszTopic;
+ Chat_Event(&gce);
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// reading a new message
@@ -158,6 +178,7 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
CMStringW wszChannelName = pch["name"].as_mstring();
CMStringW wszChannelId = pch["id"].as_mstring();
+ CMStringW wszTopic = pch["topic"].as_mstring();
SnowFlake channelId = _wtoi64(wszChannelId);
si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszChannelId, wszGuildName + L"#" + wszChannelName);
@@ -165,6 +186,15 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
Chat_Control(m_szModuleName, wszChannelId, WINDOW_HIDDEN);
Chat_Control(m_szModuleName, wszChannelId, SESSION_ONLINE);
+ if (!wszTopic.IsEmpty()) {
+ Chat_SetStatusbarText(m_szModuleName, wszChannelId, wszTopic);
+
+ GCDEST gcd = { m_szModuleName, wszChannelId, GC_EVENT_TOPIC };
+ GCEVENT gce = { &gcd };
+ gce.ptszText = wszTopic;
+ Chat_Event(&gce);
+ }
+
CDiscordUser *pUser = FindUserByChannel(channelId);
if (pUser == NULL) {
// missing channel - create it