diff options
author | George Hazan <ghazan@miranda.im> | 2019-02-23 19:16:49 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-02-23 19:16:49 +0300 |
commit | 47e83290f474e01aa8e247375abcd2bffb9a2bf5 (patch) | |
tree | 5d301325e43a23dd56e11e11dfe9956eeb602b93 | |
parent | 691b1c649ab54ebfbb66eb3cba707b132b1134a8 (diff) |
fixes #1843 ([discord] Group chat history is no longer retrieved on login)
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 8 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 2 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 8 |
4 files changed, 11 insertions, 9 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index ab0e4e63b8..57b78c4df9 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -532,7 +532,7 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot) SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID); if (pUser->lastMsgId > oldMsgId) - RetrieveHistory(pUser->hContact, MSG_AFTER, oldMsgId, 99); + RetrieveHistory(pUser, MSG_AFTER, oldMsgId, 99); } const JSONNode &readState = pRoot["read_state"]; diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 843544f87b..76fafb1918 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -214,6 +214,12 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS pUser->lastMsgId = ::getId(pch["last_message_id"]); pUser->parentId = _wtoi64(pch["parent_id"].as_mstring()); + SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID); + if (oldMsgId == 0) + RetrieveHistory(pUser, MSG_BEFORE, pUser->lastMsgId, 20); + else if (pUser->lastMsgId > oldMsgId) + RetrieveHistory(pUser, MSG_AFTER, oldMsgId, 99); + setId(pUser->hContact, DB_KEY_ID, channelId); setId(pUser->hContact, DB_KEY_CHANNELID, channelId); return pUser; @@ -298,7 +304,7 @@ void CDiscordProto::ParseGuildContents(CDiscordGuild *pGuild, const JSONNode &pR SnowFlake oldMsgId = getId(it->hContact, DB_KEY_LASTMSGID); if (oldMsgId != 0 && it->lastMsgId > oldMsgId) - RetrieveHistory(it->hContact, MSG_AFTER, oldMsgId, 99); + RetrieveHistory(it, MSG_AFTER, oldMsgId, 99); } pGuild->bSynced = true; diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 88c8325efe..c11a7787a6 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -338,7 +338,7 @@ public: void RetrieveMyInfo(); void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void RetrieveHistory(MCONTACT hContact, CDiscordHistoryOp iOp = MSG_NOFILTER, SnowFlake msgid = 0, int iLimit = 50); + void RetrieveHistory(CDiscordUser *pUser, CDiscordHistoryOp iOp = MSG_NOFILTER, SnowFlake msgid = 0, int iLimit = 50); void OnReceiveHistory(NETLIBHTTPREQUEST*, AsyncHttpRequest*); bool RetrieveAvatar(MCONTACT hContact); diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 1dd9cd104a..f1d1db3a5e 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -28,12 +28,8 @@ void CDiscordProto::RemoveFriend(SnowFlake id) ///////////////////////////////////////////////////////////////////////////////////////// // retrieves server history -void CDiscordProto::RetrieveHistory(MCONTACT hContact, CDiscordHistoryOp iOp, SnowFlake msgid, int iLimit) +void CDiscordProto::RetrieveHistory(CDiscordUser *pUser, CDiscordHistoryOp iOp, SnowFlake msgid, int iLimit) { - CDiscordUser *pUser = FindUser(getId(hContact, DB_KEY_ID)); - if (pUser == nullptr) - return; - CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveHistory); pReq << INT_PARAM("limit", iLimit); @@ -138,7 +134,7 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest // if we fetched 99 messages, but have smth more to go, continue fetching if (iNumMessages == 99 && lastId < pUser->lastMsgId) - RetrieveHistory(pUser->hContact, MSG_AFTER, lastId, 99); + RetrieveHistory(pUser, MSG_AFTER, lastId, 99); } ///////////////////////////////////////////////////////////////////////////////////////// |