aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-07-10 16:01:29 +0300
committerlevlam <levlam@telegram.org>2026-07-10 16:01:29 +0300
commite4e806bbeca07f08fed9269d4e31c5607619b597 (patch)
treeb5dedcd4b2f6b7cf50ab94b96bcbeca872050f47
parent565e77f595527b3fd5ba5fd8a8e58d769c781426 (diff)
Implement reload_community.
-rw-r--r--td/telegram/CommunityManager.cpp48
-rw-r--r--td/telegram/CommunityManager.h3
2 files changed, 50 insertions, 1 deletions
diff --git a/td/telegram/CommunityManager.cpp b/td/telegram/CommunityManager.cpp
index 6e1fca02e..1896301d0 100644
--- a/td/telegram/CommunityManager.cpp
+++ b/td/telegram/CommunityManager.cpp
@@ -7,6 +7,7 @@
#include "td/telegram/CommunityManager.h"
#include "td/telegram/AuthManager.h"
+#include "td/telegram/ChatManager.h"
#include "td/telegram/DialogPhoto.hpp"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
@@ -20,11 +21,47 @@
#include "td/db/SqliteKeyValue.h"
#include "td/db/SqliteKeyValueAsync.h"
+#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/utf8.h"
namespace td {
+class GetCommunitiesQuery final : public Td::ResultHandler {
+ Promise<Unit> promise_;
+
+ public:
+ explicit GetCommunitiesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
+ }
+
+ void send(telegram_api::object_ptr<telegram_api::InputChannel> &&input_channel) {
+ CHECK(input_channel != nullptr);
+ vector<tl_object_ptr<telegram_api::InputChannel>> input_channels;
+ input_channels.push_back(std::move(input_channel));
+ send_query(G()->net_query_creator().create(telegram_api::channels_getChannels(std::move(input_channels))));
+ }
+
+ void on_result(BufferSlice packet) final {
+ auto result_ptr = fetch_result<telegram_api::channels_getChannels>(packet);
+ if (result_ptr.is_error()) {
+ return on_error(result_ptr.move_as_error());
+ }
+
+ auto chats_ptr = result_ptr.move_as_ok();
+ if (chats_ptr->get_id() == telegram_api::messages_chats::ID) {
+ auto chats = telegram_api::move_object_as<telegram_api::messages_chats>(chats_ptr);
+ td_->chat_manager_->on_get_chats(std::move(chats->chats_), "GetCommunitiesQuery");
+ } else {
+ LOG(ERROR) << "Receive " << to_string(chats_ptr);
+ }
+ promise_.set_value(Unit());
+ }
+
+ void on_error(Status status) final {
+ promise_.set_error(std::move(status));
+ }
+};
+
template <class StorerT>
void CommunityManager::Community::store(StorerT &storer) const {
using td::store;
@@ -70,6 +107,15 @@ void CommunityManager::Community::parse(ParserT &parser) {
}
CommunityManager::CommunityManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
+ get_community_queries_.set_merge_function([this](vector<int64> query_ids, Promise<Unit> &&promise) {
+ TRY_STATUS_PROMISE(promise, G()->close_status());
+ CHECK(query_ids.size() == 1u);
+ auto input_community = get_input_community(CommunityId(query_ids[0]));
+ if (input_community == nullptr) {
+ return promise.set_error(400, "Community not found");
+ }
+ td_->create_handler<GetCommunitiesQuery>(std::move(promise))->send(std::move(input_community));
+ });
}
CommunityManager::~CommunityManager() {
@@ -325,7 +371,7 @@ void CommunityManager::reload_community(CommunityId community_id, Promise<Unit>
}
have_community_force(community_id, source);
- //get_community_queries_.add_query(community_id.get(), std::move(promise), source);
+ get_community_queries_.add_query(community_id.get(), std::move(promise), source);
}
bool CommunityManager::have_community_force(CommunityId community_id, const char *source) {
diff --git a/td/telegram/CommunityManager.h b/td/telegram/CommunityManager.h
index e53c11c0f..fb936d601 100644
--- a/td/telegram/CommunityManager.h
+++ b/td/telegram/CommunityManager.h
@@ -9,6 +9,7 @@
#include "td/telegram/CommunityId.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/DialogPhoto.h"
+#include "td/telegram/QueryMerger.h"
#include "td/actor/actor.h"
@@ -144,6 +145,8 @@ class CommunityManager final : public Actor {
FlatHashMap<CommunityId, vector<Promise<Unit>>, CommunityIdHash> load_community_from_database_queries_;
FlatHashSet<CommunityId, CommunityIdHash> loaded_from_database_communities_;
+
+ QueryMerger get_community_queries_{"GetCommunityMerger", 10, 1};
};
} // namespace td