summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-03 22:20:47 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-03 22:20:47 +0300
commit8b014af3ba76c2123745c5ec97b0f32303037956 (patch)
treefddb84071b124c65d821dc57358724c3b10c4aea
parentb6a037ba8b2bf275bafafd48d472d33c3886c7c6 (diff)
fixes #4391 (Discord: "Destroy channel" не стирает контакт из базы)
-rw-r--r--protocols/Discord/src/dispatch.cpp8
-rw-r--r--protocols/Discord/src/groupchat.cpp37
-rw-r--r--protocols/Discord/src/proto.cpp2
-rw-r--r--protocols/Discord/src/proto.h3
-rw-r--r--protocols/Discord/src/stdafx.h1
-rw-r--r--protocols/Discord/src/utils.cpp1
6 files changed, 44 insertions, 8 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index c6efbd151e..bcac245361 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -105,8 +105,11 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot)
SnowFlake guildId = ::getId(pRoot["guild_id"]);
if (guildId == 0) {
- pUser->channelId = pUser->lastMsgId = 0;
- delSetting(pUser->hContact, DB_KEY_CHANNELID);
+ if (auto *si = pUser->si) {
+ Chat_Control(si, SESSION_OFFLINE);
+ Chat_Terminate(si);
+ }
+ db_delete_contact(pUser->hContact);
}
else {
CDiscordGuild *pGuild = FindGuild(guildId);
@@ -115,6 +118,7 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot)
pUser->si = nullptr;
}
}
+ arUsers.remove(pUser);
}
void CDiscordProto::OnCommandChannelUserAdded(const JSONNode &pRoot)
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index f79cdfdb5c..0e5eb96d32 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -21,7 +21,7 @@ enum {
IDM_CANCEL,
IDM_COPY_ID,
- IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_RENAME, IDM_DESTROY
+ IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_RENAME, IDM_DESTROY, IDM_LEAVE
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -52,7 +52,8 @@ static gc_item sttLogListItems[] =
{ LPGENW("Change &topic"), IDM_CHANGETOPIC, MENU_POPUPITEM },
{ LPGENW("&Rename channel"), IDM_RENAME, MENU_POPUPITEM },
{ nullptr, 0, MENU_POPUPSEPARATOR },
- { LPGENW("&Destroy channel"), IDM_DESTROY, MENU_POPUPITEM },
+ { LPGENW("Destroy channel"), IDM_DESTROY, MENU_POPUPITEM },
+ { LPGENW("Leave channel"), IDM_LEAVE, MENU_POPUPITEM },
};
static gc_item sttNicklistItems[] =
@@ -76,6 +77,12 @@ int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam)
if (gcmi->Type == MENU_ON_LOG) {
if (pChat->pGuild == nullptr)
sttLogListItems[0].uType = 0;
+
+ if (getId(pChat->hContact, DB_KEY_OWNERID) == m_ownId)
+ sttLogListItems[6].uType = 0;
+ else
+ sttLogListItems[5].uType = 0;
+
Chat_AddMenuItems(gcmi->hMenu, _countof(sttLogListItems), sttLogListItems, &g_plugin);
}
else if (gcmi->Type == MENU_ON_NICKLIST)
@@ -121,10 +128,12 @@ void CDiscordProto::Chat_ProcessLogMenu(GCHOOK *gch)
switch (gch->dwData) {
case IDM_DESTROY:
- if (IDYES == MessageBox(nullptr, TranslateT("Do you really want to destroy this channel? This action is non-revertable."), m_tszUserName, MB_YESNO | MB_ICONQUESTION)) {
- CMStringA szUrl(FORMAT, "/channels/%S", pUser->wszUsername.c_str());
- Push(new AsyncHttpRequest(this, REQUEST_DELETE, szUrl, nullptr));
- }
+ if (IDYES == MessageBox(nullptr, TranslateT("Do you really want to destroy this channel? This action is non-revertable."), m_tszUserName, MB_YESNO | MB_ICONQUESTION))
+ LeaveChat(pUser);
+ break;
+
+ case IDM_LEAVE:
+ LeaveChat(pUser);
break;
case IDM_RENAME:
@@ -245,3 +254,19 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam)
return 1;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDiscordProto::LeaveChat(CDiscordUser *pChat)
+{
+ CMStringA szUrl(FORMAT, "/channels/%S", pChat->wszUsername.c_str());
+ Push(new AsyncHttpRequest(this, REQUEST_DELETE, szUrl, nullptr));
+}
+
+INT_PTR CDiscordProto::SvcLeaveChat(WPARAM hContact, LPARAM)
+{
+ if (auto *pUser = FindUserByChannel(getId(hContact, DB_KEY_ID)))
+ if (pUser->si)
+ LeaveChat(pUser);
+ return 0;
+}
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index daa6d1ee18..0cb25c33de 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -65,6 +65,8 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
CreateProtoService(PS_MENU_REQAUTH, &CDiscordProto::RequestFriendship);
CreateProtoService(PS_MENU_LOADHISTORY, &CDiscordProto::OnMenuLoadHistory);
+ CreateProtoService(PS_LEAVECHAT, &CDiscordProto::SvcLeaveChat);
+
CreateProtoService(PS_VOICE_CAPS, &CDiscordProto::VoiceCaps);
// Events
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 0392907394..57d7094476 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -394,6 +394,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void Chat_ProcessNickMenu(GCHOOK* gch);
void CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser);
+ void LeaveChat(CDiscordUser *pChat);
void ProcessChatUser(CDiscordUser *pChat, SnowFlake userId, const JSONNode &pRoot);
void ParseSpecialChars(SESSION_INFO *si, CMStringW &str);
@@ -457,6 +458,8 @@ public:
INT_PTR __cdecl RequestFriendship(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcLeaveChat(WPARAM, LPARAM);
+
INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h
index 1c137e42fa..dfea7e61dd 100644
--- a/protocols/Discord/src/stdafx.h
+++ b/protocols/Discord/src/stdafx.h
@@ -59,6 +59,7 @@ extern IconItem g_iconList[];
#define DB_KEY_DISCR "Discriminator"
#define DB_KEY_MFA "MfaEnabled"
#define DB_KEY_NICK "Nick"
+#define DB_KEY_OWNERID "OwnerID"
#define DB_KEY_AVHASH "AvatarHash"
#define DB_KEY_CHANNELID "ChannelID"
#define DB_KEY_LASTMSGID "LastMessageID"
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index 9b62c9fa93..a3cf8f9f5d 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -213,6 +213,7 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root)
Chat_AddGroup(si, LPGENW("Participants"));
{
SnowFlake ownerId = _wtoi64(root["owner_id"].as_mstring());
+ setId(pUser->hContact, DB_KEY_OWNERID, ownerId);
GCEVENT gce = { si, GC_EVENT_JOIN };
for (auto &it : root["recipients"]) {