diff options
| author | levlam <levlam@telegram.org> | 2026-07-10 22:51:02 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-07-10 22:51:02 +0300 |
| commit | 40a79c8367eaa64385b0a9a05d4949edd181bcba (patch) | |
| tree | 170b814ea356a799b531b6fbf7aca2fcd2b6002f | |
| parent | 60bfc54349f9c7b420bc6947de84aabd4c7ff7fa (diff) | |
Add community cache.
| -rw-r--r-- | telegram-bot-api/Client.cpp | 24 | ||||
| -rw-r--r-- | telegram-bot-api/Client.h | 8 |
2 files changed, 31 insertions, 1 deletions
diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 173948e..d7ed0d0 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -54,7 +54,7 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te Client::~Client() { td::Scheduler::instance()->destroy_on_scheduler(SharedData::get_file_gc_scheduler_id(), messages_, users_, groups_, - supergroups_, chats_, sticker_set_names_); + supergroups_, chats_, communities_, sticker_set_names_); } int Client::get_retry_after_time(td::Slice error_message) { @@ -9663,6 +9663,12 @@ void Client::on_update(object_ptr<td_api::Object> result) { add_supergroup(supergroup_info, std::move(update->supergroup_)); break; } + case td_api::updateCommunity::ID: { + auto update = move_object_as<td_api::updateCommunity>(result); + auto *community_info = add_community_info(update->community_->id_); + add_community(community_info, std::move(update->community_)); + break; + } case td_api::updateSupergroupFullInfo::ID: { auto update = move_object_as<td_api::updateSupergroupFullInfo>(result); auto supergroup_id = update->supergroup_id_; @@ -17553,6 +17559,22 @@ const Client::ChatInfo *Client::get_chat(int64 chat_id) const { return chats_.get_pointer(chat_id); } +void Client::add_community(CommunityInfo *community_info, object_ptr<td_api::community> &&community) { + community_info->name = std::move(community->name_); +} + +Client::CommunityInfo *Client::add_community_info(int64 community_id) { + auto &community_info = communities_[community_id]; + if (community_info == nullptr) { + community_info = td::make_unique<CommunityInfo>(); + } + return community_info.get(); +} + +const Client::CommunityInfo *Client::get_community_info(int64 community_id) const { + return communities_.get_pointer(community_id); +} + void Client::set_chat_available_reactions(ChatInfo *chat_info, object_ptr<td_api::ChatAvailableReactions> &&available_reactions) { CHECK(chat_info != nullptr); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6ce5973..e0b00ad 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -1210,6 +1210,13 @@ class Client final : public WebhookActor::Callback { ChatInfo *add_chat(int64 chat_id); const ChatInfo *get_chat(int64 chat_id) const; + struct CommunityInfo { + td::string name; + }; + static void add_community(CommunityInfo *community_info, object_ptr<td_api::community> &&community); + CommunityInfo *add_community_info(int64 community_id); + const CommunityInfo *get_community_info(int64 community_id) const; + void set_chat_available_reactions(ChatInfo *chat_info, object_ptr<td_api::ChatAvailableReactions> &&available_reactions); @@ -1562,6 +1569,7 @@ class Client final : public WebhookActor::Callback { td::WaitFreeHashMap<int64, td::unique_ptr<GroupInfo>> groups_; td::WaitFreeHashMap<int64, td::unique_ptr<SupergroupInfo>> supergroups_; td::WaitFreeHashMap<int64, td::unique_ptr<ChatInfo>> chats_; + td::WaitFreeHashMap<int64, td::unique_ptr<CommunityInfo>> communities_; td::WaitFreeHashMap<td::string, td::unique_ptr<BusinessConnection>> business_connections_; td::FlatHashMap<int32, td::vector<PromisedQueryPtr>> file_download_listeners_; |
