summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/proto.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-23 18:34:15 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-23 18:34:15 +0300
commitac6a2d3c5a668324d4115305a621a81e4b5d99fb (patch)
treeb650b4c84c1f7b26d1ca8b1d58776fd65870eec9 /protocols/Discord/src/proto.cpp
parent705649686832a6e12d7eea59e20528a7e61abe14 (diff)
automatic channel creation if user has none
Diffstat (limited to 'protocols/Discord/src/proto.cpp')
-rw-r--r--protocols/Discord/src/proto.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 946a356441..9b4a6fd0ad 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -347,9 +347,23 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc)
return 0;
CDiscordUser *pUser = FindUser(getId(hContact, DB_KEY_ID));
- if (pUser == NULL || pUser->channelId == NULL)
+ if (pUser == NULL || pUser->id == 0)
return 0;
+ // no channel - we need to create one
+ if (pUser->channelId == 0) {
+ JSONNode list(JSON_ARRAY); list.set_name("recipients"); list << INT64_PARAM("", pUser->id);
+ JSONNode body; body << list;
+ CMStringA szUrl(FORMAT, "/users/%lld/channels", m_ownId);
+
+ // theoretically we get the same data from the gateway thread, but there could be a delay
+ // so we bind data analysis to the http packet reply
+ mir_cslock lck(m_csHttpQueue);
+ ExecuteRequest(new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnReceiveCreateChannel, &body));
+ if (pUser->channelId == 0)
+ return 0;
+ }
+
// we generate a random 64-bit integer and pass it to the server
// to distinguish our own messages from these generated by another clients
SnowFlake nonce; Utils_GetRandom(&nonce, sizeof(nonce));