Add td_api::chatActionBarManageBusinessBot.

This commit is contained in:
levlam 2024-04-07 01:46:46 +03:00
parent 4444f0e328
commit f9dfd502da
4 changed files with 98 additions and 24 deletions

View File

@ -1882,6 +1882,13 @@ chatActionBarSharePhoneNumber = ChatActionBar;
//@request_date Point in time (Unix timestamp) when the join request was sent
chatActionBarJoinRequest title:string is_channel:Bool request_date:int32 = ChatActionBar;
//@description The chat is a private chat administered by a business bot
//@bot_user_id User identifier of the bot
//@manage_url URL to be opened to manage the bot
//@is_bot_paused True, if the bot is paused
//@can_bot_reply True, if the bot can reply
chatActionBarManageBusinessBot bot_user_id:int53 manage_url:string is_bot_paused:Bool can_bot_reply:Bool = ChatActionBar;
//@class KeyboardButtonType @description Describes a keyboard button type

View File

@ -18,12 +18,9 @@ unique_ptr<DialogActionBar> DialogActionBar::create(bool can_report_spam, bool c
bool can_share_phone_number, bool can_report_location,
bool can_unarchive, int32 distance, bool can_invite_members,
string join_request_dialog_title, bool is_join_request_broadcast,
int32 join_request_date) {
if (!can_report_spam && !can_add_contact && !can_block_user && !can_share_phone_number && !can_report_location &&
!can_invite_members && join_request_dialog_title.empty()) {
return nullptr;
}
int32 join_request_date, bool is_business_bot_paused,
bool can_business_bot_reply, UserId business_bot_user_id,
string business_bot_manage_url) {
auto action_bar = make_unique<DialogActionBar>();
action_bar->can_report_spam_ = can_report_spam;
action_bar->can_add_contact_ = can_add_contact;
@ -36,12 +33,20 @@ unique_ptr<DialogActionBar> DialogActionBar::create(bool can_report_spam, bool c
action_bar->join_request_dialog_title_ = std::move(join_request_dialog_title);
action_bar->is_join_request_broadcast_ = is_join_request_broadcast;
action_bar->join_request_date_ = join_request_date;
action_bar->is_business_bot_paused_ = is_business_bot_paused;
action_bar->can_business_bot_reply_ = can_business_bot_reply;
action_bar->business_bot_user_id_ = business_bot_user_id;
action_bar->business_bot_manage_url_ = std::move(business_bot_manage_url);
if (action_bar->is_empty()) {
return nullptr;
}
return action_bar;
}
bool DialogActionBar::is_empty() const {
return !can_report_spam_ && !can_add_contact_ && !can_block_user_ && !can_share_phone_number_ &&
!can_report_location_ && !can_invite_members_ && join_request_dialog_title_.empty();
!can_report_location_ && !can_invite_members_ && join_request_dialog_title_.empty() &&
!business_bot_user_id_.is_valid();
}
void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, FolderId folder_id) {
@ -51,6 +56,22 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
distance_ = -1;
}
if (business_bot_user_id_.is_valid()) {
if (dialog_type != DialogType::User || business_bot_manage_url_.empty()) {
LOG(ERROR) << "Receive business bot " << business_bot_user_id_ << " in " << dialog_id << " with manage URL "
<< business_bot_manage_url_;
business_bot_user_id_ = {};
business_bot_manage_url_ = {};
is_business_bot_paused_ = false;
can_business_bot_reply_ = false;
}
} else if (!business_bot_manage_url_.empty() || is_business_bot_paused_ || can_business_bot_reply_) {
LOG(ERROR) << "Receive business bot " << business_bot_user_id_ << " in " << dialog_id << " with manage URL "
<< business_bot_manage_url_;
business_bot_manage_url_ = {};
is_business_bot_paused_ = false;
can_business_bot_reply_ = false;
}
if (!join_request_dialog_title_.empty()) {
if (dialog_type != DialogType::User || join_request_date_ <= 0) {
LOG(ERROR) << "Receive join_request_date = " << join_request_date_ << " in " << dialog_id;
@ -182,7 +203,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
}
}
td_api::object_ptr<td_api::ChatActionBar> DialogActionBar::get_chat_action_bar_object(DialogType dialog_type,
td_api::object_ptr<td_api::ChatActionBar> DialogActionBar::get_chat_action_bar_object(Td *td, DialogType dialog_type,
bool hide_unarchive) const {
if (!join_request_dialog_title_.empty()) {
CHECK(dialog_type == DialogType::User);
@ -226,6 +247,12 @@ td_api::object_ptr<td_api::ChatActionBar> DialogActionBar::get_chat_action_bar_o
if (can_report_spam_) {
return td_api::make_object<td_api::chatActionBarReportSpam>(can_unarchive_);
}
if (business_bot_user_id_.is_valid()) {
CHECK(dialog_type == DialogType::User);
return td_api::make_object<td_api::chatActionBarManageBusinessBot>(
td->user_manager_->get_user_id_object(business_bot_user_id_, "chatActionBarManageBusinessBot"),
business_bot_manage_url_, is_business_bot_paused_, can_business_bot_reply_);
}
return nullptr;
}
@ -254,11 +281,15 @@ bool DialogActionBar::on_user_contact_added() {
}
bool DialogActionBar::on_user_deleted() {
if (join_request_dialog_title_.empty() && !can_share_phone_number_ && !can_block_user_ && !can_add_contact_ &&
distance_ < 0) {
if (!business_bot_user_id_.is_valid() && join_request_dialog_title_.empty() && !can_share_phone_number_ &&
!can_block_user_ && !can_add_contact_ && distance_ < 0) {
return false;
}
business_bot_user_id_ = {};
business_bot_manage_url_.clear();
is_business_bot_paused_ = false;
can_business_bot_reply_ = false;
join_request_dialog_title_.clear();
is_join_request_broadcast_ = false;
join_request_date_ = 0;
@ -291,7 +322,11 @@ bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogA
lhs->distance_ == rhs->distance_ && lhs->can_invite_members_ == rhs->can_invite_members_ &&
lhs->join_request_dialog_title_ == rhs->join_request_dialog_title_ &&
lhs->is_join_request_broadcast_ == lhs->is_join_request_broadcast_ &&
lhs->join_request_date_ == rhs->join_request_date_;
lhs->join_request_date_ == rhs->join_request_date_ &&
lhs->business_bot_user_id_ == rhs->business_bot_user_id_ &&
lhs->business_bot_manage_url_ == rhs->business_bot_manage_url_ &&
lhs->is_business_bot_paused_ == rhs->is_business_bot_paused_ &&
lhs->can_business_bot_reply_ == rhs->can_business_bot_reply_;
}
} // namespace td

View File

@ -21,6 +21,8 @@ class DialogActionBar {
int32 distance_ = -1; // distance to the peer
int32 join_request_date_ = 0;
string join_request_dialog_title_;
UserId business_bot_user_id_;
string business_bot_manage_url_;
bool can_report_spam_ = false;
bool can_add_contact_ = false;
@ -30,6 +32,8 @@ class DialogActionBar {
bool can_unarchive_ = false;
bool can_invite_members_ = false;
bool is_join_request_broadcast_ = false;
bool is_business_bot_paused_ = false;
bool can_business_bot_reply_ = false;
friend bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogActionBar> &rhs);
@ -37,7 +41,9 @@ class DialogActionBar {
static unique_ptr<DialogActionBar> create(bool can_report_spam, bool can_add_contact, bool can_block_user,
bool can_share_phone_number, bool can_report_location, bool can_unarchive,
int32 distance, bool can_invite_members, string join_request_dialog_title,
bool is_join_request_broadcast, int32 join_request_date);
bool is_join_request_broadcast, int32 join_request_date,
bool is_business_bot_paused, bool can_business_bot_reply,
UserId business_bot_user_id, string business_bot_manage_url);
bool is_empty() const;
@ -49,7 +55,7 @@ class DialogActionBar {
return can_unarchive_;
}
td_api::object_ptr<td_api::ChatActionBar> get_chat_action_bar_object(DialogType dialog_type,
td_api::object_ptr<td_api::ChatActionBar> get_chat_action_bar_object(Td *td, DialogType dialog_type,
bool hide_unarchive) const;
void fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, FolderId folder_id);
@ -66,6 +72,8 @@ class DialogActionBar {
void store(StorerT &storer) const {
bool has_distance = distance_ >= 0;
bool has_join_request = !join_request_dialog_title_.empty();
bool has_business_bot_user_id = business_bot_user_id_.is_valid();
bool has_business_bot_manage_url = !business_bot_manage_url_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(can_report_spam_);
STORE_FLAG(can_add_contact_);
@ -77,6 +85,10 @@ class DialogActionBar {
STORE_FLAG(has_distance);
STORE_FLAG(is_join_request_broadcast_);
STORE_FLAG(has_join_request);
STORE_FLAG(is_business_bot_paused_);
STORE_FLAG(can_business_bot_reply_);
STORE_FLAG(has_business_bot_user_id);
STORE_FLAG(has_business_bot_manage_url);
END_STORE_FLAGS();
if (has_distance) {
td::store(distance_, storer);
@ -85,12 +97,20 @@ class DialogActionBar {
td::store(join_request_dialog_title_, storer);
td::store(join_request_date_, storer);
}
if (has_business_bot_user_id) {
td::store(business_bot_user_id_, storer);
}
if (has_business_bot_manage_url) {
td::store(business_bot_manage_url_, storer);
}
}
template <class ParserT>
void parse(ParserT &parser) {
bool has_distance;
bool has_join_request;
bool has_business_bot_user_id;
bool has_business_bot_manage_url;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(can_report_spam_);
PARSE_FLAG(can_add_contact_);
@ -102,6 +122,10 @@ class DialogActionBar {
PARSE_FLAG(has_distance);
PARSE_FLAG(is_join_request_broadcast_);
PARSE_FLAG(has_join_request);
PARSE_FLAG(is_business_bot_paused_);
PARSE_FLAG(can_business_bot_reply_);
PARSE_FLAG(has_business_bot_user_id);
PARSE_FLAG(has_business_bot_manage_url);
END_PARSE_FLAGS();
if (has_distance) {
td::parse(distance_, parser);
@ -110,6 +134,12 @@ class DialogActionBar {
td::parse(join_request_dialog_title_, parser);
td::parse(join_request_date_, parser);
}
if (has_business_bot_user_id) {
td::parse(business_bot_user_id_, parser);
}
if (has_business_bot_manage_url) {
td::parse(business_bot_manage_url_, parser);
}
}
};

View File

@ -5263,10 +5263,11 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
(void)legacy_know_can_report_spam;
if (know_action_bar && !has_action_bar) {
action_bar = DialogActionBar::create(
action_bar_can_report_spam, action_bar_can_add_contact, action_bar_can_block_user,
action_bar_can_share_phone_number, action_bar_can_report_location, action_bar_can_unarchive,
has_outgoing_messages ? -1 : action_bar_distance, action_bar_can_invite_members, string(), false, 0);
action_bar =
DialogActionBar::create(action_bar_can_report_spam, action_bar_can_add_contact, action_bar_can_block_user,
action_bar_can_share_phone_number, action_bar_can_report_location,
action_bar_can_unarchive, has_outgoing_messages ? -1 : action_bar_distance,
action_bar_can_invite_members, string(), false, 0, false, false, UserId(), string());
}
}
@ -7960,11 +7961,12 @@ void MessagesManager::on_get_peer_settings(DialogId dialog_id,
if (distance < -1 || d->has_outgoing_messages) {
distance = -1;
}
auto action_bar =
DialogActionBar::create(peer_settings->report_spam_, peer_settings->add_contact_, peer_settings->block_contact_,
peer_settings->share_contact_, peer_settings->report_geo_, peer_settings->autoarchived_,
distance, peer_settings->invite_members_, peer_settings->request_chat_title_,
peer_settings->request_chat_broadcast_, peer_settings->request_chat_date_);
auto action_bar = DialogActionBar::create(
peer_settings->report_spam_, peer_settings->add_contact_, peer_settings->block_contact_,
peer_settings->share_contact_, peer_settings->report_geo_, peer_settings->autoarchived_, distance,
peer_settings->invite_members_, peer_settings->request_chat_title_, peer_settings->request_chat_broadcast_,
peer_settings->request_chat_date_, peer_settings->business_bot_paused_, peer_settings->business_bot_can_reply_,
UserId(peer_settings->business_bot_id_), std::move(peer_settings->business_bot_manage_url_));
fix_dialog_action_bar(d, action_bar.get());
@ -19220,13 +19222,13 @@ td_api::object_ptr<td_api::ChatActionBar> MessagesManager::get_chat_action_bar_o
if (user_d == nullptr || user_d->action_bar == nullptr) {
return nullptr;
}
return user_d->action_bar->get_chat_action_bar_object(DialogType::User, d->folder_id != FolderId::archive());
return user_d->action_bar->get_chat_action_bar_object(td_, DialogType::User, d->folder_id != FolderId::archive());
}
if (d->action_bar == nullptr) {
return nullptr;
}
return d->action_bar->get_chat_action_bar_object(dialog_type, false);
return d->action_bar->get_chat_action_bar_object(td_, dialog_type, false);
}
td_api::object_ptr<td_api::chatBackground> MessagesManager::get_chat_background_object(const Dialog *d) const {