From ed4141e5d48402b8b617e6ae360ae41464723b0c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 23 Dec 2020 21:03:01 +0300 Subject: SkypeWeb: history reader to use local time not to create time machine. Only fetching whole history shall use server side timestamps --- protocols/SkypeWeb/src/requests/history.h | 11 ++++++----- protocols/SkypeWeb/src/skype_chatrooms.cpp | 2 +- protocols/SkypeWeb/src/skype_history_sync.cpp | 24 ++++++++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/protocols/SkypeWeb/src/requests/history.h b/protocols/SkypeWeb/src/requests/history.h index 6be005ae57..7c5baf6870 100644 --- a/protocols/SkypeWeb/src/requests/history.h +++ b/protocols/SkypeWeb/src/requests/history.h @@ -35,21 +35,22 @@ struct SyncHistoryFirstRequest : public AsyncHttpRequest struct GetHistoryRequest : public AsyncHttpRequest { - GetHistoryRequest(const char *username, int pageSize, LONGLONG timestamp) : + GetHistoryRequest(const char *username, int pageSize, LONGLONG timestamp, bool bOperative) : AsyncHttpRequest(REQUEST_GET, HOST_DEFAULT, 0, &CSkypeProto::OnGetServerHistory) { m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", mir_urlEncode(username).c_str()); + if (bOperative) + pUserInfo = this; + this << INT_PARAM("startTime", timestamp) << INT_PARAM("pageSize", pageSize) << CHAR_PARAM("view", "msnp24Equivalent") << CHAR_PARAM("targetType", "Passport|Skype|Lync|Thread"); } -}; -struct GetHistoryOnUrlRequest : public AsyncHttpRequest -{ - GetHistoryOnUrlRequest(const char *url) : + GetHistoryRequest(const char *url, void *pInfo) : AsyncHttpRequest(REQUEST_GET, HOST_DEFAULT, url, &CSkypeProto::OnGetServerHistory) { + pUserInfo = pInfo; } }; diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 080edd1abb..8cc0b39393 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -406,7 +406,7 @@ void CSkypeProto::OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) AddChatContact(si, username, role, true); } - PushRequest(new GetHistoryRequest(_T2A(si->ptszID), true, 0)); + PushRequest(new GetHistoryRequest(T2Utf(si->ptszID), 100, 0, true)); } wchar_t* CSkypeProto::GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name) diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 60ecb06cf4..57b46c92cc 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -19,7 +19,7 @@ along with this program. If not, see . /* HISTORY SYNC */ -void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) +void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest) { JsonReply reply(response); if (reply.error()) @@ -33,9 +33,11 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque std::string syncState = metadata["syncState"].as_string(); bool markAllAsUnread = getBool("MarkMesUnread", true); + bool bUseLocalTime = pRequest->pUserInfo != 0; + time_t iLocalTime = time(0); if (totalCount >= 99 || conversations.size() >= 99) - PushRequest(new GetHistoryOnUrlRequest(syncState.c_str())); + PushRequest(new GetHistoryRequest(syncState.c_str(), pRequest->pUserInfo)); for (int i = (int)conversations.size(); i >= 0; i--) { const JSONNode &message = conversations.at(i); @@ -57,16 +59,18 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque if (timestamp > getDword(hContact, "LastMsgTime", 0)) setDword(hContact, "LastMsgTime", timestamp); + if (bUseLocalTime) + timestamp = iLocalTime; - DWORD iFlags = DBEF_UTF; + if (userType == 8 || userType == 2) { + DWORD iFlags = DBEF_UTF; - if (!markAllAsUnread) - iFlags |= DBEF_READ; + if (!markAllAsUnread) + iFlags |= DBEF_READ; - if (IsMe(wszFrom)) - iFlags |= DBEF_SENT; + if (IsMe(wszFrom)) + iFlags |= DBEF_SENT; - if (userType == 8 || userType == 2) { if (messageType == "Text" || messageType == "RichText") { CMStringW szMessage(messageType == "RichText" ? RemoveHtml(wszContent) : wszContent); MEVENT dbevent = GetMessageFromDb(szMessageId); @@ -114,7 +118,7 @@ void CSkypeProto::ReadHistoryRest(const char *szUrl) INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM) { - PushRequest(new GetHistoryRequest(getId(hContact), 100, 0)); + PushRequest(new GetHistoryRequest(getId(hContact), 100, 0, false)); return 0; } @@ -148,7 +152,7 @@ void CSkypeProto::OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) MCONTACT hContact = FindContact(szSkypename); if (hContact != NULL) if (getDword(hContact, "LastMsgTime", 0) < composeTime) - PushRequest(new GetHistoryRequest(szSkypename, 100, 0)); + PushRequest(new GetHistoryRequest(szSkypename, 100, 0, true)); } } -- cgit v1.2.3