summaryrefslogtreecommitdiff
path: root/protocols/Discord
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-02-01 21:03:42 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-02-01 21:03:42 +0300
commit3e9fed0c18b72ccf4a7b06f62fe7eff2e12d773c (patch)
treef4cc66cf0f18bba5a10d0a93d42dc9debee0f90f /protocols/Discord
parentd2d633a1667ea16c9c88eae9d679c91c545a77ee (diff)
Discord:
- we don't request user info when no user id is set; - fix for the user addition; - fix for creating shadow users when a presence is sent to non-existing user
Diffstat (limited to 'protocols/Discord')
-rw-r--r--protocols/Discord/src/dispatch.cpp2
-rw-r--r--protocols/Discord/src/server.cpp12
-rw-r--r--protocols/Discord/src/utils.cpp17
3 files changed, 24 insertions, 7 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index becbab63f9..299074adde 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -249,7 +249,7 @@ void CDiscordProto::OnCommandMessageAck(const JSONNode &pRoot)
void CDiscordProto::OnCommandPresence(const JSONNode &pRoot)
{
- CDiscordUser *pUser = PrepareUser(pRoot["user"]);
+ CDiscordUser *pUser = FindUser(_wtoi64(pRoot["user"]["id"].as_mstring()));
if (pUser == NULL)
return;
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index ecc43c6b07..ece1f6a79d 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -117,10 +117,14 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest
void CDiscordProto::RetrieveUserInfo(MCONTACT hContact)
{
CMStringA szUrl;
- if (hContact == 0)
- szUrl = "/users/@me";
- else
- szUrl.Format("/users/%lld", getId(hContact, DB_KEY_ID));
+ if (hContact != 0) {
+ SnowFlake id = getId(hContact, DB_KEY_ID);
+ if (id == 0)
+ return;
+ szUrl.Format("/users/%lld", id);
+ }
+ else szUrl = "/users/@me";
+
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveUserInfo);
pReq->pUserInfo = (void*)hContact;
Push(pReq);
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index daddcc46ff..5b496b74c4 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -176,12 +176,25 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
CMStringW username = user["username"].as_mstring();
CDiscordUser *pUser = FindUser(id);
- if (pUser == NULL)
- pUser = FindUser(username, iDiscriminator);
if (pUser == NULL) {
+ MCONTACT tmp = INVALID_CONTACT_ID;
+
+ // no user found by userid, try to find him via username+discriminator
+ pUser = FindUser(username, iDiscriminator);
+ if (pUser != NULL) {
+ // if found, remove the object from list to resort it (its userid==0)
+ if (pUser->hContact != 0)
+ tmp = pUser->hContact;
+ arUsers.remove(pUser);
+ }
pUser = new CDiscordUser(id);
pUser->wszUsername = username;
pUser->iDiscriminator = iDiscriminator;
+ if (tmp != INVALID_CONTACT_ID) {
+ // if we previously had a recently added contact without userid, write it down
+ pUser->hContact = tmp;
+ setId(pUser->hContact, DB_KEY_ID, id);
+ }
arUsers.insert(pUser);
}