From 2093ff88d5badf348372057c59453175412f0dd7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 May 2020 12:37:16 +0300 Subject: Discord: fix for processing custom user statuses --- protocols/Discord/src/dispatch.cpp | 28 +++++++--------------------- protocols/Discord/src/guilds.cpp | 23 +++++++++++++++++++++++ protocols/Discord/src/proto.h | 1 + 3 files changed, 31 insertions(+), 21 deletions(-) (limited to 'protocols/Discord/src') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 04cb8a9b8e..b5094b04ad 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -449,22 +449,11 @@ void CDiscordProto::OnCommandMessageDelete(const JSONNode &pRoot) void CDiscordProto::OnCommandPresence(const JSONNode &pRoot) { - CDiscordUser *pUser = FindUser(::getId(pRoot["user"]["id"])); - if (pUser == nullptr) - return; - - int iStatus = StrToStatus(pRoot["status"].as_mstring()); - if (iStatus != 0) - setWord(pUser->hContact, "Status", iStatus); - - CMStringW wszGame = pRoot["game"]["name"].as_mstring(); - if (!wszGame.IsEmpty()) - setWString(pUser->hContact, "XStatusMsg", wszGame); - else - delSetting(pUser->hContact, "XStatusMsg"); - - // check avatar - CheckAvatarChange(pUser->hContact, pRoot["user"]["avatar"].as_mstring()); + auto *pGuild = FindGuild(::getId(pRoot["user"]["guild_id"])); + if (pGuild == nullptr) + ProcessPresence(pRoot); + // else + // pGuild->ProcessPresence(pRoot); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -485,11 +474,8 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) ProcessType(pUser, it); } - for (auto &it : pRoot["presences"]) { - CDiscordUser *pUser = FindUser(::getId(it["user"]["id"])); - if (pUser != nullptr) - setWord(pUser->hContact, "Status", StrToStatus(it["status"].as_mstring())); - } + for (auto &it : pRoot["presences"]) + ProcessPresence(it); for (auto &it : pRoot["private_channels"]) PreparePrivateChannel(it); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 37eb5a3e5c..9b360d8bc8 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -47,6 +47,29 @@ CDiscordUser::~CDiscordUser() pGuild->arChannels.remove(this); } +///////////////////////////////////////////////////////////////////////////////////////// +// reads a presence block from json + +void CDiscordProto::ProcessPresence(const JSONNode &root) +{ + auto userId = ::getId(root["user"]["id"]); + CDiscordUser *pUser = FindUser(userId); + if (pUser == nullptr) { + debugLogA("Presence from unknown user id %lld ignored", userId); + return; + } + + setWord(pUser->hContact, "Status", StrToStatus(root["status"].as_mstring())); + + CheckAvatarChange(pUser->hContact, root["user"]["avatar"].as_mstring()); + + for (auto &act : root["activities"]) { + CMStringW wszStatus(act["state"].as_mstring()); + if (!wszStatus.IsEmpty()) + db_set_ws(pUser->hContact, "CList", "StatusMsg", wszStatus); + } +} + ///////////////////////////////////////////////////////////////////////////////////////// // reads a role from json diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index b52e809811..52f9104107 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -302,6 +302,7 @@ class CDiscordProto : public PROTO void ProcessGuild(const JSONNode &json); CDiscordUser* ProcessGuildChannel(CDiscordGuild *guild, const JSONNode &json); + void ProcessPresence(const JSONNode &json); void ProcessRole(CDiscordGuild *guild, const JSONNode &json); void ProcessType(CDiscordUser *pUser, const JSONNode &json); -- cgit v1.2.3