summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-06 16:27:47 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-06 16:27:47 +0300
commitbe2aa995bbff6e82a9f5a465490a6e0037c28484 (patch)
tree603fc38b106b579bd635fc1fae9a2c0263ae8fb8 /protocols
parentcde15ed520b736560605d4ce021d99364778b06e (diff)
fixes #4403 (Discord: add 'Make group owner' point to the nick list)
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/dispatch.cpp15
-rw-r--r--protocols/Discord/src/groupchat.cpp17
-rw-r--r--protocols/Discord/src/proto.h1
3 files changed, 25 insertions, 8 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 503b24f682..3691836d98 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -175,6 +175,9 @@ void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot)
pUser->lastMsgId = ::getId(pRoot["last_message_id"]);
+ SnowFlake ownerId = ::getId(pRoot["owner_id"]);
+ setId(pUser->hContact, DB_KEY_OWNERID, ownerId);
+
// if channel name was changed
CMStringW wszName = pRoot["name"].as_mstring();
if (!wszName.IsEmpty()) {
@@ -202,15 +205,13 @@ void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot)
// reset members info for private channels
if (pUser->pGuild == nullptr) {
- SnowFlake ownerId = getId(pUser->hContact, DB_KEY_OWNERID);
-
- for (auto &it : pRoot["recipients"]) {
- CMStringW wszNick(getName(it)), wszUserId(it["id"].as_mstring());
+ for (auto &it : pUser->si->arUsers) {
+ SnowFlake userId = _wtoi64(it->pszUID);
GCEVENT gce = { pUser->si, GC_EVENT_SETSTATUS };
- gce.pszNick.w = wszNick;
- gce.pszUID.w = wszUserId;
- gce.pszStatus.w = (_wtoi64(wszUserId) == ownerId) ? L"Owners" : L"Participants";
+ gce.pszUID.w = it->pszUID;
+ gce.pszStatus.w = (userId == ownerId) ? L"Owners" : L"Participants";
+ gce.bIsMe = userId == m_ownId;
gce.time = time(0);
Chat_Event(&gce);
}
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index 832e254523..81543fa174 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -21,7 +21,8 @@ enum {
IDM_CANCEL,
IDM_COPY_ID,
- IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_RENAME, IDM_DESTROY, IDM_LEAVE,
+ IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_RENAME, IDM_PASSOWNER,
+ IDM_DESTROY, IDM_LEAVE,
IDM_KICK, IDM_INVITE
};
@@ -78,6 +79,7 @@ static gc_item sttNicklistItems[] =
{ LPGENW("Copy ID"), IDM_COPY_ID, MENU_ITEM },
{ nullptr, 0, MENU_SEPARATOR },
{ LPGENW("Kick user"), IDM_KICK, MENU_ITEM },
+ { LPGENW("Make group owner"), IDM_PASSOWNER, MENU_ITEM },
};
int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam)
@@ -106,6 +108,7 @@ int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam)
}
else if (gcmi->Type == MENU_ON_NICKLIST) {
sttDisableMenuItem(_countof(sttNicklistItems), sttNicklistItems, IDM_KICK, !isOwner);
+ sttDisableMenuItem(_countof(sttNicklistItems), sttNicklistItems, IDM_PASSOWNER, !isOwner);
Chat_AddMenuItems(gcmi->hMenu, _countof(sttNicklistItems), sttNicklistItems, &g_plugin);
}
@@ -293,6 +296,14 @@ void CDiscordProto::KickChatUser(CDiscordUser *pChat, const wchar_t *pszUID)
Push(new AsyncHttpRequest(this, REQUEST_DELETE, szUrl, 0));
}
+void CDiscordProto::MakeChatOwner(CDiscordUser *pChat, const wchar_t *pszUID)
+{
+ JSONNode payload; payload << WCHAR_PARAM("owner", pszUID);
+
+ CMStringA szUrl(FORMAT, "/channels/%lld", pChat->channelId);
+ Push(new AsyncHttpRequest(this, REQUEST_PATCH, szUrl, 0, &payload));
+}
+
void CDiscordProto::Chat_ProcessNickMenu(GCHOOK* gch)
{
auto *pChannel = FindUserByChannel(_wtoi64(gch->si->ptszID));
@@ -307,6 +318,10 @@ void CDiscordProto::Chat_ProcessNickMenu(GCHOOK* gch)
case IDM_KICK:
KickChatUser(pChannel, gch->ptszUID);
break;
+
+ case IDM_PASSOWNER:
+ MakeChatOwner(pChannel, gch->ptszUID);
+ break;
}
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index aafc627b4f..c277731f7e 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -397,6 +397,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser);
void KickChatUser(CDiscordUser *pChat, const wchar_t *pszUID);
void LeaveChat(CDiscordUser *pChat);
+ void MakeChatOwner(CDiscordUser *pChat, const wchar_t *pszUID);
void ProcessChatUser(CDiscordUser *pChat, SnowFlake userId, const JSONNode &pRoot);
void ParseSpecialChars(SESSION_INFO *si, CMStringW &str);