diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-09 17:19:12 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-09 17:19:12 +0300 |
commit | 2aff16cfed601355f871862d7143c43f3528243c (patch) | |
tree | 4fe7b7d46a3ae288f768e233bd77bf05c88b7a9a /protocols/Discord/src/avatars.cpp | |
parent | ee2dac14cc7ef216f42ff46794eea5d37ebc6871 (diff) |
separate method for avatars retrieval
Diffstat (limited to 'protocols/Discord/src/avatars.cpp')
-rw-r--r-- | protocols/Discord/src/avatars.cpp | 32 |
1 files changed, 19 insertions, 13 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; } |