summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-09 17:53:21 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-09 17:53:21 +0300
commit86e49c1f6a1f4b978fd700590747c1a03ff7d156 (patch)
tree4e6791ebcdc1fd260c8436656a6c2a6e1d743b63
parent3cc643812de9ad33f411ad936183d447be4fe51a (diff)
fix for duplicated messages when reading history
-rw-r--r--protocols/Discord/src/dispatch.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 307394c8ca..0cb74c06a3 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -82,6 +82,10 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
recv.szMessage = buf;
recv.lParam = (LPARAM)msgId.c_str();
ProtoChainRecvMsg(pUser->hContact, &recv);
+
+ SnowFlake lastId = getId(pUser->hContact, DB_KEY_LASTMSGID); // as stored in a database
+ if (lastId < _wtoi64(msgId))
+ setId(pUser->hContact, DB_KEY_LASTMSGID, _wtoi64(msgId));
}
//////////////////////////////////////////////////////////////////////////////////////
@@ -148,20 +152,23 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot)
for (auto it = channels.begin(); it != channels.end(); ++it) {
const JSONNode &p = *it;
+ CDiscordUser *pUser = NULL;
const JSONNode &recipients = p["recipients"];
- for (auto it2 = recipients.begin(); it2 != recipients.end(); ++it2) {
- const JSONNode &r = *it2;
- CDiscordUser *pUser = PrepareUser(r);
- pUser->lastMessageId = _wtoi64(r["last_message_id"].as_mstring());
- pUser->channelId = _wtoi64(p["id"].as_mstring());
- pUser->bIsPrivate = true;
-
- setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
-
- SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID);
- if (pUser->lastMessageId > oldMsgId)
- RetrieveHistory(pUser->hContact, MSG_AFTER, oldMsgId);
- }
+ for (auto it2 = recipients.begin(); it2 != recipients.end(); ++it2)
+ pUser = PrepareUser(*it2);
+
+ if (pUser == NULL)
+ continue;
+
+ pUser->channelId = _wtoi64(p["id"].as_mstring());
+ pUser->lastMessageId = _wtoi64(p["last_message_id"].as_mstring());
+ pUser->bIsPrivate = true;
+
+ setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
+
+ SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID);
+ if (pUser->lastMessageId > oldMsgId)
+ RetrieveHistory(pUser->hContact, MSG_AFTER, oldMsgId);
}
}