diff options
author | George Hazan <ghazan@miranda.im> | 2019-03-06 20:34:51 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-03-06 20:34:51 +0300 |
commit | e855b0922f15871e8deb07562f3d5c8ba675bf93 (patch) | |
tree | 1f0dc19f024964595c1c53d1d8ef3d33cdd6c47f /protocols/Discord/src | |
parent | 85a007ed346d57d266dca3f6c6b2809ca8d61c97 (diff) |
related to #1863 ([Discord] Make option to turn off group chats/channels ; & add manual history sync from IMs/DMs (private chat))
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 5 | ||||
-rw-r--r-- | protocols/Discord/src/menus.cpp | 26 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 5 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
5 files changed, 36 insertions, 5 deletions
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index da7b4a7441..023b8684fd 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -130,9 +130,6 @@ void CDiscordProto::ProcessGuild(const JSONNode &p) arGuilds.insert(pGuild); } - if (!pGuild->bSynced) - GatewaySendGuildInfo(guildId); - pGuild->ownerId = ::getId(p["owner_id"]); pGuild->wszName = p["name"].as_mstring(); if (m_bUseGuildGroups) @@ -142,6 +139,8 @@ void CDiscordProto::ProcessGuild(const JSONNode &p) pGuild->pParentSi = (SESSION_INFO*)si; pGuild->hContact = si->hContact; setId(si->hContact, DB_KEY_CHANNELID, guildId); + if (!pGuild->bSynced && getByte(si->hContact, "EnableSync")) + GatewaySendGuildInfo(guildId); Chat_Control(m_szModuleName, pGuild->wszName, WINDOW_HIDDEN); Chat_Control(m_szModuleName, pGuild->wszName, SESSION_ONLINE); diff --git a/protocols/Discord/src/menus.cpp b/protocols/Discord/src/menus.cpp index a465dbb33c..88404bd782 100644 --- a/protocols/Discord/src/menus.cpp +++ b/protocols/Discord/src/menus.cpp @@ -76,15 +76,33 @@ INT_PTR CDiscordProto::OnMenuLeaveGuild(WPARAM hContact, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// +INT_PTR CDiscordProto::OnMenuToggleSync(WPARAM hContact, LPARAM) +{ + bool bEnabled = !getBool(hContact, "EnableSync"); + setByte(hContact, "EnableSync", bEnabled); + + if (bEnabled) + GatewaySendGuildInfo(getId(hContact, DB_KEY_CHANNELID)); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + int CDiscordProto::OnMenuPrebuild(WPARAM hContact, LPARAM) { // "Leave guild" menu item should be visible only for the guild contacts bool bIsGuild = getByte(hContact, "ChatRoom") == 2; Menu_ShowItem(m_hMenuLeaveGuild, bIsGuild); Menu_ShowItem(m_hMenuCreateChannel, bIsGuild); + Menu_ShowItem(m_hMenuToggleSync, bIsGuild); if (getWord(hContact, "ApparentMode") != 0) Menu_ShowItem(m_hmiReqAuth, true); + + if (getByte(hContact, "EnableSync")) + Menu_ModifyItem(m_hMenuToggleSync, LPGENW("Disable sync"), Skin_GetIconHandle(SKINICON_CHAT_LEAVE)); + else + Menu_ModifyItem(m_hMenuToggleSync, LPGENW("Enable sync"), Skin_GetIconHandle(SKINICON_CHAT_JOIN)); return 0; } @@ -136,5 +154,13 @@ void CDiscordProto::InitMenus() SET_UID(mi2, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8E); Menu_AddContactMenuItem(&mi2, m_szModuleName); + mi2.pszService = "/ToggleSync"; + CreateProtoService(mi2.pszService, &CDiscordProto::OnMenuToggleSync); + mi2.name.a = LPGEN("Enable guild"); + mi2.position = -200001003; + mi2.hIcolibItem = Skin_GetIconHandle(SKINICON_CHAT_JOIN); + SET_UID(mi2, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8F); + m_hMenuToggleSync = Menu_AddContactMenuItem(&mi2, m_szModuleName); + HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CDiscordProto::OnMenuPrebuild); } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index b01d48ce58..e20cdb18ca 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -110,6 +110,11 @@ void CDiscordProto::OnModulesLoaded() pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); arUsers.insert(pNew); + + // set EnableSync = 1 by default for all existing guilds + if (getByte(hContact, "ChatRoom") == 2) + if (getDword(hContact, "EnableSync", -1) == -1) + setDword(hContact, "EnableSync", 1); } GCREGISTER gcr = {}; diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index c11a7787a6..873287bc1c 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -209,8 +209,9 @@ class CDiscordProto : public PROTO<CDiscordProto> INT_PTR __cdecl OnMenuCreateChannel(WPARAM, LPARAM); INT_PTR __cdecl OnMenuJoinGuild(WPARAM, LPARAM); INT_PTR __cdecl OnMenuLeaveGuild(WPARAM, LPARAM); + INT_PTR __cdecl OnMenuToggleSync(WPARAM, LPARAM); - HGENMENU m_hMenuLeaveGuild, m_hMenuCreateChannel; + HGENMENU m_hMenuLeaveGuild, m_hMenuCreateChannel, m_hMenuToggleSync; ////////////////////////////////////////////////////////////////////////////////////// // guilds diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index 970893d9dd..da2758b1c2 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 6 #define __RELEASE_NUM 1 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include <stdver.h> |