diff options
Diffstat (limited to 'protocols/Discord/src/proto.cpp')
-rw-r--r-- | protocols/Discord/src/proto.cpp | 16 |
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)); |