diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 7cdd107..e95a53c 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -3578,7 +3578,7 @@ class Client::JsonMessageReactionCountUpdated final : public td::Jsonable { class Client::JsonBusinessConnection final : public td::Jsonable { public: - JsonBusinessConnection(const td_api::businessConnection *connection, const Client *client) + JsonBusinessConnection(const BusinessConnection *connection, const Client *client) : connection_(connection), client_(client) { } void store(td::JsonValueScope *scope) const { @@ -3592,7 +3592,7 @@ class Client::JsonBusinessConnection final : public td::Jsonable { } private: - const td_api::businessConnection *connection_; + const BusinessConnection *connection_; const Client *client_; }; @@ -11839,6 +11839,28 @@ td::string Client::get_chat_description(int64 chat_id) const { } } +const Client::BusinessConnection *Client::add_business_connection( + object_ptr &&business_connection, bool from_update) { + CHECK(business_connection != nullptr); + auto &connection = business_connections_[business_connection->id_]; + if (connection == nullptr) { + connection = td::make_unique(); + } else if (!from_update) { + return connection.get(); + } + connection->id_ = std::move(business_connection->id_); + connection->user_id_ = business_connection->user_id_; + connection->user_chat_id_ = business_connection->user_chat_id_; + connection->date_ = business_connection->date_; + connection->can_reply_ = business_connection->can_reply_; + connection->is_enabled_ = business_connection->is_enabled_; + return connection.get(); +} + +const Client::BusinessConnection *Client::get_business_connection(const td::string &connection_id) const { + return business_connections_.get_pointer(connection_id); +} + void Client::json_store_file(td::JsonObjectScope &object, const td_api::file *file, bool with_path) const { if (file->id_ == 0) { return; @@ -12344,12 +12366,11 @@ void Client::add_update_message_reaction_count(object_ptr &&update) { CHECK(update != nullptr); - auto connection = std::move(update->connection_); + const auto *connection = add_business_connection(std::move(update->connection_), true); auto left_time = connection->date_ + 86400 - get_unix_time(); if (left_time > 0) { auto webhook_queue_id = connection->user_id_ + (static_cast(10) << 33); - add_update(UpdateType::BusinessConnection, JsonBusinessConnection(connection.get(), this), left_time, - webhook_queue_id); + add_update(UpdateType::BusinessConnection, JsonBusinessConnection(connection, this), left_time, webhook_queue_id); } else { LOG(DEBUG) << "Skip updateBusinessConnection with date " << connection->date_ << ", because current date is " << get_unix_time(); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 0f2a1c6..cd34b49 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -888,6 +888,18 @@ class Client final : public WebhookActor::Callback { mutable bool is_content_changed = false; }; + struct BusinessConnection { + td::string id_; + int64 user_id_ = 0; + int64 user_chat_id_ = 0; + int32 date_ = 0; + bool can_reply_ = false; + bool is_enabled_ = false; + }; + const BusinessConnection *add_business_connection(object_ptr &&business_connection, + bool from_update); + const BusinessConnection *get_business_connection(const td::string &connection_id) const; + static int64 get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to, int64 message_thread_id); @@ -1112,6 +1124,7 @@ class Client final : public WebhookActor::Callback { td::WaitFreeHashMap> groups_; td::WaitFreeHashMap> supergroups_; td::WaitFreeHashMap> chats_; + td::WaitFreeHashMap> business_connections_; td::FlatHashMap> file_download_listeners_; td::FlatHashSet download_started_file_ids_;