diff options
author | George Hazan <ghazan@miranda.im> | 2017-09-21 22:42:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-09-21 22:42:00 +0300 |
commit | de49de5f2c3fd25902a263b047ff8c71f5d43545 (patch) | |
tree | f48d40ccf455e243c4b850e2a4700883d1c67c36 /protocols/Discord | |
parent | a487776816aacc4ee218e7acd481527362bfc7ff (diff) |
Discord: fix for guild sorting order
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 26 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 11 |
2 files changed, 32 insertions, 5 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 6a9776c304..5e615367b3 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -321,7 +321,8 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) { CMStringW wszMessageId = pRoot["id"].as_mstring(); CMStringW wszUserId = pRoot["author"]["id"].as_mstring(); - CDiscordMessage msg(_wtoi64(wszMessageId), _wtoi64(wszUserId)); + SnowFlake userId = _wtoi64(wszUserId); + CDiscordMessage msg(_wtoi64(wszMessageId), userId); // try to find a sender by his channel SnowFlake channelId = ::getId(pRoot["channel_id"]); @@ -365,10 +366,31 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) SESSION_INFO *si = pci->SM_FindSession(pUser->wszUsername, m_szModuleName); if (si == nullptr) { - debugLogA("nessage to unknown channal %lld ignored", channelId); + debugLogA("message to unknown channel %lld ignored", channelId); return; } + CDiscordGuild *pGuild = FindGuild(pUser->guildId); + if (pGuild == nullptr) { + debugLogA("message to unknown guild %lld ignored", pUser->guildId); + return; + } + + 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["user"]["username"].as_mstring() + L"#" + pRoot["user"]["discriminator"].as_mstring(); + pGuild->arChatUsers.insert(pm); + + for (int i = 0; i < arUsers.getCount(); i++) { + CDiscordUser &pChannel = arUsers[i]; + if (pChannel.guildId == pGuild->id) + AddUserToChannel(pChannel, *pm); + } + } + ParseSpecialChars(si, wszText); GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_MESSAGE }; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index b384f34be8..941fc5917b 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -17,9 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" +__forceinline int compareInt64(const SnowFlake i1, const SnowFlake i2) +{ + return (i1 == i2) ? 0 : (i1 < i2) ? -1 : 1; +} + static int compareMessages(const SnowFlake *p1, const SnowFlake *p2) { - return *p1 - *p2; + return compareInt64(*p1, *p2); } static int compareRequests(const AsyncHttpRequest *p1, const AsyncHttpRequest *p2) @@ -29,12 +34,12 @@ static int compareRequests(const AsyncHttpRequest *p1, const AsyncHttpRequest *p int compareUsers(const CDiscordUser *p1, const CDiscordUser *p2) { - return p1->id - p2->id; + return compareInt64(p1->id, p2->id); } static int compareGuilds(const CDiscordGuild *p1, const CDiscordGuild *p2) { - return p1->id - p2->id; + return compareInt64(p1->id, p2->id); } CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : |