diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-11 20:06:45 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-11 20:06:45 +0300 |
commit | f6e96ca5c529f7bff287d2c47b5e319f18435235 (patch) | |
tree | abc9e995aba02c70c098d1661af298da41c1fea4 | |
parent | 7af11cc0f8e7b23891e24fad89cbd53e7d9e4f8f (diff) |
Discord: fixes #2838 (groupchat messages were retrieved from history without nicks)
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 15 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 26 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 12 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
5 files changed, 36 insertions, 20 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 761ef6a6fe..458fcf4ed9 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -430,20 +430,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) return; } - CDiscordGuild *pGuild = pUser->pGuild; - if (pGuild != nullptr && userId != 0) { - CDiscordGuildMember *pm = pGuild->FindUser(userId); - if (pm == nullptr) { - pm = new CDiscordGuildMember(userId); - pm->wszNick = pRoot["nick"].as_mstring(); - if (pm->wszNick.IsEmpty()) - pm->wszNick = pRoot["author"]["username"].as_mstring() + L"#" + pRoot["author"]["discriminator"].as_mstring(); - pGuild->arChatUsers.insert(pm); - - debugLogA("add missing user to chat: id=%lld, nick=%S", userId, pm->wszNick.c_str()); - AddGuildUser(pGuild, *pm); - } - } + ProcessChatUser(pUser, wszUserId, pRoot); ParseSpecialChars(si, wszText); wszText.Replace(L"%", L"%%"); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 83922575f9..4933c67389 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -309,6 +309,32 @@ CDiscordGuildMember* CDiscordProto::ProcessGuildUser(CDiscordGuild *pGuild, cons ///////////////////////////////////////////////////////////////////////////////////////// +void CDiscordProto::ProcessChatUser(CDiscordUser *pChat, const CMStringW &wszUserId, const JSONNode &pRoot) +{ + // input data control + SnowFlake userId = _wtoi64(wszUserId); + CDiscordGuild *pGuild = pChat->pGuild; + if (pGuild == nullptr || userId == 0) + return; + + // does user exist? if yes, there's nothing to do + auto *pm = pGuild->FindUser(userId); + if (pm != nullptr) + return; + + // otherwise let's create a user and insert him into all guild's chats + pm = new CDiscordGuildMember(userId); + pm->wszNick = pRoot["nick"].as_mstring(); + if (pm->wszNick.IsEmpty()) + pm->wszNick = pRoot["author"]["username"].as_mstring() + L"#" + pRoot["author"]["discriminator"].as_mstring(); + pGuild->arChatUsers.insert(pm); + + debugLogA("add missing user to chat: id=%lld, nick=%S", userId, pm->wszNick.c_str()); + AddGuildUser(pGuild, *pm); +} + +///////////////////////////////////////////////////////////////////////////////////////// + void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMember &pUser) { int flags = 0; diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index d9013c261e..bdbb7752c7 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -328,6 +328,7 @@ class CDiscordProto : public PROTO<CDiscordProto> void Chat_ProcessLogMenu(GCHOOK *gch); void CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser); + void ProcessChatUser(CDiscordUser *pChat, const CMStringW &wszUserId, const JSONNode &pRoot); void ParseSpecialChars(SESSION_INFO *si, CMStringW &str); ////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 28aa0f12f8..ec2e5e816c 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -84,12 +84,12 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest } for (auto &it : arNodes) { - auto &p = *it; - CMStringW wszText = PrepareMessageText(p); - CMStringW wszUserId = p["author"]["id"].as_mstring(); - SnowFlake msgid = ::getId(p["id"]); + auto &pNode = *it; + CMStringW wszText = PrepareMessageText(pNode); + CMStringW wszUserId = pNode["author"]["id"].as_mstring(); + SnowFlake msgid = ::getId(pNode["id"]); SnowFlake authorid = _wtoi64(wszUserId); - DWORD dwTimeStamp = StringToDate(p["timestamp"].as_mstring()); + DWORD dwTimeStamp = StringToDate(pNode["timestamp"].as_mstring()); if (pUser->bIsPrivate) { DBEVENTINFO dbei = {}; @@ -125,6 +125,8 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest } } else { + ProcessChatUser(pUser, wszUserId, pNode); + ParseSpecialChars(si, wszText); GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index 10427dc97f..946c4136ed 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 6 #define __RELEASE_NUM 2 -#define __BUILD_NUM 8 +#define __BUILD_NUM 9 #include <stdver.h> |