From 0f43b99e7dbdeaa8cba7d2c17415782f0f9b7cb3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 2 Apr 2025 19:50:28 +0300 Subject: =?UTF-8?q?fixes=20#4941=20(Telegram:=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=BE=D0=B5=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=81=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/server.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'protocols/Telegram/src/server.cpp') diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index e3f82dcd5b..4e783c06a6 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -456,6 +456,12 @@ void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *p auto *pUser = (TG_USER *)pUserInfo; TD::int53 lastMsgId = INT64_MAX; auto *pMessages = (TD::messages *)response.object.get(); + if (pMessages->messages_.size() == 0) { + if (pUser->isForum) + delete pUser; + return; + } + for (auto &it : pMessages->messages_) { auto *pMsg = it.get(); if (pMsg->id_ < lastMsgId) @@ -489,27 +495,15 @@ void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *p db_event_add(GetRealContact(pUser), &dbei); } - pUser->nHistoryChunks--; - - if (pUser->isForum) { - if (lastMsgId != INT64_MAX && pUser->nHistoryChunks > 0) - SendQuery(new TD::getMessageThreadHistory(pUser->chatId, lastMsgId, lastMsgId, 0, 100), &CTelegramProto::OnGetHistory, pUser); - else - delete pUser; - } - else if (lastMsgId != INT64_MAX && pUser->nHistoryChunks > 0) + // fetch next portion + if (pUser->isForum) + SendQuery(new TD::getMessageThreadHistory(pUser->chatId, lastMsgId, lastMsgId, 0, 100), &CTelegramProto::OnGetHistory, pUser); + else SendQuery(new TD::getChatHistory(pUser->chatId, lastMsgId, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); } INT_PTR CTelegramProto::SvcLoadServerHistory(WPARAM hContact, LPARAM) { - TD::int53 lastMsgId = 0; - - if (MEVENT hEvent = db_event_first(hContact)) { - DB::EventInfo dbei(hEvent, false); - lastMsgId = dbei2id(dbei); - } - auto userId = GetId(hContact); if (TD::int53 threadId = GetId(hContact, DBKEY_THREAD)) { @@ -517,16 +511,13 @@ INT_PTR CTelegramProto::SvcLoadServerHistory(WPARAM hContact, LPARAM) auto *pUser = new TG_USER(-1, hContact, true); pUser->chatId = userId; pUser->isForum = pUser->isGroupChat = true; - pUser->nHistoryChunks = 5; - SendQuery(new TD::getMessageThreadHistory(pUser->chatId, lastMsgId, lastMsgId, 0, 100), &CTelegramProto::OnGetHistory, pUser); + SendQuery(new TD::getMessageThreadHistory(pUser->chatId, 0, 0, 0, 100), &CTelegramProto::OnGetHistory, pUser); return 0; } } - if (auto *pUser = FindUser(userId)) { - pUser->nHistoryChunks = 5; - SendQuery(new TD::getChatHistory(pUser->chatId, lastMsgId, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); - } + if (auto *pUser = FindUser(userId)) + SendQuery(new TD::getChatHistory(pUser->chatId, 0, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); return 0; } -- cgit v1.2.3