diff options
author | George Hazan <ghazan@miranda.im> | 2018-10-13 23:47:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-10-13 23:47:14 +0300 |
commit | 27a552b8bf0f42af225e07b009d5b3e9c633e3fe (patch) | |
tree | 2a2b3204955b92e9cf87aed76a7033067a050ecd /protocols/Discord/src | |
parent | 31af9f2c6205e0517185f71c6c66f76d6425e2a5 (diff) |
group chats:
- GC_SHAREDUSERS removed;
- SESSION_INFO::pParent used instead to collect data about shared user info
- fix for SESSION_INFO::pMe calculation
- Discord chats now go offline when proto goes offline
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r-- | protocols/Discord/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 26 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 |
5 files changed, 17 insertions, 20 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp index 1034ecc2b3..d23ad64041 100644 --- a/protocols/Discord/src/connection.cpp +++ b/protocols/Discord/src/connection.cpp @@ -87,7 +87,7 @@ void CDiscordProto::OnLoggedOut() ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - setAllContactStatuses(ID_STATUS_OFFLINE, true); + setAllContactStatuses(ID_STATUS_OFFLINE, false); } void CDiscordProto::ShutdownSession() diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index fa301ee37c..a0bf365e2a 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -377,7 +377,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) pm->wszNick = pRoot["user"]["username"].as_mstring() + L"#" + pRoot["user"]["discriminator"].as_mstring(); pGuild->arChatUsers.insert(pm); - AddGuildUser(pGuild->id, *pm); + AddGuildUser(pGuild, *pm); } ParseSpecialChars(si, wszText); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 1d0a137fea..b30dcf8aef 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -76,7 +76,12 @@ void CDiscordProto::ProcessGuild(const JSONNode &p) GCSessionInfoBase *si = Chat_NewSession(GCW_SERVER, m_szModuleName, pGuild->wszName, pGuild->wszName, pGuild); Chat_Control(m_szModuleName, pGuild->wszName, WINDOW_HIDDEN); Chat_Control(m_szModuleName, pGuild->wszName, SESSION_ONLINE); - + BuildStatusList(pGuild, pGuild->wszName); + + for (auto &it : pGuild->arChatUsers) + AddGuildUser(pGuild, *it); + + pGuild->pParentSi = si; pGuild->hContact = si->hContact; setId(si->hContact, DB_KEY_CHANNELID, guildId); @@ -104,6 +109,7 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS CMStringW wszTopic = pch["topic"].as_mstring(); GCSessionInfoBase *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszChannelId, wszChannelName); + si->pParent = pGuild->pParentSi; BuildStatusList(pGuild, wszChannelId); Chat_Control(m_szModuleName, wszChannelId, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); @@ -143,18 +149,8 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS ///////////////////////////////////////////////////////////////////////////////////////// -void CDiscordProto::AddGuildUser(SnowFlake guildId, const CDiscordGuildMember &pUser) +void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMember &pUser) { - 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: @@ -165,7 +161,7 @@ void CDiscordProto::AddGuildUser(SnowFlake guildId, const CDiscordGuildMember &p return; } - GCEVENT gce = { m_szModuleName, pChannel->wszUsername, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, pGuild->pParentSi->ptszID, GC_EVENT_JOIN }; gce.time = time(0); gce.dwFlags = GCEF_SILENT; @@ -178,7 +174,7 @@ void CDiscordProto::AddGuildUser(SnowFlake guildId, const CDiscordGuildMember &p gce.ptszNick = pUser.wszNick; Chat_Event(&gce); - Chat_SetStatusEx(m_szModuleName, pChannel->wszUsername, flags, wszUserId); + Chat_SetStatusEx(m_szModuleName, pGuild->pParentSi->ptszID, flags, wszUserId); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -230,5 +226,5 @@ void CDiscordProto::ParseGuildContents(CDiscordGuild *pGuild, const JSONNode &pR } for (auto &pm : newMembers) - AddGuildUser(pGuild->id, *pm); + AddGuildUser(pGuild, *pm); } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index f6a91aca67..129e9eee64 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -108,7 +108,7 @@ void CDiscordProto::OnModulesLoaded() } GCREGISTER gcr = {}; - gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR | GC_SHAREDUSERS; + gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR; gcr.ptszDispName = m_tszUserName; gcr.pszModule = m_szModuleName; Chat_Register(&gcr); @@ -169,7 +169,7 @@ int CDiscordProto::SetStatus(int iNewStatus) ShutdownSession(); } m_iStatus = m_iDesiredStatus; - setAllContactStatuses(ID_STATUS_OFFLINE, true); + setAllContactStatuses(ID_STATUS_OFFLINE, false); ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus); } diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 5e6d537b24..a99bfa22d2 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -112,6 +112,7 @@ struct CDiscordGuild : public MZeroedObject CMStringW wszName; MCONTACT hContact; + GCSessionInfoBase *pParentSi; OBJLIST<CDiscordGuildMember> arChatUsers; OBJLIST<CDiscordRole> arRoles; // guild roles }; @@ -227,7 +228,7 @@ class CDiscordProto : public PROTO<CDiscordProto> } void ProcessGuild(const JSONNode&); - void AddGuildUser(SnowFlake guildId, const CDiscordGuildMember &pUser); + void AddGuildUser(CDiscordGuild *guild, const CDiscordGuildMember &pUser); void ParseGuildContents(CDiscordGuild *guild, const JSONNode &); CDiscordUser* ProcessGuildChannel(CDiscordGuild *guild, const JSONNode&); void ProcessRole(CDiscordGuild *guild, const JSONNode&); |