diff options
author | George Hazan <ghazan@miranda.im> | 2021-11-18 21:59:48 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-11-18 21:59:48 +0300 |
commit | eaf991b1de462b6c3dd61fcef75231e0579f5cef (patch) | |
tree | 5c3495c0f226084796aa4148ea6efa771c10c64a | |
parent | 2ff4116cc11b7b3678f191de0dfb596029add833 (diff) |
Discord: copy ID menu item for group chats
-rw-r--r-- | protocols/Discord/src/groupchat.cpp | 26 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 8 | ||||
-rw-r--r-- | protocols/Discord/src/menus.cpp | 14 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 18 |
6 files changed, 53 insertions, 17 deletions
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp index dbf33f2c53..8c68d1276f 100644 --- a/protocols/Discord/src/groupchat.cpp +++ b/protocols/Discord/src/groupchat.cpp @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. enum { IDM_CANCEL, + IDM_COPY_ID, IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_RENAME, IDM_DESTROY }; @@ -45,6 +46,11 @@ static gc_item sttLogListItems[] = { LPGENW("&Destroy channel"), IDM_DESTROY, MENU_POPUPITEM }, }; +static gc_item sttNicklistItems[] = +{ + { LPGENW("Copy ID"), IDM_COPY_ID, MENU_ITEM }, +}; + int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam) { GCMENUITEMS* gcmi = (GCMENUITEMS*)lParam; @@ -60,6 +66,8 @@ int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam) if (gcmi->Type == MENU_ON_LOG) Chat_AddMenuItems(gcmi->hMenu, _countof(sttLogListItems), sttLogListItems, &g_plugin); + else if (gcmi->Type == MENU_ON_NICKLIST) + Chat_AddMenuItems(gcmi->hMenu, _countof(sttNicklistItems), sttNicklistItems, &g_plugin); return 0; } @@ -146,6 +154,23 @@ void CDiscordProto::Chat_ProcessLogMenu(GCHOOK *gch) } } +void CDiscordProto::Chat_ProcessNickMenu(GCHOOK* gch) +{ + auto *pChannel = FindUserByChannel(_wtoi64(gch->si->ptszID)); + if (pChannel == nullptr || pChannel->pGuild == nullptr) + return; + + auto* pUser = pChannel->pGuild->FindUser(_wtoi64(gch->ptszUID)); + if (pUser == nullptr) + return; + + switch (gch->dwData) { + case IDM_COPY_ID: + CopyId(pUser->wszDiscordId); + break; + } +} + int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK*)lParam; @@ -198,6 +223,7 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam) break; case GC_USER_NICKLISTMENU: + Chat_ProcessNickMenu(gch); break; } diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 267084b60a..3bed5cee8f 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -292,9 +292,10 @@ CDiscordGuildMember* CDiscordProto::ProcessGuildUser(CDiscordGuild *pGuild, cons bNew = true; } + pm->wszDiscordId = pUser["username"].as_mstring() + L"#" + pUser["discriminator"].as_mstring(); pm->wszNick = pRoot["nick"].as_mstring(); if (pm->wszNick.IsEmpty()) - pm->wszNick = pUser["username"].as_mstring() + L"#" + pUser["discriminator"].as_mstring(); + pm->wszNick = pm->wszDiscordId; else bNew = true; @@ -332,9 +333,10 @@ void CDiscordProto::ProcessChatUser(CDiscordUser *pChat, const CMStringW &wszUse // otherwise let's create a user and insert him into all guild's chats pm = new CDiscordGuildMember(userId); + pm->wszDiscordId = pRoot["author"]["username"].as_mstring() + L"#" + pRoot["author"]["discriminator"].as_mstring(); pm->wszNick = pRoot["nick"].as_mstring(); if (pm->wszNick.IsEmpty()) - pm->wszNick = pRoot["author"]["username"].as_mstring() + L"#" + pRoot["author"]["discriminator"].as_mstring(); + pm->wszNick = pm->wszDiscordId; pGuild->arChatUsers.insert(pm); debugLogA("add missing user to chat: id=%lld, nick=%S", userId, pm->wszNick.c_str()); @@ -365,7 +367,7 @@ void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMembe ///////////////////////////////////////////////////////////////////////////////////////// -void CDiscordGuild ::LoadFromFile() +void CDiscordGuild::LoadFromFile() { int fileNo = _wopen(GetCacheFile(), O_TEXT | O_RDONLY); if (fileNo == -1) diff --git a/protocols/Discord/src/menus.cpp b/protocols/Discord/src/menus.cpp index 5aa2f37926..f51d7c7d5c 100644 --- a/protocols/Discord/src/menus.cpp +++ b/protocols/Discord/src/menus.cpp @@ -19,19 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. INT_PTR CDiscordProto::OnMenuCopyId(WPARAM hContact, LPARAM) { - if (OpenClipboard(nullptr)) { - EmptyClipboard(); - - CMStringW mynick(FORMAT, L"%s#%d", getMStringW(hContact, DB_KEY_NICK).c_str(), getDword(hContact, DB_KEY_DISCR)); - int length = mynick.GetLength() + 1; - if (HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, length * sizeof(wchar_t))) { - mir_wstrncpy((wchar_t *)GlobalLock(hMemory), mynick, length); - GlobalUnlock(hMemory); - SetClipboardData(CF_UNICODETEXT, hMemory); - } - CloseClipboard(); - } - + CopyId(CMStringW(FORMAT, L"%s#%d", getMStringW(hContact, DB_KEY_NICK).c_str(), getDword(hContact, DB_KEY_DISCR))); return 0; } diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 2c63b09362..c90aafba6a 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -103,7 +103,7 @@ struct CDiscordGuildMember : public MZeroedObject {} SnowFlake userId; - CMStringW wszNick, wszRole; + CMStringW wszDiscordId, wszNick, wszRole; int iStatus; }; @@ -327,6 +327,7 @@ class CDiscordProto : public PROTO<CDiscordProto> void Chat_SendPrivateMessage(GCHOOK *gch); void Chat_ProcessLogMenu(GCHOOK *gch); + void Chat_ProcessNickMenu(GCHOOK* gch); void CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser); void ProcessChatUser(CDiscordUser *pChat, const CMStringW &wszUserId, const JSONNode &pRoot); diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index e80ebac2cf..6cba015cc3 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -72,6 +72,7 @@ extern IconItem g_iconList[]; void BuildStatusList(const CDiscordGuild *pGuild, SESSION_INFO *si); +void CopyId(const CMStringW &nick); SnowFlake getId(const JSONNode &pNode); CMStringW PrepareMessageText(const JSONNode &pRoot); int StrToStatus(const CMStringW &str); diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 91a777e5e0..a3764f9b35 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -104,6 +104,24 @@ void CDiscordProto::setId(MCONTACT hContact, const char *szSetting, SnowFlake iV ///////////////////////////////////////////////////////////////////////////////////////// +void CopyId(const CMStringW &nick) +{ + if (!OpenClipboard(nullptr)) + return; + + EmptyClipboard(); + + int length = nick.GetLength() + 1; + if (HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, length * sizeof(wchar_t))) { + mir_wstrncpy((wchar_t*)GlobalLock(hMemory), nick, length); + GlobalUnlock(hMemory); + SetClipboardData(CF_UNICODETEXT, hMemory); + } + CloseClipboard(); +} + +///////////////////////////////////////////////////////////////////////////////////////// + static CDiscordUser *g_myUser = new CDiscordUser(0); CDiscordUser* CDiscordProto::FindUser(SnowFlake id) |