diff options
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 7 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 2 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 21 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 28 |
4 files changed, 45 insertions, 13 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index ef8cb223f7..ba58f4cd16 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -33,6 +33,7 @@ static handlers[] = // these structures must me sorted alphabetically { L"READY", &CDiscordProto::OnCommandReady }, + { L"RELATIONSHIP_ADD", &CDiscordProto::OnCommandFriendAdded }, { L"RELATIONSHIP_REMOVE", &CDiscordProto::OnCommandFriendRemoved }, { L"TYPING_START", &CDiscordProto::OnCommandTyping }, @@ -55,6 +56,12 @@ GatewayHandlerFunc CDiscordProto::GetHandler(const wchar_t *pwszCommand) ////////////////////////////////////////////////////////////////////////////////////// // reading a new message +void CDiscordProto::OnCommandFriendAdded(const JSONNode &pRoot) +{ + CDiscordUser *pUser = PrepareUser(pRoot["user"]); + ProcessType(pUser, pRoot); +} + void CDiscordProto::OnCommandFriendRemoved(const JSONNode &pRoot) { SnowFlake id = _wtoi64(pRoot["id"].as_mstring()); diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 051095d8e8..f201306e9b 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -227,6 +227,7 @@ public: int __cdecl OnDbEventRead(WPARAM, LPARAM); // dispatch commands + void OnCommandFriendAdded(const JSONNode&); void OnCommandFriendRemoved(const JSONNode&); void OnCommandMessage(const JSONNode&); void OnCommandPresence(const JSONNode&); @@ -258,6 +259,7 @@ public: void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); // Misc + void ProcessType(CDiscordUser *pUser, const JSONNode&); void SetServerStatus(int iStatus); CMStringW GetAvatarFilename(MCONTACT hContact); diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 0b7c59fa9a..58742a63d4 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -112,35 +112,30 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques ptrW wszOldAvatar(getWStringA(hContact, DB_KEY_AVHASH)); - m_ownId = _wtoi64(root["id"].as_mstring()); - setId(hContact, DB_KEY_ID, m_ownId); + SnowFlake id = _wtoi64(root["id"].as_mstring()); + setId(hContact, DB_KEY_ID, id); setByte(hContact, DB_KEY_MFA, root["mfa_enabled"].as_bool()); setDword(hContact, DB_KEY_DISCR, _wtoi(root["discriminator"].as_mstring())); setWString(hContact, DB_KEY_NICK, root["username"].as_mstring()); setWString(hContact, DB_KEY_EMAIL, root["email"].as_mstring()); - switch (root["type"].as_int()) { - case 1: // confirmed - db_unset(hContact, "CList", "NotOnList"); - break; - - case 3: // expecting autorization - db_set_b(hContact, "CList", "NotOnList", 1); - break; - } - - 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); + } } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index ac9eb85c11..4d1747c3f9 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -179,3 +179,31 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user) setWString(pUser->hContact, DB_KEY_AVHASH, avatar); return pUser; } + +///////////////////////////////////////////////////////////////////////////////////////// + +void CDiscordProto::ProcessType(CDiscordUser *pUser, const JSONNode &pRoot) +{ + switch (pRoot["type"].as_int()) { + case 1: // confirmed + db_unset(pUser->hContact, "CList", "NotOnList"); + delSetting(pUser->hContact, "FakeAuth"); + break; + + case 3: // expecting authorization + db_set_b(pUser->hContact, "CList", "NotOnList", 1); + if (!getByte(pUser->hContact, "FakeAuth", 0)) { + setByte(pUser->hContact, "FakeAuth", 1); + + CMStringA szId(FORMAT, "%lld", pUser->id); + DB_AUTH_BLOB blob(pUser->hContact, T2Utf(pUser->wszUsername), NULL, NULL, szId, NULL); + + PROTORECVEVENT pre = { 0 }; + pre.timestamp = (DWORD)time(NULL); + pre.lParam = blob.size(); + pre.szMessage = blob; + ProtoChainRecv(pUser->hContact, PSR_AUTH, 0, (LPARAM)&pre); + } + break; + } +} |