From 51cb1a0a2101fc6d7b8376f5d07adbede24f56a9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 26 Jan 2017 17:37:16 +0300 Subject: fix of marking unread events as read --- protocols/Discord/src/dispatch.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'protocols/Discord/src/dispatch.cpp') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 3afa2f7a1c..6662163301 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -274,6 +274,17 @@ static void __stdcall sttStartTimer(void *param) SetTimer(g_hwndHeartbeat, (UINT_PTR)param, ppro->getHeartbeatInterval(), &CDiscordProto::HeartbeatTimerProc); } +static SnowFlake sttGetLastRead(const JSONNode &reads, const wchar_t *wszChannelId) +{ + for (auto it = reads.begin(); it != reads.end(); ++it) { + const JSONNode &p = *it; + + if (p["id"].as_mstring() == wszChannelId) + return _wtoi64(p["last_message_id"].as_mstring()); + } + return 0; +} + void CDiscordProto::OnCommandReady(const JSONNode &pRoot) { GatewaySendHeartbeat(); @@ -281,6 +292,8 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) m_szGatewaySessionId = pRoot["session_id"].as_mstring(); + const JSONNode &readState = pRoot["read_state"]; + const JSONNode &guilds = pRoot["guilds"]; for (auto it = guilds.begin(); it != guilds.end(); ++it) { const JSONNode &p = *it; @@ -320,6 +333,7 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) pUser->wszUsername = wszChannelId; pUser->guildId = guildId; pUser->lastMessageId = _wtoi64(pch["last_message_id"].as_mstring()); + pUser->lastReadId = sttGetLastRead(readState, wszChannelId); setId(pUser->hContact, DB_KEY_CHANNELID, channelId); } @@ -344,9 +358,11 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) if (pUser == NULL) continue; - - pUser->channelId = _wtoi64(p["id"].as_mstring()); + + CMStringW wszChannelId = p["id"].as_mstring(); + pUser->channelId = _wtoi64(wszChannelId); pUser->lastMessageId = _wtoi64(p["last_message_id"].as_mstring()); + pUser->lastReadId = sttGetLastRead(readState, wszChannelId); pUser->bIsPrivate = true; setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId); -- cgit v1.2.3