Add chatActionBarJoinRequest.

This commit is contained in:
levlam 2021-11-23 13:06:38 +03:00
parent 11b13021d2
commit 2eb5f1195c
4 changed files with 95 additions and 23 deletions

View File

@ -1015,7 +1015,7 @@ chatActionBarReportSpam can_unarchive:Bool = ChatActionBar;
//@description The chat is a location-based supergroup, which can be reported as having unrelated location using the method reportChat with the reason chatReportReasonUnrelatedLocation
chatActionBarReportUnrelatedLocation = ChatActionBar;
//@description The chat is a recently created group chat, to which new members can be invited
//@description The chat is a recently created group chat to which new members can be invited
chatActionBarInviteMembers = ChatActionBar;
//@description The chat is a private or secret chat, which can be reported using the method reportChat, or the other user can be blocked using the method toggleMessageSenderIsBlocked, or the other user can be added to the contact list using the method addContact
@ -1029,6 +1029,12 @@ chatActionBarAddContact = ChatActionBar;
//@description The chat is a private or secret chat with a mutual contact and the user's phone number can be shared with the other user using the method sharePhoneNumber
chatActionBarSharePhoneNumber = ChatActionBar;
//@description The chat is a private chat with an administrator of a chat to which the user sent join request
//@title Title of the chat to which the join request was sent
//@is_channel True, if the join request was sent to a channel chat
//@request_date Point in time (Unix timestamp) when the join request was sent
chatActionBarJoinRequest title:string is_channel:Bool request_date:int32 = ChatActionBar;
//@class KeyboardButtonType @description Describes a keyboard button type

View File

@ -13,9 +13,11 @@ namespace td {
unique_ptr<DialogActionBar> 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) {
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) {
!can_invite_members && join_request_dialog_title.empty()) {
return nullptr;
}
@ -28,29 +30,59 @@ unique_ptr<DialogActionBar> DialogActionBar::create(bool can_report_spam, bool c
action_bar->can_unarchive_ = can_unarchive;
action_bar->distance_ = distance >= 0 ? distance : -1;
action_bar->can_invite_members_ = can_invite_members;
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;
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_;
!can_report_location_ && !can_invite_members_ && join_request_dialog_title_.empty();
}
void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, FolderId folder_id) {
auto dialog_type = dialog_id.get_type();
if (distance_ >= 0 && dialog_type != DialogType::User) {
LOG(ERROR) << "Receive distance_ " << distance_ << " to " << dialog_id;
LOG(ERROR) << "Receive distance " << distance_ << " to " << dialog_id;
distance_ = -1;
}
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;
join_request_dialog_title_.clear();
is_join_request_broadcast_ = false;
join_request_date_ = 0;
} else if (can_report_location_ || can_report_spam_ || can_add_contact_ || can_block_user_ ||
can_share_phone_number_ || can_unarchive_ || can_invite_members_) {
LOG(ERROR) << "Receive action bar " << can_report_location_ << '/' << can_report_spam_ << '/' << can_add_contact_
<< '/' << can_block_user_ << '/' << can_share_phone_number_ << '/' << can_report_location_ << '/'
<< can_unarchive_ << '/' << can_invite_members_;
can_report_location_ = false;
can_report_spam_ = false;
can_add_contact_ = false;
can_block_user_ = false;
can_share_phone_number_ = false;
can_unarchive_ = false;
can_invite_members_ = false;
distance_ = -1;
}
}
if (join_request_dialog_title_.empty() && (is_join_request_broadcast_ || join_request_date_ != 0)) {
LOG(ERROR) << "Receive join request date = " << join_request_date_ << " and " << is_join_request_broadcast_
<< " in " << dialog_id;
is_join_request_broadcast_ = false;
join_request_date_ = 0;
}
if (can_report_location_) {
if (dialog_type != DialogType::Channel) {
LOG(ERROR) << "Receive can_report_location_ in " << dialog_id;
LOG(ERROR) << "Receive can_report_location in " << dialog_id;
can_report_location_ = false;
} else if (can_report_spam_ || can_add_contact_ || can_block_user_ || can_share_phone_number_ || can_unarchive_ ||
can_invite_members_) {
LOG(ERROR) << "Receive action bar " << can_report_spam_ << "/" << can_add_contact_ << "/" << can_block_user_
<< "/" << can_share_phone_number_ << "/" << can_report_location_ << "/" << can_unarchive_ << "/"
LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_
<< '/' << can_share_phone_number_ << '/' << can_report_location_ << '/' << can_unarchive_ << '/'
<< can_invite_members_;
can_report_spam_ = false;
can_add_contact_ = false;
@ -65,11 +97,11 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
if (dialog_type != DialogType::Chat &&
(dialog_type != DialogType::Channel || td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast)) {
LOG(ERROR) << "Receive can_invite_members_ in " << dialog_id;
LOG(ERROR) << "Receive can_invite_members in " << dialog_id;
can_invite_members_ = false;
} else if (can_report_spam_ || can_add_contact_ || can_block_user_ || can_share_phone_number_ || can_unarchive_) {
LOG(ERROR) << "Receive action bar " << can_report_spam_ << "/" << can_add_contact_ << "/" << can_block_user_
<< "/" << can_share_phone_number_ << "/" << can_unarchive_ << "/" << can_invite_members_;
LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_
<< '/' << can_share_phone_number_ << '/' << can_unarchive_ << '/' << can_invite_members_;
can_report_spam_ = false;
can_add_contact_ = false;
can_block_user_ = false;
@ -102,11 +134,11 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
CHECK(!can_report_location_);
CHECK(!can_invite_members_);
if (dialog_type != DialogType::User) {
LOG(ERROR) << "Receive can_share_phone_number_ in " << dialog_id;
LOG(ERROR) << "Receive can_share_phone_number in " << dialog_id;
can_share_phone_number_ = false;
} else if (can_report_spam_ || can_add_contact_ || can_block_user_ || can_unarchive_ || distance_ >= 0) {
LOG(ERROR) << "Receive action bar " << can_report_spam_ << "/" << can_add_contact_ << "/" << can_block_user_
<< "/" << can_share_phone_number_ << "/" << can_unarchive_ << "/" << distance_;
LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_
<< '/' << can_share_phone_number_ << '/' << can_unarchive_ << '/' << distance_;
can_report_spam_ = false;
can_add_contact_ = false;
can_block_user_ = false;
@ -118,10 +150,10 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
CHECK(!can_invite_members_);
CHECK(!can_share_phone_number_);
if (dialog_type != DialogType::User) {
LOG(ERROR) << "Receive can_block_user_ in " << dialog_id;
LOG(ERROR) << "Receive can_block_user in " << dialog_id;
can_block_user_ = false;
} else if (!can_report_spam_ || !can_add_contact_) {
LOG(ERROR) << "Receive action bar " << can_report_spam_ << "/" << can_add_contact_ << "/" << can_block_user_;
LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_;
can_report_spam_ = true;
can_add_contact_ = true;
}
@ -131,10 +163,10 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
CHECK(!can_invite_members_);
CHECK(!can_share_phone_number_);
if (dialog_type != DialogType::User) {
LOG(ERROR) << "Receive can_add_contact_ in " << dialog_id;
LOG(ERROR) << "Receive can_add_contact in " << dialog_id;
can_add_contact_ = false;
} else if (can_report_spam_ != can_block_user_) {
LOG(ERROR) << "Receive action bar " << can_report_spam_ << "/" << can_add_contact_ << "/" << can_block_user_;
LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_;
can_report_spam_ = false;
can_block_user_ = false;
can_unarchive_ = false;
@ -150,6 +182,13 @@ 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,
bool hide_unarchive) const {
if (!join_request_dialog_title_.empty()) {
CHECK(dialog_type == DialogType::User);
CHECK(!can_report_location_ && !can_share_phone_number_ && !can_block_user_ && !can_add_contact_ &&
!can_report_spam_ && !can_invite_members_);
return td_api::make_object<td_api::chatActionBarJoinRequest>(join_request_dialog_title_, is_join_request_broadcast_,
join_request_date_);
}
if (can_report_location_) {
CHECK(dialog_type == DialogType::Channel);
CHECK(!can_share_phone_number_ && !can_block_user_ && !can_add_contact_ && !can_report_spam_ &&
@ -213,10 +252,14 @@ bool DialogActionBar::on_user_contact_added() {
}
bool DialogActionBar::on_user_deleted() {
if (!can_share_phone_number_ && !can_block_user_ && !can_add_contact_ && distance_ < 0) {
if (join_request_dialog_title_.empty() && !can_share_phone_number_ && !can_block_user_ && !can_add_contact_ &&
distance_ < 0) {
return false;
}
join_request_dialog_title_.clear();
is_join_request_broadcast_ = false;
join_request_date_ = 0;
can_share_phone_number_ = false;
can_block_user_ = false;
can_add_contact_ = false;
@ -243,7 +286,11 @@ bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogA
return lhs->can_report_spam_ == rhs->can_report_spam_ && lhs->can_add_contact_ == rhs->can_add_contact_ &&
lhs->can_block_user_ == rhs->can_block_user_ && lhs->can_share_phone_number_ == rhs->can_share_phone_number_ &&
lhs->can_report_location_ == rhs->can_report_location_ && lhs->can_unarchive_ == rhs->can_unarchive_ &&
lhs->distance_ == rhs->distance_ && lhs->can_invite_members_ == rhs->can_invite_members_;
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_;
;
}
} // namespace td

View File

@ -19,6 +19,8 @@ class Td;
class DialogActionBar {
int32 distance_ = -1; // distance to the peer
int32 join_request_date_ = 0;
string join_request_dialog_title_;
bool can_report_spam_ = false;
bool can_add_contact_ = false;
@ -27,13 +29,15 @@ class DialogActionBar {
bool can_report_location_ = false;
bool can_unarchive_ = false;
bool can_invite_members_ = false;
bool is_join_request_broadcast_ = false;
friend bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogActionBar> &rhs);
public:
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);
int32 distance, bool can_invite_members, string join_request_dialog_title,
bool is_join_request_broadcast, int32 join_request_date);
bool is_empty() const;
@ -61,6 +65,7 @@ class DialogActionBar {
template <class StorerT>
void store(StorerT &storer) const {
bool has_distance = distance_ >= 0;
bool has_join_request = !join_request_dialog_title_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(can_report_spam_);
STORE_FLAG(can_add_contact_);
@ -70,15 +75,22 @@ class DialogActionBar {
STORE_FLAG(can_unarchive_);
STORE_FLAG(can_invite_members_);
STORE_FLAG(has_distance);
STORE_FLAG(is_join_request_broadcast_);
STORE_FLAG(has_join_request);
END_STORE_FLAGS();
if (has_distance) {
td::store(distance_, storer);
}
if (has_join_request) {
td::store(join_request_dialog_title_, storer);
td::store(join_request_date_, storer);
}
}
template <class ParserT>
void parse(ParserT &parser) {
bool has_distance;
bool has_join_request;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(can_report_spam_);
PARSE_FLAG(can_add_contact_);
@ -88,10 +100,16 @@ class DialogActionBar {
PARSE_FLAG(can_unarchive_);
PARSE_FLAG(can_invite_members_);
PARSE_FLAG(has_distance);
PARSE_FLAG(is_join_request_broadcast_);
PARSE_FLAG(has_join_request);
END_PARSE_FLAGS();
if (has_distance) {
td::parse(distance_, parser);
}
if (has_join_request) {
td::parse(join_request_dialog_title_, parser);
td::parse(join_request_date_, parser);
}
}
};

View File

@ -5721,7 +5721,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
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);
has_outgoing_messages ? -1 : action_bar_distance, action_bar_can_invite_members, string(), false, 0);
}
}
@ -8328,7 +8328,8 @@ void MessagesManager::on_get_peer_settings(DialogId dialog_id,
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_);
distance, peer_settings->invite_members_, peer_settings->request_chat_title_,
peer_settings->request_chat_broadcast_, peer_settings->request_chat_date_);
fix_dialog_action_bar(d, action_bar.get());