summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-25 20:01:18 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-25 20:01:18 +0300
commitd8c9835b36be01fbd5584f52a1ee1c1ba66b61b0 (patch)
treea7b313b37602ffed81a2eb56c7b69ed217c7af9d
parentbdff86736fb1d45f7cdaa216307bf2e38ca407aa (diff)
fixes #4300 (Telegram: не удаётся загрузить историю у ветки)
-rw-r--r--protocols/Telegram/src/proto.h2
-rw-r--r--protocols/Telegram/src/server.cpp42
2 files changed, 41 insertions, 3 deletions
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<CTelegramProto>
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;