diff options
author | George Hazan <ghazan@miranda.im> | 2017-02-01 21:03:42 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-02-01 21:03:42 +0300 |
commit | 3e9fed0c18b72ccf4a7b06f62fe7eff2e12d773c (patch) | |
tree | f4cc66cf0f18bba5a10d0a93d42dc9debee0f90f | |
parent | d2d633a1667ea16c9c88eae9d679c91c545a77ee (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
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 12 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 17 |
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); } |