diff options
author | George Hazan <ghazan@miranda.im> | 2019-11-05 23:33:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-11-05 23:33:59 +0300 |
commit | 5afaef11dcafe99799f79f0a8cc7d4fb50c15c6e (patch) | |
tree | 642d0bcd5c11c753da041a6692a21270f1dc3069 | |
parent | 88de53b8a6c208f290ee780b46155d4626467fbc (diff) |
fixes #2115 ([Discord] "Group chats" (not chatrooms/servers but personal groups!) are broken)
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 9 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 67 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
4 files changed, 67 insertions, 15 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 14ed7a6eba..ee0b780b65 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -363,7 +363,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (!edited.isnull()) wszText.AppendFormat(L" (%s %s)", TranslateT("edited at"), edited.as_mstring().c_str()); - if (pUser->bIsPrivate) { + if (pUser->bIsPrivate && !pUser->bIsGroup) { // if a message has myself as an author, add some flags PROTORECVEVENT recv = {}; if (bOurMessage) @@ -387,12 +387,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) } CDiscordGuild *pGuild = pUser->pGuild; - if (pGuild == nullptr) { - debugLogA("message to unknown guild ignored"); - return; - } - - if (userId != 0) { + if (pGuild != nullptr && userId != 0) { CDiscordGuildMember *pm = pGuild->FindUser(userId); if (pm == nullptr) { pm = new CDiscordGuildMember(userId); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 6dbb3ff477..a25f7429f6 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -34,8 +34,8 @@ static int compareChatUsers(const CDiscordGuildMember *p1, const CDiscordGuildMe return compareInt64(p1->userId, p2->userId); } -CDiscordGuild::CDiscordGuild(SnowFlake _id) - : id(_id), +CDiscordGuild::CDiscordGuild(SnowFlake _id) : + id(_id), arChannels(10, compareUsers), arChatUsers(30, compareChatUsers), arRoles(10, compareRoles) diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 07b293d1b4..69af8f0789 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -135,14 +135,71 @@ CDiscordUser* CDiscordProto::FindUserByChannel(SnowFlake channelId) void CDiscordProto::PreparePrivateChannel(const JSONNode &root) { CDiscordUser *pUser = nullptr; - for (auto &it : root["recipients"]) - pUser = PrepareUser(it); - if (pUser == nullptr) + CMStringW wszChannelId = root["id"].as_mstring(); + SnowFlake channelId = _wtoi64(wszChannelId); + + int type = root["type"].as_int(); + switch (type) { + case 1: // single channel + for (auto &it : root["recipients"]) + pUser = PrepareUser(it); + if (pUser == nullptr) { + debugLogA("Invalid recipients list, exiting"); + return; + } + break; + + case 3: // private groupchat + if ((pUser = FindUserByChannel(channelId)) == nullptr) { + pUser = new CDiscordUser(channelId); + arUsers.insert(pUser); + } + pUser->bIsGroup = true; + pUser->wszUsername = wszChannelId; + pUser->wszChannelName = root["name"].as_mstring(); + { + SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, pUser->wszUsername, pUser->wszChannelName); + pUser->hContact = si->hContact; + + Chat_AddGroup(si, LPGENW("Owners")); + Chat_AddGroup(si, LPGENW("Participants")); + + SnowFlake ownerId = _wtoi64(root["owner_id"].as_mstring()); + + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = pUser->wszUsername; + for (auto &it : root["recipients"]) { + CMStringW wszId = it["id"].as_mstring(); + CMStringW wszNick = it["nick"].as_mstring(); + if (wszNick.IsEmpty()) + wszNick = it["username"].as_mstring() + L"#" + it["discriminator"].as_mstring(); + + gce.pszUID.w = wszId; + gce.pszNick.w = wszNick; + gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants"; + Chat_Event(&gce); + } + + CMStringW wszId(FORMAT, L"%lld", getId(DB_KEY_ID)); + CMStringW wszNick(FORMAT, L"%s#%d", getMStringW(DB_KEY_NICK).c_str(), getDword(DB_KEY_DISCR)); + gce.bIsMe = true; + gce.pszUID.w = wszId; + gce.pszNick.w = wszNick; + gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants"; + Chat_Event(&gce); + + Chat_Control(m_szModuleName, pUser->wszUsername, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(m_szModuleName, pUser->wszUsername, SESSION_ONLINE); + } + break; + + default: + debugLogA("Invalid channel type: %d, exiting", type); return; + } - CMStringW wszChannelId = root["id"].as_mstring(); - pUser->channelId = _wtoi64(wszChannelId); + pUser->channelId = channelId; pUser->lastMsgId = ::getId(root["last_message_id"]); pUser->bIsPrivate = true; diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index 489805825c..407e5b603a 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 1 +#define __BUILD_NUM 2 #include <stdver.h> |