summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/utils.cpp
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/src/utils.cpp
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/src/utils.cpp')
-rw-r--r--protocols/Discord/src/utils.cpp17
1 files changed, 15 insertions, 2 deletions
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);
}