summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Discord/src/avatars.cpp32
-rw-r--r--protocols/Discord/src/proto.h4
-rw-r--r--protocols/Discord/src/server.cpp6
3 files changed, 24 insertions, 18 deletions
diff --git a/protocols/Discord/src/avatars.cpp b/protocols/Discord/src/avatars.cpp
index ec984d4fa4..1e0f41a565 100644
--- a/protocols/Discord/src/avatars.cpp
+++ b/protocols/Discord/src/avatars.cpp
@@ -108,7 +108,21 @@ LBL_Error:
CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0);
}
-INT_PTR CDiscordProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
+bool CDiscordProto::RetrieveAvatar(MCONTACT hContact)
+{
+ ptrA szAvatarHash(getStringA(hContact, DB_KEY_AVHASH));
+ SnowFlake id = getId(hContact, DB_KEY_ID);
+ if (id == 0 || szAvatarHash == NULL)
+ return false;
+
+ CMStringA szUrl(FORMAT, "https://cdn.discordapp.com/avatars/%lld/%s.jpg", id, szAvatarHash);
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveAvatar);
+ pReq->pUserInfo = (void*)hContact;
+ Push(pReq);
+ return true;
+}
+
+INT_PTR CDiscordProto::GetAvatarInfo(WPARAM flags, LPARAM lParam)
{
PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION *)lParam;
@@ -119,19 +133,11 @@ INT_PTR CDiscordProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
bool bFileExist = _waccess(wszFileName, 0) == 0;
// if we still need to load an avatar
- if ((wParam & GAIF_FORCE) || !bFileExist) {
- ptrA szAvatarHash(getStringA(pai->hContact, DB_KEY_AVHASH));
- SnowFlake id = getId(pai->hContact, DB_KEY_ID);
- if (id == 0 || szAvatarHash == NULL)
- return GAIR_NOAVATAR;
-
- CMStringA szUrl(FORMAT, "https://cdn.discordapp.com/avatars/%lld/%s.jpg", id, szAvatarHash);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveAvatar);
- pReq->pUserInfo = (void*)pai->hContact;
- Push(pReq);
- return GAIR_WAITFOR;
+ if ((flags & GAIF_FORCE) || !bFileExist) {
+ if (RetrieveAvatar(pai->hContact))
+ return GAIR_WAITFOR;
}
- if (bFileExist)
+ else if (bFileExist)
return GAIR_SUCCESS;
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index d6b00fe878..b5293614ea 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -233,7 +233,6 @@ public:
void OnLoggedOut();
void OnReceiveAuth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveChannels(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -247,6 +246,9 @@ public:
void RetrieveHistory(MCONTACT hContact, CDiscordHitoryOp iOp = MSG_NOFILTER, SnowFlake msgid = 0, int iLimit = 50);
void OnReceiveHistory(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ bool RetrieveAvatar(MCONTACT hContact);
+ void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+
// Misc
void SetServerStatus(int iStatus);
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index b0d836e889..a8a44b500a 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -125,10 +125,8 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques
if (hContact == NULL) {
// if avatar's hash changed, we need to request a new one
- if (mir_wstrcmp(wszNewAvatar, wszOldAvatar)) {
- PROTO_AVATAR_INFORMATION ai = {};
- GetAvatarInfo(GAIF_FORCE, (LPARAM)&ai);
- }
+ if (mir_wstrcmp(wszNewAvatar, wszOldAvatar))
+ RetrieveAvatar(NULL);
OnLoggedIn();
}