diff options
Diffstat (limited to 'protocols/Discord/src/groupchat.cpp')
-rw-r--r-- | protocols/Discord/src/groupchat.cpp | 116 |
1 files changed, 90 insertions, 26 deletions
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp index fa317b5171..13c2690bd2 100644 --- a/protocols/Discord/src/groupchat.cpp +++ b/protocols/Discord/src/groupchat.cpp @@ -17,6 +17,92 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" +enum { + IDM_CANCEL, + + IDM_CHANGENICK, IDM_INVITE +}; + +static gc_item sttLogListItems[] = +{ + { LPGENW("Change &nickname"), IDM_CHANGENICK, MENU_ITEM }, + { LPGENW("&Invite a user"), IDM_INVITE, MENU_ITEM }, +}; + +int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM lParam) +{ + GCMENUITEMS* gcmi = (GCMENUITEMS*)lParam; + if (gcmi == NULL) + return 0; + + if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) + return 0; + + CDiscordUser *pChat = FindUserByChannel(_wtoi64(gcmi->pszID)); + if (pChat == NULL) + return 0; + + if (gcmi->Type == MENU_ON_LOG) { + gcmi->nItems = _countof(sttLogListItems); + gcmi->Item = sttLogListItems; + } + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void CDiscordProto::Chat_SendPrivateMessage(GCHOOK *gch) +{ + SnowFlake userId = _wtoi64(gch->ptszUID); + + MCONTACT hContact; + CDiscordUser *pUser = FindUser(userId); + if (pUser == NULL) { + PROTOSEARCHRESULT psr = { sizeof(psr) }; + psr.id.w = (wchar_t*)gch->ptszUID; + psr.nick.w = (wchar_t*)gch->ptszNick; + if ((hContact = AddToList(PALF_TEMPORARY, &psr)) == 0) + return; + + setId(hContact, DB_KEY_ID, userId); + setId(hContact, DB_KEY_CHANNELID, _wtoi64(gch->pDest->ptszID)); + setWString(hContact, "Nick", gch->ptszNick); + db_set_b(hContact, "CList", "Hidden", 1); + db_set_dw(hContact, "Ignore", "Mask1", 0); + } + else hContact = pUser->hContact; + + CallService(MS_MSG_SENDMESSAGE, hContact, 0); +} + +void CDiscordProto::Chat_ProcessLogMenu(GCHOOK *gch) +{ + CDiscordUser *pUser = FindUserByChannel(_wtoi64(gch->pDest->ptszID)); + if (pUser == NULL) + return; + + switch (gch->dwData) { + case IDM_INVITE: + break; + + case IDM_CHANGENICK: + ENTER_STRING es = { sizeof(es) }; + es.caption = TranslateT("Enter your new nick name:"); + es.type = ESF_COMBO; + es.szModuleName = m_szModuleName; + es.szDataPrefix = "chat_nick"; + es.recentCount = 5; + if (EnterString(&es)) { + JSONNode root; root << WCHAR_PARAM("nick", es.ptszResult); + CMStringA szUrl(FORMAT, "/guilds/%lld/members/@me/nick", pUser->guildId); + Push(new AsyncHttpRequest(this, REQUEST_PATCH, szUrl, NULL, &root)); + mir_free(es.ptszResult); + } + break; + } +} + int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK*)lParam; @@ -43,38 +129,16 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam) break; case GC_USER_PRIVMESS: - MCONTACT hContact; - { - SnowFlake userId = _wtoi64(gch->ptszUID); - - CDiscordUser *pUser = FindUser(userId); - if (pUser == NULL) { - PROTOSEARCHRESULT psr = { sizeof(psr) }; - psr.id.w = (wchar_t*)gch->ptszUID; - psr.nick.w = (wchar_t*)gch->ptszNick; - if ((hContact = AddToList(PALF_TEMPORARY, &psr)) == 0) - return 0; - - setId(hContact, DB_KEY_ID, userId); - setId(hContact, DB_KEY_CHANNELID, _wtoi64(gch->pDest->ptszID)); - setWString(hContact, "Nick", gch->ptszNick); - db_set_b(hContact, "CList", "Hidden", 1); - db_set_dw(hContact, "Ignore", "Mask1", 0); - } - else hContact = pUser->hContact; - } - CallService(MS_MSG_SENDMESSAGE, hContact, 0); + Chat_SendPrivateMessage(gch); break; case GC_USER_LOGMENU: + Chat_ProcessLogMenu(gch); + break; + case GC_USER_NICKLISTMENU: break; } return 0; } - -int CDiscordProto::GroupchatMenuHook(WPARAM, LPARAM) -{ - return 0; -} |