mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-02 16:42:56 +01:00
Add cache for business connections.
This commit is contained in:
parent
393b6c00fb
commit
a3f62fcdf7
@ -3578,7 +3578,7 @@ class Client::JsonMessageReactionCountUpdated final : public td::Jsonable {
|
|||||||
|
|
||||||
class Client::JsonBusinessConnection final : public td::Jsonable {
|
class Client::JsonBusinessConnection final : public td::Jsonable {
|
||||||
public:
|
public:
|
||||||
JsonBusinessConnection(const td_api::businessConnection *connection, const Client *client)
|
JsonBusinessConnection(const BusinessConnection *connection, const Client *client)
|
||||||
: connection_(connection), client_(client) {
|
: connection_(connection), client_(client) {
|
||||||
}
|
}
|
||||||
void store(td::JsonValueScope *scope) const {
|
void store(td::JsonValueScope *scope) const {
|
||||||
@ -3592,7 +3592,7 @@ class Client::JsonBusinessConnection final : public td::Jsonable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const td_api::businessConnection *connection_;
|
const BusinessConnection *connection_;
|
||||||
const Client *client_;
|
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<td_api::businessConnection> &&business_connection, bool from_update) {
|
||||||
|
CHECK(business_connection != nullptr);
|
||||||
|
auto &connection = business_connections_[business_connection->id_];
|
||||||
|
if (connection == nullptr) {
|
||||||
|
connection = td::make_unique<BusinessConnection>();
|
||||||
|
} 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 {
|
void Client::json_store_file(td::JsonObjectScope &object, const td_api::file *file, bool with_path) const {
|
||||||
if (file->id_ == 0) {
|
if (file->id_ == 0) {
|
||||||
return;
|
return;
|
||||||
@ -12344,12 +12366,11 @@ void Client::add_update_message_reaction_count(object_ptr<td_api::updateMessageR
|
|||||||
|
|
||||||
void Client::add_update_business_connection(object_ptr<td_api::updateBusinessConnection> &&update) {
|
void Client::add_update_business_connection(object_ptr<td_api::updateBusinessConnection> &&update) {
|
||||||
CHECK(update != nullptr);
|
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();
|
auto left_time = connection->date_ + 86400 - get_unix_time();
|
||||||
if (left_time > 0) {
|
if (left_time > 0) {
|
||||||
auto webhook_queue_id = connection->user_id_ + (static_cast<int64>(10) << 33);
|
auto webhook_queue_id = connection->user_id_ + (static_cast<int64>(10) << 33);
|
||||||
add_update(UpdateType::BusinessConnection, JsonBusinessConnection(connection.get(), this), left_time,
|
add_update(UpdateType::BusinessConnection, JsonBusinessConnection(connection, this), left_time, webhook_queue_id);
|
||||||
webhook_queue_id);
|
|
||||||
} else {
|
} else {
|
||||||
LOG(DEBUG) << "Skip updateBusinessConnection with date " << connection->date_ << ", because current date is "
|
LOG(DEBUG) << "Skip updateBusinessConnection with date " << connection->date_ << ", because current date is "
|
||||||
<< get_unix_time();
|
<< get_unix_time();
|
||||||
|
@ -888,6 +888,18 @@ class Client final : public WebhookActor::Callback {
|
|||||||
mutable bool is_content_changed = false;
|
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<td_api::businessConnection> &&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,
|
static int64 get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to,
|
||||||
int64 message_thread_id);
|
int64 message_thread_id);
|
||||||
|
|
||||||
@ -1112,6 +1124,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
td::WaitFreeHashMap<int64, td::unique_ptr<GroupInfo>> groups_;
|
td::WaitFreeHashMap<int64, td::unique_ptr<GroupInfo>> groups_;
|
||||||
td::WaitFreeHashMap<int64, td::unique_ptr<SupergroupInfo>> supergroups_;
|
td::WaitFreeHashMap<int64, td::unique_ptr<SupergroupInfo>> supergroups_;
|
||||||
td::WaitFreeHashMap<int64, td::unique_ptr<ChatInfo>> chats_;
|
td::WaitFreeHashMap<int64, td::unique_ptr<ChatInfo>> chats_;
|
||||||
|
td::WaitFreeHashMap<td::string, td::unique_ptr<BusinessConnection>> business_connections_;
|
||||||
|
|
||||||
td::FlatHashMap<int32, td::vector<PromisedQueryPtr>> file_download_listeners_;
|
td::FlatHashMap<int32, td::vector<PromisedQueryPtr>> file_download_listeners_;
|
||||||
td::FlatHashSet<int32> download_started_file_ids_;
|
td::FlatHashSet<int32> download_started_file_ids_;
|
||||||
|
Loading…
Reference in New Issue
Block a user