summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-24 16:39:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-24 16:39:59 +0300
commit40a7c77ad034b366007dff28d239d5fbf40da16f (patch)
tree0c476fef01d116b7039653a30795a29bb2747e8a
parent0479fc77ff072b34b01f17d51daf7569a80cf54c (diff)
Discord: private messages in group chats
-rw-r--r--protocols/Discord/src/groupchat.cpp31
-rw-r--r--protocols/Discord/src/proto.cpp15
2 files changed, 36 insertions, 10 deletions
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index 607d6152c6..7bbab9dbd6 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -26,13 +26,9 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam)
if (mir_strcmpi(gch->pDest->pszModule, m_szModuleName))
return 0;
- CDiscordUser *pUser = FindUserByChannel(_wtoi64(gch->pDest->ptszID));
- if (pUser == NULL)
- return 0;
-
switch (gch->pDest->iType) {
case GC_USER_MESSAGE:
- if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) {
+ if (mir_wstrlen(gch->ptszText) > 0) {
rtrimw(gch->ptszText);
if (m_bOnline) {
@@ -40,13 +36,36 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam)
Chat_UnescapeTags(wszText);
JSONNode body; body << WCHAR_PARAM("content", wszText);
- CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId);
+ CMStringA szUrl(FORMAT, "/channels/%s/messages", gch->pDest->ptszID);
Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnReceiveMessage, &body));
}
}
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);
+ break;
+
case GC_USER_LOGMENU:
case GC_USER_NICKLISTMENU:
break;
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 9b4a6fd0ad..03e903e46f 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -195,7 +195,7 @@ void CDiscordProto::SearchThread(void *param)
psr.nick.w = (wchar_t*)param;
psr.firstName.w = L"";
psr.lastName.w = L"";
- psr.id.w = (wchar_t*)param;
+ psr.id.w = L"";
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)param, (LPARAM)&psr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)param, 0);
@@ -289,10 +289,10 @@ int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*)
MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
- if (psr->id.w == NULL)
+ if (mir_wstrlen(psr->nick.w) == 0)
return 0;
- wchar_t *p = wcschr(psr->id.w, '#');
+ wchar_t *p = wcschr(psr->nick.w, '#');
if (p == NULL)
return 0;
@@ -304,12 +304,19 @@ MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
*p = 0;
CDiscordUser *pUser = new CDiscordUser(0);
pUser->hContact = hContact;
- pUser->wszUsername = psr->id.w;
+ pUser->wszUsername = psr->nick.w;
pUser->iDiscriminator = _wtoi(p + 1);
*p = '#';
+ if (mir_wstrlen(psr->id.w)) {
+ pUser->id = _wtoi64(psr->id.w);
+ setId(hContact, DB_KEY_ID, pUser->id);
+ }
+
+ db_set_ws(hContact, "CList", "Group", m_wszDefaultGroup);
setWString(hContact, DB_KEY_NICK, pUser->wszUsername);
setDword(hContact, DB_KEY_DISCR, pUser->iDiscriminator);
+ arUsers.insert(pUser);
return hContact;
}