summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/guilds.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-10-13 21:29:05 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-10-13 21:29:05 +0300
commit1ba1e51fc6fa7e30b0a627a141348f515ffaba76 (patch)
treef73f73f96662e545d0c995d41b22ed5f2908a2a2 /protocols/Discord/src/guilds.cpp
parent1724ed49a870a75f7608a8badc2a897ca471203d (diff)
chat api:
- GC_SHAREDUSERS flag added to share the same array of users for all group chats; - USERINFO.next removed; - MODULEINFO.arUsers & SESSION_INFO.arUsers introduced to maintain user lists; - MM_AddModule removed; - memory allocation model changed for MODULEINFO & SESSION_INFO - MM_CreateModule & SM_CreateSession members are added to g_chatApi
Diffstat (limited to 'protocols/Discord/src/guilds.cpp')
-rw-r--r--protocols/Discord/src/guilds.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index 0bb61ed52a..1d0a137fea 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -98,9 +98,8 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS
CMStringW wszChannelName = pGuild->wszName + L"#" + pch["name"].as_mstring();
// filter our all channels but the text ones
- if (pch["type"].as_int() != 0) {
+ if (pch["type"].as_int() != 0)
return nullptr;
- }
CMStringW wszTopic = pch["topic"].as_mstring();
@@ -139,18 +138,34 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS
SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID);
if (oldMsgId != 0 && pUser->lastMsg.id > oldMsgId)
RetrieveHistory(pUser->hContact, MSG_AFTER, oldMsgId, 99);
-
- for (auto &it : pGuild->arChatUsers)
- AddUserToChannel(*pUser, *it);
-
return pUser;
}
/////////////////////////////////////////////////////////////////////////////////////////
-void CDiscordProto::AddUserToChannel(const CDiscordUser &pChannel, const CDiscordGuildMember &pUser)
+void CDiscordProto::AddGuildUser(SnowFlake guildId, const CDiscordGuildMember &pUser)
{
- GCEVENT gce = { m_szModuleName, pChannel.wszUsername, GC_EVENT_JOIN };
+ const CDiscordUser *pChannel = nullptr;
+ for (auto &it : arUsers)
+ if (it->guildId == guildId) {
+ pChannel = it;
+ break;
+ }
+
+ if (pChannel == nullptr)
+ return;
+
+ int flags = GC_SSE_ONLYLISTED;
+ switch (pUser.iStatus) {
+ case ID_STATUS_ONLINE: case ID_STATUS_NA: case ID_STATUS_DND:
+ flags += GC_SSE_ONLINE;
+ break;
+
+ default:
+ return;
+ }
+
+ GCEVENT gce = { m_szModuleName, pChannel->wszUsername, GC_EVENT_JOIN };
gce.time = time(0);
gce.dwFlags = GCEF_SILENT;
@@ -163,15 +178,7 @@ void CDiscordProto::AddUserToChannel(const CDiscordUser &pChannel, const CDiscor
gce.ptszNick = pUser.wszNick;
Chat_Event(&gce);
- int flags = GC_SSE_ONLYLISTED;
- switch (pUser.iStatus) {
- case ID_STATUS_ONLINE: case ID_STATUS_NA: case ID_STATUS_DND:
- flags += GC_SSE_ONLINE;
- break;
- default:
- flags += GC_SSE_OFFLINE;
- }
- Chat_SetStatusEx(m_szModuleName, pChannel.wszUsername, flags, wszUserId);
+ Chat_SetStatusEx(m_szModuleName, pChannel->wszUsername, flags, wszUserId);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -222,10 +229,6 @@ void CDiscordProto::ParseGuildContents(CDiscordGuild *pGuild, const JSONNode &pR
gm->iStatus = StrToStatus(s["status"].as_mstring());
}
- for (auto &pm : newMembers) {
- for (auto &pUser : arUsers) {
- if (pUser->guildId == pGuild->id)
- AddUserToChannel(*pUser, *pm);
- }
- }
+ for (auto &pm : newMembers)
+ AddGuildUser(pGuild->id, *pm);
}