summaryrefslogtreecommitdiff
path: root/protocols/Discord/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-01 15:04:55 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-01 15:04:55 +0300
commit89547af5b067b00cae18c44e356044c1e75361cb (patch)
treeaf34f92223b6e03622a88a75e69d0d3d52132130 /protocols/Discord/src
parent060084bb68a749147bb4947e0accb56d11d2257f (diff)
fixes #4159 (Discord: possible crash when guild member leaves)
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r--protocols/Discord/src/dispatch.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 642694e3cb..d24d0ab60e 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -255,17 +255,27 @@ void CDiscordProto::OnCommandGuildMemberRemoved(const JSONNode &pRoot)
return;
CMStringW wszUserId = pRoot["user"]["id"].as_mstring();
+ auto *gm = pGuild->FindUser(_wtoi64(wszUserId));
+ if (gm == nullptr)
+ return;
+
+ // remove a user once from the common list of users
+ GCEVENT gce = { pGuild->pParentSi, GC_EVENT_PART };
+ gce.pszNick.w = gm->wszNick;
+ gce.time = time(0);
+ gce.pszUID.w = wszUserId;
+ Chat_Event(&gce);
- for (auto &pUser : arUsers) {
- if (pUser->pGuild != pGuild)
+ // then update every nicklist for any opened chat
+ for (auto &cc: arUsers) {
+ if (cc->pGuild != pGuild)
continue;
- GCEVENT gce = { pUser->si, GC_EVENT_PART };
- gce.pszUID.w = pUser->wszUsername;
- gce.time = time(0);
- gce.pszUID.w = wszUserId;
- Chat_Event(&gce);
+ if (cc->si && cc->si->pDlg)
+ cc->si->pDlg->UpdateNickList();
}
+
+ pGuild->arChatUsers.remove(gm);
}
void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot)
@@ -285,11 +295,11 @@ void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot)
gm->wszNick = pRoot["user"]["username"].as_mstring();
for (auto &it : arUsers) {
- if (it->pGuild != pGuild)
+ if (it->pGuild != pGuild || !it->si)
continue;
CMStringW wszOldNick;
- SESSION_INFO *si = Chat_Find(it->wszUsername, m_szModuleName);
+ SESSION_INFO *si = it->si;
if (si != nullptr) {
USERINFO *ui = g_chatApi.UM_FindUser(si, wszUserId);
if (ui != nullptr)