diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-08 23:27:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-08 23:27:13 +0300 |
commit | 9ab52162d7d1e0bdbf47d412fcfe83d533f0708b (patch) | |
tree | 9c8050b008642b41655bd773ca6e516212fba0ae /protocols | |
parent | f05340be7d013ac713fd24c19ff8304712223a73 (diff) |
better way of setting avatar either for me or any other user
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/src/avatars.cpp | 16 | ||||
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 31 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 2 |
3 files changed, 33 insertions, 16 deletions
diff --git a/protocols/Discord/src/avatars.cpp b/protocols/Discord/src/avatars.cpp index aac083789b..ec984d4fa4 100644 --- a/protocols/Discord/src/avatars.cpp +++ b/protocols/Discord/src/avatars.cpp @@ -163,20 +163,6 @@ INT_PTR CDiscordProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// -void CDiscordProto::OnReceiveMyAvatar(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) -{ - MCONTACT hContact = (MCONTACT)pReq->pUserInfo; - if (pReply->resultCode != 200) - return; - - JSONNode root = JSONNode::parse(pReply->pData); - if (!root) - return; - - setWString(hContact, DB_KEY_AVHASH, root["avatar"].as_mstring()); - CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); -} - INT_PTR CDiscordProto::SetMyAvatar(WPARAM, LPARAM lParam) { CMStringW wszFileName(GetAvatarFilename(NULL)); @@ -213,6 +199,6 @@ INT_PTR CDiscordProto::SetMyAvatar(WPARAM, LPARAM lParam) szPayload.Append(ptrA(mir_base64_encode((BYTE*)szFileContents.get(), iFileLength))); JSONNode root; root << CHAR_PARAM("avatar", szPayload); - Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me", &CDiscordProto::OnReceiveMyAvatar, &root)); + Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me", NULL, &root)); return 0; } diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index e96471f116..0b7f96a33f 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -36,6 +36,8 @@ static handlers[] = // these structures must me sorted alphabetically { L"READY", &CDiscordProto::OnCommandReady }, { L"TYPING_START", &CDiscordProto::OnCommandTyping }, + + { L"USER_UPDATE", &CDiscordProto::OnCommandUserUpdate }, }; static int __cdecl pSearchFunc(const void *p1, const void *p2) @@ -182,3 +184,32 @@ void CDiscordProto::OnCommandTyping(const JSONNode &pRoot) debugLogA("user is typing in a group channel, skipped"); } } + +////////////////////////////////////////////////////////////////////////////////////// +// UTN support + +void CDiscordProto::OnCommandUserUpdate(const JSONNode &pRoot) +{ + SnowFlake id = _wtoi64(pRoot["id"].as_mstring()); + + MCONTACT hContact; + if (id != m_ownId) { + CDiscordUser *pUser = FindUser(id); + if (pUser == NULL) + return; + + hContact = pUser->hContact; + } + 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); + + PROTO_AVATAR_INFORMATION ai = {}; + ai.hContact = hContact; + GetAvatarInfo(GAIF_FORCE, (LPARAM)&ai); + } +} diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 6996b54aed..66709e8f3b 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -218,6 +218,7 @@ public: void OnCommandPresence(const JSONNode&); void OnCommandReady(const JSONNode&); void OnCommandTyping(const JSONNode&); + void OnCommandUserUpdate(const JSONNode&); void OnLoggedIn(); void OnLoggedOut(); @@ -229,7 +230,6 @@ public: void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveGuilds(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveMessageAck(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void OnReceiveMyAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveToken(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveUserInfo(MCONTACT hContact); |