diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 21 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 19 |
3 files changed, 26 insertions, 15 deletions
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 52f9104107..8b43d85aeb 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -30,6 +30,7 @@ public: JsonReply(NETLIBHTTPREQUEST *); ~JsonReply(); + __forceinline int error() const { return m_errorCode; } __forceinline JSONNode& data() const { return *m_root; } __forceinline operator bool() const { return m_errorCode == 200; } }; diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 54ef51fe7d..37cd89304c 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -30,14 +30,20 @@ void CDiscordProto::RemoveFriend(SnowFlake id) void CDiscordProto::RetrieveHistory(CDiscordUser *pUser, CDiscordHistoryOp iOp, SnowFlake msgid, int iLimit) { + if (!pUser->hContact || getByte(pUser->hContact, DB_KEY_DONT_FETCH)) + return; + CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveHistory); pReq << INT_PARAM("limit", iLimit); - switch (iOp) { - case MSG_AFTER: - pReq << INT64_PARAM("after", msgid); break; - case MSG_BEFORE: - pReq << INT64_PARAM("before", msgid); break; + + if (msgid) { + switch (iOp) { + case MSG_AFTER: + pReq << INT64_PARAM("after", msgid); break; + case MSG_BEFORE: + pReq << INT64_PARAM("before", msgid); break; + } } pReq->pUserInfo = pUser; Push(pReq); @@ -53,8 +59,11 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest CDiscordUser *pUser = (CDiscordUser*)pReq->pUserInfo; JsonReply root(pReply); - if (!root) + if (!root) { + if (root.error() == 403) // forbidden, don't try to read it anymore + setByte(pUser->hContact, DB_KEY_DONT_FETCH, true); return; + } SESSION_INFO *si = nullptr; if (!pUser->bIsPrivate) { diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index acf9ec0dfc..9d3951a4e9 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -53,15 +53,16 @@ extern IconItem g_iconList[]; -#define DB_KEY_ID "id" -#define DB_KEY_PASSWORD "Password" -#define DB_KEY_DISCR "Discriminator" -#define DB_KEY_MFA "MfaEnabled" -#define DB_KEY_NICK "Nick" -#define DB_KEY_AVHASH "AvatarHash" -#define DB_KEY_CHANNELID "ChannelID" -#define DB_KEY_LASTMSGID "LastMessageID" -#define DB_KEY_REQAUTH "ReqAuth" +#define DB_KEY_ID "id" +#define DB_KEY_PASSWORD "Password" +#define DB_KEY_DISCR "Discriminator" +#define DB_KEY_MFA "MfaEnabled" +#define DB_KEY_NICK "Nick" +#define DB_KEY_AVHASH "AvatarHash" +#define DB_KEY_CHANNELID "ChannelID" +#define DB_KEY_LASTMSGID "LastMessageID" +#define DB_KEY_REQAUTH "ReqAuth" +#define DB_KEY_DONT_FETCH "DontFetch" #define DB_KEYVAL_GROUP L"Discord" |