From d3f0c4ded55a510ebaf7f609e33146a8ec08a4d9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 20 May 2024 22:12:35 +0300 Subject: =?UTF-8?q?fixes=20#4415=20(Telegram:=20=D0=B7=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B0=20=D0=B2=D0=BE=20=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D1=8F=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.h | 4 +--- protocols/Telegram/src/server.cpp | 46 +++++++++++++++------------------------ 2 files changed, 18 insertions(+), 32 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 76c6c5d3d0..8466083bae 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -4,7 +4,6 @@ #define DBKEY_COMPAT "Compatibility" #define DBKEY_OWNER "OwnerId" #define DBKEY_THREAD "ThreadId" -#define DBKEY_LAST_MSG "LastMessageId" #define DBKEY_AUTHORIZED "Authorized" #define DBKEY_AVATAR_HASH "AvatarHash" @@ -101,7 +100,7 @@ struct TG_USER : public MZeroedObject int64_t id, chatId = -1; MCONTACT hContact; - int folderId = -1; + int folderId = -1, nHistoryChunks; bool isGroupChat, isBot, isForum, bLoadMembers, bStartChat, bInited; CMStringA szAvatarHash; CMStringW wszNick, wszFirstName, wszLastName; @@ -233,7 +232,6 @@ class CTelegramProto : public PROTO void OnEndSession(td::ClientManager::Response &response); void OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo); void OnGetFileLink(td::ClientManager::Response &response); - void OnGetForumTopics(td::ClientManager::Response &response); void OnGetHistory(td::ClientManager::Response &response, void *pUserInfo); void OnGetSessions(td::ClientManager::Response &response, void *pUserInfo); void OnKillSession(td::ClientManager::Response &response, void *pUserInfo); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 02582fa653..0568151f6d 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -459,27 +459,39 @@ void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *p db_event_add(GetRealContact(pUser), &dbei); } + pUser->nHistoryChunks--; + if (pUser->isForum) { - if (lastMsgId != INT64_MAX) + 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) + else if (lastMsgId != INT64_MAX && pUser->nHistoryChunks > 0) 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); + } + if (TD::int53 threadId = GetId(hContact, DBKEY_THREAD)) { auto chatId = GetId(hContact); auto *pUser = new TG_USER(-1, hContact, true); pUser->chatId = chatId; pUser->isForum = pUser->isGroupChat = true; - SendQuery(new TD::getMessageThreadHistory(chatId, GetId(hContact, DBKEY_LAST_MSG), 0, 0, 100), &CTelegramProto::OnGetHistory, pUser); + pUser->nHistoryChunks = 5; + SendQuery(new TD::getMessageThreadHistory(chatId, lastMsgId, lastMsgId, 0, 100), &CTelegramProto::OnGetHistory, pUser); + } + else if (auto *pUser = FindUser(GetId(hContact))) { + pUser->nHistoryChunks = 5; + SendQuery(new TD::getChatHistory(pUser->chatId, lastMsgId, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); } - else if (auto *pUser = FindUser(GetId(hContact))) - SendQuery(new TD::getChatHistory(pUser->chatId, 0, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); return 0; } @@ -498,28 +510,6 @@ INT_PTR CTelegramProto::SvcEmptyServerHistory(WPARAM hContact, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////// -void CTelegramProto::OnGetForumTopics(td::ClientManager::Response &response) -{ - if (!response.object) - return; - - if (response.object->get_id() != TD::forumTopics::ID) { - debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::forumTopics::ID); - return; - } - - auto *topics = (TD::forumTopics *)response.object.get(); - for (auto &it : topics->topics_) { - auto *pMessage = it->last_message_.get(); - if (!pMessage) - continue; - - CMStringW wszChatId(FORMAT, L"%lld_%lld", pMessage->chat_id_, it->info_->message_thread_id_); - if (auto *si = Chat_Find(wszChatId, m_szModuleName)) - SetId(si->hContact, pMessage->id_, DBKEY_LAST_MSG); - } -} - void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) { int64_t userId; @@ -554,8 +544,6 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) } pUser->chatId = pChat->id_; - if (pUser->isForum) - SendQuery(new TD::getForumTopics(pChat->id_, "", 0, 0, 0, 100), &CTelegramProto::OnGetForumTopics); MCONTACT hContact = (pUser->id == m_iOwnId) ? 0 : pUser->hContact; -- cgit v1.2.3