From d8c9835b36be01fbd5584f52a1ee1c1ba66b61b0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 25 Mar 2024 20:01:18 +0300 Subject: =?UTF-8?q?fixes=20#4300=20(Telegram:=20=D0=BD=D0=B5=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D1=91=D1=82=D1=81=D1=8F=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=B8=D1=82=D1=8C=20=D0=B8=D1=81=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=83=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.h | 2 ++ protocols/Telegram/src/server.cpp | 42 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 141a2d3034..d7c6587c70 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -3,6 +3,7 @@ #define DBKEY_ID "id" #define DBKEY_COMPAT "Compatibility" #define DBKEY_THREAD "ThreadId" +#define DBKEY_LAST_MSG "LastMessageId" #define DBKEY_AUTHORIZED "Authorized" #define DBKEY_AVATAR_HASH "AvatarHash" @@ -231,6 +232,7 @@ 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 1460fb63b1..f9ed581e50 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -443,14 +443,28 @@ void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *p db_event_add(GetRealContact(pUser), &dbei); } - if (lastMsgId != INT64_MAX) + if (pUser->isForum) { + if (lastMsgId != INT64_MAX) + SendQuery(new TD::getMessageThreadHistory(pUser->chatId, lastMsgId, lastMsgId, 0, 100), &CTelegramProto::OnGetHistory, pUser); + else + delete pUser; + } + else if (lastMsgId != INT64_MAX) SendQuery(new TD::getChatHistory(pUser->chatId, lastMsgId, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); } INT_PTR CTelegramProto::SvcLoadServerHistory(WPARAM hContact, LPARAM) { - if (auto *pUser = FindUser(GetId(hContact))) + 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); + } + else if (auto *pUser = FindUser(GetId(hContact))) SendQuery(new TD::getChatHistory(pUser->chatId, 0, 0, 100, false), &CTelegramProto::OnGetHistory, pUser); + return 0; } @@ -468,6 +482,28 @@ 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; @@ -495,7 +531,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) isForum = pGroup->group->is_forum_; if (isForum) - SendQuery(new TD::getForumTopics(pChat->id_, "", 0, 0, 0, 100)); + SendQuery(new TD::getForumTopics(pChat->id_, "", 0, 0, 0, 100), &CTelegramProto::OnGetForumTopics); } break; -- cgit v1.2.3