From 5732a19c7dd15ee2a70fb30b3b27db9514208d2f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 7 Aug 2024 17:19:37 +0300 Subject: =?UTF-8?q?fixes=20#4542=20(SkypeWeb:=20Load=20Server=20History=20?= =?UTF-8?q?=D0=B2=D1=82=D1=8F=D0=B3=D0=B8=D0=B2=D0=B0=D0=B5=D1=82=20=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=BE=20=D1=81=D0=B2=D0=B5=D0=B6=D0=B8=D1=85?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9,=20?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B5=20=D0=B2=D1=81=D1=8E=20=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D1=8E)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/SkypeWeb/src/skype_history_sync.cpp | 62 +++++++++------------------ 1 file changed, 20 insertions(+), 42 deletions(-) (limited to 'protocols/SkypeWeb/src/skype_history_sync.cpp') diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 294800d304..a1e86c777b 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -25,6 +25,7 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * if (reply.error()) return; + auto *pOrig = (GetHistoryRequest *)pRequest; auto &root = reply.data(); const JSONNode &metadata = root["_metadata"]; @@ -33,7 +34,9 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * bool markAllAsUnread = getBool("MarkMesUnread", true); bool bUseLocalTime = !bUseServerTime && pRequest->pUserInfo != 0; - uint32_t lastMsgTime = 0; + bool bSetLastTime = false; + + int64_t lastMsgTime = 0; // max timestamp on this page time_t iLocalTime = time(0); auto &conv = root["messages"]; @@ -47,24 +50,19 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * MCONTACT hContact = FindContact(szChatId); - time_t timestamp = IsoToUnixTime(message["composetime"].as_string()); - if (timestamp > getDword(hContact, "LastMsgTime", 0)) - setDword(hContact, "LastMsgTime", timestamp); - DB::EventInfo dbei(db_event_getById(m_szModuleName, szMessageId)); dbei.hContact = hContact; dbei.szModule = m_szModuleName; - dbei.timestamp = timestamp; + dbei.timestamp = (bUseLocalTime) ? iLocalTime : IsoToUnixTime(message["composetime"].as_string()); dbei.szId = szMessageId; if (iUserType == 19) dbei.szUserId = szFrom; - uint32_t id = message["id"].as_int(); - if (id > lastMsgTime) + int64_t id = _atoi64(message["id"].as_string().c_str()); + if (id > lastMsgTime) { + bSetLastTime = true; lastMsgTime = id; - - if (bUseLocalTime) - timestamp = iLocalTime; + } dbei.flags = DBEF_UTF; if (!markAllAsUnread) @@ -80,37 +78,20 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * } } - if (totalCount >= 99 || conv.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)); - } - } -} + if (bSetLastTime && lastMsgTime > getLastTime(pOrig->hContact)) + setLastTime(pOrig->hContact, lastMsgTime); -void CSkypeProto::ReadHistoryRest(const char *szUrl) -{ - auto *p = strstr(szUrl, g_plugin.szDefaultServer); - if (p) - PushRequest(new SyncHistoryFirstRequest(p+ g_plugin.szDefaultServer.GetLength()+3)); + if (totalCount >= 99 || conv.size() >= 99) + PushRequest(new GetHistoryRequest(pOrig->hContact, pOrig->m_who, 100, lastMsgTime, pRequest->pUserInfo != 0)); } INT_PTR CSkypeProto::SvcLoadHistory(WPARAM hContact, LPARAM) { - PushRequest(new GetHistoryRequest(getId(hContact), 100, 0, false)); + PushRequest(new GetHistoryRequest(hContact, getId(hContact), 100, 0, false)); return 0; } -void CSkypeProto::OnSyncHistory(MHttpResponse *response, AsyncHttpRequest*) +void CSkypeProto::OnSyncConversations(MHttpResponse *response, AsyncHttpRequest*) { JsonReply reply(response); if (reply.error()) @@ -120,12 +101,9 @@ void CSkypeProto::OnSyncHistory(MHttpResponse *response, AsyncHttpRequest*) const JSONNode &metadata = root["_metadata"]; const JSONNode &conversations = root["conversations"].as_array(); - int totalCount = metadata["totalCount"].as_int(); + // int totalCount = metadata["totalCount"].as_int(); std::string syncState = metadata["syncState"].as_string(); - if (totalCount >= 99 || conversations.size() >= 99) - ReadHistoryRest(syncState.c_str()); - for (auto &conversation : conversations) { const JSONNode &lastMessage = conversation["lastMessage"]; if (!lastMessage) @@ -135,13 +113,13 @@ void CSkypeProto::OnSyncHistory(MHttpResponse *response, AsyncHttpRequest*) std::string strConversationLink = lastMessage["conversationLink"].as_string(); CMStringA szSkypename = UrlToSkypeId(strConversationLink.c_str(), &iUserType); if (iUserType == 8 || iUserType == 2) { - time_t composeTime(IsoToUnixTime(lastMessage["composetime"].as_string())); + int64_t id = _atoi64(lastMessage["id"].as_string().c_str()); MCONTACT hContact = FindContact(szSkypename); if (hContact != NULL) { - uint32_t lastMsgTime = getDword(hContact, "LastMsgTime", 0); - if (lastMsgTime && lastMsgTime < composeTime) - PushRequest(new GetHistoryRequest(szSkypename, 100, lastMsgTime, true)); + auto lastMsgTime = getLastTime(hContact); + if (lastMsgTime && lastMsgTime < id) + PushRequest(new GetHistoryRequest(hContact, szSkypename, 100, lastMsgTime, true)); } } } -- cgit v1.2.3