From a06f77c54ea9c5600ffbcf996cd0ce27b6326128 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 30 Aug 2021 11:56:23 +0300 Subject: fixes #2588 (SkypeWeb: server history loading loads only the last 100 messages) --- protocols/SkypeWeb/src/requests/history.h | 4 +-- protocols/SkypeWeb/src/skype_history_sync.cpp | 38 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) (limited to 'protocols/SkypeWeb/src') diff --git a/protocols/SkypeWeb/src/requests/history.h b/protocols/SkypeWeb/src/requests/history.h index 008cd2cd2e..d6a6726dc2 100644 --- a/protocols/SkypeWeb/src/requests/history.h +++ b/protocols/SkypeWeb/src/requests/history.h @@ -35,7 +35,7 @@ struct SyncHistoryFirstRequest : public AsyncHttpRequest struct GetHistoryRequest : public AsyncHttpRequest { - GetHistoryRequest(const char *username, int pageSize, LONGLONG timestamp, bool bOperative) : + GetHistoryRequest(const char *username, int pageSize, DWORD timestamp, bool bOperative) : AsyncHttpRequest(REQUEST_GET, HOST_DEFAULT, 0, &CSkypeProto::OnGetServerHistory) { m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", mir_urlEncode(username).c_str()); @@ -54,4 +54,4 @@ struct GetHistoryRequest : public AsyncHttpRequest } }; -#endif //_SKYPE_REQUEST_HISTORY_H_ \ No newline at end of file +#endif //_SKYPE_REQUEST_HISTORY_H_ diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 550cb7fb69..f7133ff8c7 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -34,11 +34,9 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque bool markAllAsUnread = getBool("MarkMesUnread", true); bool bUseLocalTime = !bUseServerTime && pRequest->pUserInfo != 0; + DWORD lastMsgTime = 0; time_t iLocalTime = time(0); - if (totalCount >= 99 || conversations.size() >= 99) - PushRequest(new GetHistoryRequest(syncState.c_str(), pRequest->pUserInfo)); - for (int i = (int)conversations.size(); i >= 0; i--) { const JSONNode &message = conversations.at(i); @@ -49,16 +47,20 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque CMStringW wszContent = message["content"].as_mstring(); CMStringW wszFrom = UrlToSkypeId(message["from"].as_mstring()); + MCONTACT hContact = FindContact(wszChatId); std::string messageType = message["messagetype"].as_string(); int emoteOffset = message["skypeemoteoffset"].as_int(); + time_t timestamp = IsoToUnixTime(message["composetime"].as_string()); + if (timestamp > getDword(hContact, "LastMsgTime", 0)) + setDword(hContact, "LastMsgTime", timestamp); bool isEdited = message["skypeeditedid"]; - MCONTACT hContact = FindContact(wszChatId); + DWORD id = message["id"].as_int(); + if (id > lastMsgTime) + lastMsgTime = id; - if (timestamp > getDword(hContact, "LastMsgTime", 0)) - setDword(hContact, "LastMsgTime", timestamp); if (bUseLocalTime) timestamp = iLocalTime; @@ -107,6 +109,22 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque AddMessageToChat(si, wszFrom, messageType == "RichText" ? RemoveHtml(wszContent) : wszContent, emoteOffset != NULL, emoteOffset, timestamp, true); } } + + if (totalCount >= 99 || conversations.size() >= 99) { + CMStringA szUrl(pRequest->m_szUrl); + int i1 = szUrl.Find("startTime="); + int i2 = szUrl.Find("&", i1); + if (i1 != -1 && i2 != -1) { + i1 += 10; + szUrl.Delete(i1, i2 - i1); + + char buf[100]; + itoa(lastMsgTime, buf, sizeof(buf)); + szUrl.Insert(i1, buf); + + PushRequest(new GetHistoryRequest(szUrl, pRequest->pUserInfo)); + } + } } void CSkypeProto::ReadHistoryRest(const char *szUrl) @@ -150,9 +168,11 @@ void CSkypeProto::OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) time_t composeTime(IsoToUnixTime(lastMessage["composetime"].as_string())); MCONTACT hContact = FindContact(szSkypename); - if (hContact != NULL) - if (getDword(hContact, "LastMsgTime", 0) < composeTime) - PushRequest(new GetHistoryRequest(szSkypename, 100, 0, true)); + if (hContact != NULL) { + DWORD lastMsgTime = getDword(hContact, "LastMsgTime", 0); + if (lastMsgTime && lastMsgTime < composeTime) + PushRequest(new GetHistoryRequest(szSkypename, 100, lastMsgTime, true)); + } } } -- cgit v1.2.3