diff options
author | George Hazan <george.hazan@gmail.com> | 2024-06-13 18:17:10 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-06-13 18:17:10 +0300 |
commit | 643752d38701341617bba6dad931ce9ffeb228f8 (patch) | |
tree | 3108c98c8ec24465a2dd2c7d5e64e755eb2b0470 | |
parent | 3a4d5709c73fa0495138857f7bdb7a49e9e8a80a (diff) |
Discord: fix for occasional crash
-rw-r--r-- | protocols/Discord/src/utils.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 983cd6201b..1790c934cf 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -194,7 +194,6 @@ CDiscordUser* CDiscordProto::FindUserByChannel(SnowFlake channelId) void CDiscordProto::PreparePrivateChannel(const JSONNode &root)
{
- SESSION_INFO *si;
CDiscordUser *pUser = nullptr;
CMStringW wszChannelId = root["id"].as_mstring();
@@ -234,53 +233,54 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) break;
}
}
-
- si = pUser->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 = ::getId(root["owner_id"]);
- setId(pUser->hContact, DB_KEY_OWNERID, ownerId);
-
- CheckAvatarChange(si->hContact, root["icon"].as_mstring());
-
- bool bHasMe = false;
- GCEVENT gce = { si, GC_EVENT_JOIN };
- for (auto &it : root["recipients"]) {
- CMStringW wszId = it["id"].as_mstring();
- CMStringW wszNick = it["global_name"].as_mstring();
- if (wszNick.IsEmpty())
- wszNick = getNick(it);
-
- gce.bIsMe = _wtoi64(wszId) == m_ownId;
- gce.pszUID.w = wszId;
- gce.pszNick.w = wszNick;
- gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants";
- Chat_Event(&gce);
-
- if (gce.bIsMe)
- bHasMe = true;
+ if (auto *si = pUser->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 = ::getId(root["owner_id"]);
+ setId(pUser->hContact, DB_KEY_OWNERID, ownerId);
+
+ CheckAvatarChange(si->hContact, root["icon"].as_mstring());
+
+ bool bHasMe = false;
+ GCEVENT gce = { si, GC_EVENT_JOIN };
+ for (auto &it : root["recipients"]) {
+ CMStringW wszId = it["id"].as_mstring();
+ CMStringW wszNick = it["global_name"].as_mstring();
+ if (wszNick.IsEmpty())
+ wszNick = getNick(it);
+
+ gce.bIsMe = _wtoi64(wszId) == m_ownId;
+ gce.pszUID.w = wszId;
+ gce.pszNick.w = wszNick;
+ gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants";
+ Chat_Event(&gce);
+
+ if (gce.bIsMe)
+ bHasMe = true;
+ }
+
+ if (!bHasMe) {
+ CMStringW wszId(FORMAT, L"%lld", getId(DB_KEY_ID)), wszNick;
+ if (auto iDiscr = getDword(DB_KEY_DISCR))
+ wszNick.Format(L"%s#%d", getMStringW(DB_KEY_NICK).c_str(), iDiscr);
+ else
+ wszNick = getMStringW(DB_KEY_NICK);
+
+ gce.bIsMe = true;
+ gce.pszUID.w = wszId;
+ gce.pszNick.w = wszNick;
+ gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants";
+ Chat_Event(&gce);
+ }
}
-
- if (!bHasMe) {
- CMStringW wszId(FORMAT, L"%lld", getId(DB_KEY_ID)), wszNick;
- if (auto iDiscr = getDword(DB_KEY_DISCR))
- wszNick.Format(L"%s#%d", getMStringW(DB_KEY_NICK).c_str(), iDiscr);
- else
- wszNick = getMStringW(DB_KEY_NICK);
-
- 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(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
- Chat_Control(si, SESSION_ONLINE);
+ Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
+ }
break;
default:
|