diff options
author | George Hazan <ghazan@miranda.im> | 2020-05-11 12:37:16 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-05-11 12:37:16 +0300 |
commit | 2093ff88d5badf348372057c59453175412f0dd7 (patch) | |
tree | ef5c02f034d05709d59f4f742692413f29cca35f /protocols/Discord | |
parent | 288f7b5d7c5e76ba458ffa5522901b41c750f55a (diff) |
Discord: fix for processing custom user statuses
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 28 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 23 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 1 |
3 files changed, 31 insertions, 21 deletions
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 @@ -48,6 +48,29 @@ CDiscordUser::~CDiscordUser() } ///////////////////////////////////////////////////////////////////////////////////////// +// 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 void CDiscordProto::ProcessRole(CDiscordGuild *guild, const JSONNode &role) 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<CDiscordProto> 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); |