diff options
author | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
commit | 899221e2d058f5afe30bb2ecdbf168c8ad3c15a6 (patch) | |
tree | ea2346678575a4fc5fdd9575b6a9174bd30c70dc /protocols/Discord | |
parent | c736d08681747a9453bd4c266f6dd54d8cbd79eb (diff) |
Group chats: all old APIs with lookup by module+session removed
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 33 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 15 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 3 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 7 |
5 files changed, 28 insertions, 31 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 7554fa669c..2c749eb8b9 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -108,8 +108,10 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot) }
else {
CDiscordGuild *pGuild = FindGuild(guildId);
- if (pGuild != nullptr)
- Chat_Terminate(m_szModuleName, pUser->wszUsername, true);
+ if (pGuild != nullptr) {
+ Chat_Terminate(pUser->si, true);
+ pUser->si = nullptr;
+ }
}
}
@@ -130,14 +132,13 @@ void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot) CMStringW wszName = pRoot["name"].as_mstring();
if (!wszName.IsEmpty()) {
CMStringW wszNewName = pGuild->wszName + L"#" + wszName;
- Chat_ChangeSessionName(m_szModuleName, pUser->wszUsername, wszNewName);
+ Chat_ChangeSessionName(pUser->si, wszNewName);
}
CMStringW wszTopic = pRoot["topic"].as_mstring();
- Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, wszTopic);
+ Chat_SetStatusbarText(pUser->si, wszTopic);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC };
- gce.pszID.w = pUser->wszUsername;
+ GCEVENT gce = { pUser->si, GC_EVENT_TOPIC };
gce.pszText.w = wszTopic;
gce.time = time(0);
Chat_Event(&gce);
@@ -184,11 +185,12 @@ void CDiscordProto::OnCommandGuildDeleted(const JSONNode &pRoot) for (auto &it : arUsers.rev_iter())
if (it->pGuild == pGuild) {
- Chat_Terminate(m_szModuleName, it->wszUsername, true);
+ Chat_Terminate(it->si, true);
arUsers.removeItem(&it);
}
- Chat_Terminate(m_szModuleName, pRoot["name"].as_mstring(), true);
+ Chat_Terminate(pGuild->pParentSi, true);
+ pGuild->pParentSi = nullptr;
arGuilds.remove(pGuild);
}
@@ -226,7 +228,7 @@ void CDiscordProto::OnCommandGuildMemberListUpdate(const JSONNode &pRoot) else if (iStatus) {
CMStringW wszUserId(FORMAT, L"%lld", pm->userId);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_SETCONTACTSTATUS };
+ GCEVENT gce = { 0, GC_EVENT_SETCONTACTSTATUS };
gce.time = time(0);
gce.pszUID.w = wszUserId;
@@ -234,7 +236,7 @@ void CDiscordProto::OnCommandGuildMemberListUpdate(const JSONNode &pRoot) if (!cc->bIsGroup)
continue;
- gce.pszID.w = cc->wszChannelName;
+ gce.si = cc->si;
gce.dwItemData = iStatus;
Chat_Event(&gce);
}
@@ -258,7 +260,7 @@ void CDiscordProto::OnCommandGuildMemberRemoved(const JSONNode &pRoot) if (pUser->pGuild != pGuild)
continue;
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART };
+ GCEVENT gce = { pUser->si, GC_EVENT_PART };
gce.pszUID.w = pUser->wszUsername;
gce.time = time(0);
gce.pszUID.w = wszUserId;
@@ -294,8 +296,7 @@ void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot) wszOldNick = ui->pszNick;
}
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK };
- gce.pszID.w = it->wszUsername;
+ GCEVENT gce = { si, GC_EVENT_NICK };
gce.time = time(0);
gce.pszUID.w = wszUserId;
gce.pszNick.w = wszOldNick;
@@ -435,8 +436,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) ParseSpecialChars(si, wszText);
wszText.Replace(L"%", L"%%");
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
- gce.pszID.w = pUser->wszUsername;
+ GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_ADDTOLOG;
gce.pszUID.w = wszUserId;
gce.pszText.w = wszText;
@@ -548,8 +548,7 @@ void CDiscordProto::OnCommandTyping(const JSONNode &pRoot) CMStringW wszUerId = pRoot["user_id"].as_mstring();
ProcessGuildUser(pChannel->pGuild, pRoot); // never returns null
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TYPING };
- gce.pszID.w = pChannel->wszUsername;
+ GCEVENT gce = { pChannel->si, GC_EVENT_TYPING };
gce.pszUID.w = wszUerId;
gce.dwItemData = 1;
gce.time = time(0);
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 760437ceb0..6095b0a234 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -114,7 +114,7 @@ void CDiscordProto::BatchChatCreate(void *param) void CDiscordProto::CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser)
{
- SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, pUser->wszUsername, pUser->wszChannelName);
+ auto *si = pUser->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, pUser->wszUsername, pUser->wszChannelName);
si->pParent = pGuild->pParentSi;
pUser->hContact = si->hContact;
setId(pUser->hContact, DB_KEY_ID, pUser->channelId);
@@ -139,14 +139,13 @@ void CDiscordProto::CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser) BuildStatusList(pGuild, si);
- Chat_Control(m_szModuleName, pUser->wszUsername, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
- Chat_Control(m_szModuleName, pUser->wszUsername, SESSION_ONLINE);
+ Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
if (!pUser->wszTopic.IsEmpty()) {
- Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, pUser->wszTopic);
+ Chat_SetStatusbarText(si, pUser->wszTopic);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC };
- gce.pszID.w = pUser->wszUsername;
+ GCEVENT gce = { si, GC_EVENT_TOPIC };
gce.time = time(0);
gce.pszText.w = pUser->wszTopic;
Chat_Event(&gce);
@@ -177,8 +176,8 @@ void CDiscordProto::ProcessGuild(const JSONNode &pRoot) pGuild->hContact = si->hContact;
setId(pGuild->hContact, DB_KEY_CHANNELID, guildId);
- Chat_Control(m_szModuleName, pGuild->wszName, WINDOW_HIDDEN);
- Chat_Control(m_szModuleName, pGuild->wszName, SESSION_ONLINE);
+ Chat_Control(si, WINDOW_HIDDEN);
+ Chat_Control(si, SESSION_ONLINE);
for (auto &it : pRoot["roles"])
ProcessRole(pGuild, it);
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index b5262f4e0a..683c0cbb05 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -86,6 +86,7 @@ struct CDiscordUser : public MZeroedObject bool bSynced;
struct CDiscordGuild *pGuild;
+ SESSION_INFO *si;
CMStringW wszUsername, wszChannelName, wszTopic;
int iDiscriminator;
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 16f716e89f..8266e11a0b 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -129,8 +129,7 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest ParseSpecialChars(si, wszText);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
- gce.pszID.w = pUser->wszUsername;
+ GCEVENT gce = { si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_ADDTOLOG;
gce.pszUID.w = wszUserId;
gce.pszText.w = wszText;
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index ce12a81443..b9297735e1 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -185,8 +185,7 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) SnowFlake ownerId = _wtoi64(root["owner_id"].as_mstring());
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN };
- gce.pszID.w = pUser->wszUsername;
+ GCEVENT gce = { pUser->si, GC_EVENT_JOIN };
for (auto &it : root["recipients"]) {
CMStringW wszId = it["id"].as_mstring();
CMStringW wszNick = it["nick"].as_mstring();
@@ -207,8 +206,8 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) 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);
+ Chat_Control(pUser->si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(pUser->si, SESSION_ONLINE);
}
break;
|