diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 30 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 12 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 7 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
5 files changed, 29 insertions, 23 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 17b7a28b98..b0f0719d60 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -70,15 +70,15 @@ void CDiscordProto::OnCommandChannelCreated(const JSONNode &pRoot) const JSONNode &members = pRoot["recipients"]; for (auto it = members.begin(); it != members.end(); ++it) { CDiscordUser *pUser = PrepareUser(*it); - pUser->lastMessageId = _wtoi64(pRoot["last_message_id"].as_mstring()); - pUser->channelId = _wtoi64(pRoot["id"].as_mstring()); + pUser->lastMessageId = ::getId(pRoot["last_message_id"]); + pUser->channelId = ::getId(pRoot["id"]); setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId); } } void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot) { - CDiscordUser *pUser = FindUserByChannel(_wtoi64(pRoot["id"].as_mstring())); + CDiscordUser *pUser = FindUserByChannel(::getId(pRoot["id"])); if (pUser != NULL) { pUser->channelId = pUser->lastMessageId = 0; delSetting(pUser->hContact, DB_KEY_CHANNELID); @@ -97,7 +97,7 @@ void CDiscordProto::OnCommandFriendAdded(const JSONNode &pRoot) void CDiscordProto::OnCommandFriendRemoved(const JSONNode &pRoot) { - SnowFlake id = _wtoi64(pRoot["id"].as_mstring()); + SnowFlake id = ::getId(pRoot["id"]); CDiscordUser *pUser = FindUser(id); if (pUser != NULL) { if (pUser->hContact) { @@ -128,7 +128,7 @@ void CDiscordProto::OnCommandGuildSync(const JSONNode &pRoot) { const JSONNode &pStatuses = pRoot["presences"]; - SnowFlake guildId = _wtoi64(pRoot["id"].as_mstring()); + SnowFlake guildId = ::getId(pRoot["id"]); const JSONNode &pMembers = pRoot["members"]; for (auto it = pMembers.begin(); it != pMembers.end(); ++it) { @@ -171,7 +171,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) PROTORECVEVENT recv = {}; CMStringW wszMessageId = pRoot["id"].as_mstring(); SnowFlake messageId = _wtoi64(wszMessageId); - SnowFlake nonce = _wtoi64(pRoot["nonce"].as_mstring()); + SnowFlake nonce = ::getId(pRoot["nonce"]); SnowFlake *p = arOwnMessages.find(&nonce); if (p != NULL) { // own message? skip it @@ -235,7 +235,7 @@ void CDiscordProto::OnCommandMessageAck(const JSONNode &pRoot) { CDiscordUser *pUser = FindUserByChannel(pRoot["channel_id"]); if (pUser != NULL) - pUser->lastMessageId = _wtoi64(pRoot["message_id"].as_mstring()); + pUser->lastMessageId = ::getId(pRoot["message_id"]); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -243,7 +243,7 @@ void CDiscordProto::OnCommandMessageAck(const JSONNode &pRoot) void CDiscordProto::OnCommandPresence(const JSONNode &pRoot) { - CDiscordUser *pUser = FindUser(_wtoi64(pRoot["user"]["id"].as_mstring())); + CDiscordUser *pUser = FindUser(::getId(pRoot["user"]["id"])); if (pUser == NULL) return; @@ -278,7 +278,7 @@ static SnowFlake sttGetLastRead(const JSONNode &reads, const wchar_t *wszChannel const JSONNode &p = *it; if (p["id"].as_mstring() == wszChannelId) - return _wtoi64(p["last_message_id"].as_mstring()); + return ::getId(p["last_message_id"]); } return 0; } @@ -297,7 +297,7 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) for (auto it = guilds.begin(); it != guilds.end(); ++it) { const JSONNode &p = *it; - SnowFlake guildId = _wtoi64(p["id"].as_mstring()); + SnowFlake guildId = ::getId(p["id"]); GatewaySendGuildInfo(guildId); CMStringW wszGuildName = p["name"].as_mstring(); @@ -331,7 +331,7 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) } pUser->wszUsername = wszChannelId; pUser->guildId = guildId; - pUser->lastMessageId = _wtoi64(pch["last_message_id"].as_mstring()); + pUser->lastMessageId = ::getId(pch["last_message_id"]); pUser->lastReadId = sttGetLastRead(readState, wszChannelId); setId(pUser->hContact, DB_KEY_CHANNELID, channelId); @@ -364,7 +364,7 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) CMStringW wszChannelId = p["id"].as_mstring(); pUser->channelId = _wtoi64(wszChannelId); - pUser->lastMessageId = _wtoi64(p["last_message_id"].as_mstring()); + pUser->lastMessageId = ::getId(p["last_message_id"]); pUser->lastReadId = sttGetLastRead(readState, wszChannelId); pUser->bIsPrivate = true; @@ -381,8 +381,8 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) void CDiscordProto::OnCommandTyping(const JSONNode &pRoot) { - SnowFlake userId = _wtoi64(pRoot["user_id"].as_mstring()); - SnowFlake channelId = _wtoi64(pRoot["channel_id"].as_mstring()); + SnowFlake userId = ::getId(pRoot["user_id"]); + SnowFlake channelId = ::getId(pRoot["channel_id"]); debugLogA("user typing notification: userid=%lld, channelid=%lld", userId, channelId); CDiscordUser *pUser = FindUser(userId); @@ -405,7 +405,7 @@ void CDiscordProto::OnCommandTyping(const JSONNode &pRoot) void CDiscordProto::OnCommandUserUpdate(const JSONNode &pRoot) { - SnowFlake id = _wtoi64(pRoot["id"].as_mstring()); + SnowFlake id = ::getId(pRoot["id"]); MCONTACT hContact; if (id != m_ownId) { diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 203380c994..0a55c78de0 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -80,13 +80,13 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest for (int i = 0; i < arNodes.getCount(); i++) { JSONNode &p = *arNodes[i]; - SnowFlake authorid = _wtoi64(p["author"]["id"].as_mstring()); + SnowFlake authorid = ::getId(p["author"]["id"]); if (authorid == m_ownId) dbei.flags |= DBEF_SENT; else dbei.flags &= ~DBEF_SENT; - SnowFlake msgid = _wtoi64(p["id"].as_mstring()); + SnowFlake msgid = ::getId(p["id"]); if (msgid <= pUser->lastReadId) dbei.flags |= DBEF_READ; else @@ -147,7 +147,7 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques return; } - SnowFlake id = _wtoi64(root["id"].as_mstring()); + SnowFlake id = ::getId(root["id"]); setId(hContact, DB_KEY_ID, id); setByte(hContact, DB_KEY_MFA, root["mfa_enabled"].as_bool()); @@ -249,8 +249,8 @@ void CDiscordProto::OnReceiveChannels(NETLIBHTTPREQUEST *pReply, AsyncHttpReques continue; CDiscordUser *pUser = PrepareUser(user); - pUser->lastMessageId = _wtoi64(p["last_message_id"].as_mstring()); - pUser->channelId = _wtoi64(p["id"].as_mstring()); + pUser->lastMessageId = ::getId(p["last_message_id"]); + pUser->channelId = ::getId(p["id"]); pUser->bIsPrivate = p["is_private"].as_bool(); setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId); @@ -297,7 +297,7 @@ void CDiscordProto::OnReceiveMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest JSONNode root = JSONNode::parse(pReply->pData); if (root) { - SnowFlake newLastId = _wtoi64(root["id"].as_mstring()); + SnowFlake newLastId = ::getId(root["id"]); SnowFlake oldLastId = getId(hContact, DB_KEY_LASTMSGID); // as stored in a database if (oldLastId < newLastId) setId(hContact, DB_KEY_LASTMSGID, newLastId); diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 01f35bfb35..dd468dbd87 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -64,6 +64,7 @@ extern HWND g_hwndHeartbeat; #define DB_KEY_GROUP "GroupName" #define DB_KEYVAL_GROUP L"Discord" +SnowFlake getId(const JSONNode &pNode); CMStringW PrepareMessageText(const JSONNode &pRoot); int StrToStatus(const CMStringW &str); time_t StringToDate(const CMStringW &str); diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 8a2041c534..f84ecfb61a 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -100,6 +100,11 @@ int SerialNext() ///////////////////////////////////////////////////////////////////////////////////////// +SnowFlake getId(const JSONNode &pNode) +{ + return _wtoi64(pNode.as_mstring()); +} + SnowFlake CDiscordProto::getId(const char *szSetting) { DBVARIANT dbv; @@ -167,7 +172,7 @@ CDiscordUser* CDiscordProto::FindUserByChannel(SnowFlake channelId) CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user) { - SnowFlake id = _wtoi64(user["id"].as_mstring()); + SnowFlake id = ::getId(user["id"]); if (id == m_ownId) return g_myUser; diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index cd73918a4b..7953ebf230 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 #define __RELEASE_NUM 0 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include <stdver.h> |