summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-02-02 16:36:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-02-02 16:36:43 +0300
commite1d7991a9095a848f0be2dd4a2677697b2e500da (patch)
treeddecdab8142634c6e2147adf0d8d9da203db7384
parentfa650aaf5029cc11edf1540996e596a88acabbc1 (diff)
Discord: avatar change detector moved to the separate function
-rw-r--r--protocols/Discord/src/avatars.cpp13
-rw-r--r--protocols/Discord/src/dispatch.cpp7
-rw-r--r--protocols/Discord/src/proto.h1
-rw-r--r--protocols/Discord/src/server.cpp12
-rw-r--r--protocols/Discord/src/utils.cpp6
5 files changed, 18 insertions, 21 deletions
diff --git a/protocols/Discord/src/avatars.cpp b/protocols/Discord/src/avatars.cpp
index e44df7da04..fff069b252 100644
--- a/protocols/Discord/src/avatars.cpp
+++ b/protocols/Discord/src/avatars.cpp
@@ -211,3 +211,16 @@ INT_PTR CDiscordProto::SetMyAvatar(WPARAM, LPARAM lParam)
Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me", NULL, &root));
return 0;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDiscordProto::CheckAvatarChange(MCONTACT hContact, const CMStringW &wszNewHash)
+{
+ ptrW wszOldAvatar(getWStringA(hContact, DB_KEY_AVHASH));
+
+ // if avatar's hash changed, we need to request a new one
+ if (mir_wstrcmp(wszNewHash, wszOldAvatar)) {
+ setWString(hContact, DB_KEY_AVHASH, wszNewHash);
+ RetrieveAvatar(hContact);
+ }
+}
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 299074adde..7b5f2587e1 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -419,12 +419,7 @@ void CDiscordProto::OnCommandUserUpdate(const JSONNode &pRoot)
else hContact = 0;
// force rereading avatar
- ptrW wszOldHash(getWStringA(hContact, DB_KEY_AVHASH));
- CMStringW wszNewHash(pRoot["avatar"].as_mstring());
- if (mir_wstrcmp(wszOldHash, wszNewHash)) {
- setWString(hContact, DB_KEY_AVHASH, wszNewHash);
- RetrieveAvatar(hContact);
- }
+ CheckAvatarChange(hContact, pRoot["avatar"].as_mstring());
}
void CDiscordProto::OnCommandUserSettingsUpdate(const JSONNode &pRoot)
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 3fde65a597..91cfe59ab7 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -280,6 +280,7 @@ public:
void RemoveFriend(SnowFlake id);
CMStringW GetAvatarFilename(MCONTACT hContact);
+ void CheckAvatarChange(MCONTACT hContact, const CMStringW &wszNewHash);
__forceinline int getHeartbeatInterval() const { return m_iHartbeatInterval; }
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index ece1f6a79d..5d86ec1721 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -146,8 +146,6 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques
return;
}
- ptrW wszOldAvatar(getWStringA(hContact, DB_KEY_AVHASH));
-
SnowFlake id = _wtoi64(root["id"].as_mstring());
setId(hContact, DB_KEY_ID, id);
@@ -156,22 +154,16 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques
setWString(hContact, DB_KEY_NICK, root["username"].as_mstring());
setWString(hContact, DB_KEY_EMAIL, root["email"].as_mstring());
- CMStringW wszNewAvatar(root["avatar"].as_mstring());
- setWString(hContact, DB_KEY_AVHASH, wszNewAvatar);
-
if (hContact == NULL) {
m_ownId = id;
-
- // if avatar's hash changed, we need to request a new one
- if (mir_wstrcmp(wszNewAvatar, wszOldAvatar))
- RetrieveAvatar(NULL);
-
OnLoggedIn();
}
else {
CDiscordUser *pUser = FindUser(id);
ProcessType(pUser, root);
}
+
+ CheckAvatarChange(hContact, root["avatar"].as_mstring());
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index 5b496b74c4..de86bef956 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -172,7 +172,6 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
return g_myUser;
int iDiscriminator = _wtoi(user["discriminator"].as_mstring());
- CMStringW avatar = user["avatar"].as_mstring();
CMStringW username = user["username"].as_mstring();
CDiscordUser *pUser = FindUser(id);
@@ -210,10 +209,7 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
pUser->hContact = hContact;
}
- if (avatar.IsEmpty())
- delSetting(pUser->hContact, DB_KEY_AVHASH);
- else
- setWString(pUser->hContact, DB_KEY_AVHASH, avatar);
+ CheckAvatarChange(pUser->hContact, user["avatar"].as_mstring());
return pUser;
}