diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-26 17:37:16 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-26 17:37:16 +0300 |
commit | 51cb1a0a2101fc6d7b8376f5d07adbede24f56a9 (patch) | |
tree | 26b2251fe405475cda53bf50b5f826652c4f3397 /protocols/Discord/src/dispatch.cpp | |
parent | 3ac978c8338af177cde02e5c1c1d285170027d82 (diff) |
fix of marking unread events as read
Diffstat (limited to 'protocols/Discord/src/dispatch.cpp')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
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); |