Make DialogActionBar fields private.
This commit is contained in:
parent
be30321801
commit
46b8aeab97
@ -20,62 +20,62 @@ unique_ptr<DialogActionBar> DialogActionBar::create(bool can_report_spam, bool c
|
||||
}
|
||||
|
||||
auto action_bar = make_unique<DialogActionBar>();
|
||||
action_bar->can_report_spam = can_report_spam;
|
||||
action_bar->can_add_contact = can_add_contact;
|
||||
action_bar->can_block_user = can_block_user;
|
||||
action_bar->can_share_phone_number = can_share_phone_number;
|
||||
action_bar->can_report_location = can_report_location;
|
||||
action_bar->can_unarchive = can_unarchive;
|
||||
action_bar->distance = distance >= 0 ? distance : -1;
|
||||
action_bar->can_invite_members = can_invite_members;
|
||||
action_bar->can_report_spam_ = can_report_spam;
|
||||
action_bar->can_add_contact_ = can_add_contact;
|
||||
action_bar->can_block_user_ = can_block_user;
|
||||
action_bar->can_share_phone_number_ = can_share_phone_number;
|
||||
action_bar->can_report_location_ = can_report_location;
|
||||
action_bar->can_unarchive_ = can_unarchive;
|
||||
action_bar->distance_ = distance >= 0 ? distance : -1;
|
||||
action_bar->can_invite_members_ = can_invite_members;
|
||||
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;
|
||||
return !can_report_spam_ && !can_add_contact_ && !can_block_user_ && !can_share_phone_number_ &&
|
||||
!can_report_location_ && !can_invite_members_;
|
||||
}
|
||||
|
||||
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;
|
||||
distance = -1;
|
||||
if (distance_ >= 0 && dialog_type != DialogType::User) {
|
||||
LOG(ERROR) << "Receive distance_ " << distance_ << " to " << dialog_id;
|
||||
distance_ = -1;
|
||||
}
|
||||
|
||||
if (can_report_location) {
|
||||
if (can_report_location_) {
|
||||
if (dialog_type != DialogType::Channel) {
|
||||
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 << "/"
|
||||
<< can_invite_members;
|
||||
can_report_spam = false;
|
||||
can_add_contact = false;
|
||||
can_block_user = false;
|
||||
can_share_phone_number = false;
|
||||
can_unarchive = false;
|
||||
can_invite_members = false;
|
||||
CHECK(distance == -1);
|
||||
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_ << "/"
|
||||
<< can_invite_members_;
|
||||
can_report_spam_ = false;
|
||||
can_add_contact_ = false;
|
||||
can_block_user_ = false;
|
||||
can_share_phone_number_ = false;
|
||||
can_unarchive_ = false;
|
||||
can_invite_members_ = false;
|
||||
CHECK(distance_ == -1);
|
||||
}
|
||||
}
|
||||
if (can_invite_members) {
|
||||
if (can_invite_members_) {
|
||||
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;
|
||||
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;
|
||||
can_report_spam = false;
|
||||
can_add_contact = false;
|
||||
can_block_user = false;
|
||||
can_share_phone_number = false;
|
||||
can_unarchive = false;
|
||||
CHECK(distance == -1);
|
||||
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_;
|
||||
can_report_spam_ = false;
|
||||
can_add_contact_ = false;
|
||||
can_block_user_ = false;
|
||||
can_share_phone_number_ = false;
|
||||
can_unarchive_ = false;
|
||||
CHECK(distance_ == -1);
|
||||
}
|
||||
}
|
||||
if (dialog_type == DialogType::User) {
|
||||
@ -84,151 +84,152 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
|
||||
bool is_deleted = td->contacts_manager_->is_user_deleted(user_id);
|
||||
bool is_contact = td->contacts_manager_->is_user_contact(user_id);
|
||||
if (is_me || is_dialog_blocked) {
|
||||
can_report_spam = false;
|
||||
can_unarchive = false;
|
||||
can_report_spam_ = false;
|
||||
can_unarchive_ = false;
|
||||
}
|
||||
if (is_me || is_dialog_blocked || is_deleted) {
|
||||
can_share_phone_number = false;
|
||||
can_share_phone_number_ = false;
|
||||
}
|
||||
if (is_me || is_dialog_blocked || is_deleted || is_contact) {
|
||||
can_block_user = false;
|
||||
can_add_contact = false;
|
||||
can_block_user_ = false;
|
||||
can_add_contact_ = false;
|
||||
}
|
||||
}
|
||||
if (folder_id != FolderId::archive()) {
|
||||
can_unarchive = false;
|
||||
can_unarchive_ = false;
|
||||
}
|
||||
if (can_share_phone_number) {
|
||||
CHECK(!can_report_location);
|
||||
CHECK(!can_invite_members);
|
||||
if (can_share_phone_number_) {
|
||||
CHECK(!can_report_location_);
|
||||
CHECK(!can_invite_members_);
|
||||
if (dialog_type != DialogType::User) {
|
||||
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;
|
||||
can_report_spam = false;
|
||||
can_add_contact = false;
|
||||
can_block_user = false;
|
||||
can_unarchive = false;
|
||||
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_;
|
||||
can_report_spam_ = false;
|
||||
can_add_contact_ = false;
|
||||
can_block_user_ = false;
|
||||
can_unarchive_ = false;
|
||||
}
|
||||
}
|
||||
if (can_block_user) {
|
||||
CHECK(!can_report_location);
|
||||
CHECK(!can_invite_members);
|
||||
CHECK(!can_share_phone_number);
|
||||
if (can_block_user_) {
|
||||
CHECK(!can_report_location_);
|
||||
CHECK(!can_invite_members_);
|
||||
CHECK(!can_share_phone_number_);
|
||||
if (dialog_type != DialogType::User) {
|
||||
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;
|
||||
can_report_spam = true;
|
||||
can_add_contact = true;
|
||||
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_;
|
||||
can_report_spam_ = true;
|
||||
can_add_contact_ = true;
|
||||
}
|
||||
}
|
||||
if (can_add_contact) {
|
||||
CHECK(!can_report_location);
|
||||
CHECK(!can_invite_members);
|
||||
CHECK(!can_share_phone_number);
|
||||
if (can_add_contact_) {
|
||||
CHECK(!can_report_location_);
|
||||
CHECK(!can_invite_members_);
|
||||
CHECK(!can_share_phone_number_);
|
||||
if (dialog_type != DialogType::User) {
|
||||
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;
|
||||
can_report_spam = false;
|
||||
can_block_user = false;
|
||||
can_unarchive = false;
|
||||
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_;
|
||||
can_report_spam_ = false;
|
||||
can_block_user_ = false;
|
||||
can_unarchive_ = false;
|
||||
}
|
||||
}
|
||||
if (!can_block_user) {
|
||||
distance = -1;
|
||||
if (!can_block_user_) {
|
||||
distance_ = -1;
|
||||
}
|
||||
if (!can_report_spam) {
|
||||
can_unarchive = false;
|
||||
if (!can_report_spam_) {
|
||||
can_unarchive_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::ChatActionBar> DialogActionBar::get_chat_action_bar_object(DialogType dialog_type,
|
||||
bool hide_unarchive) const {
|
||||
if (can_report_location) {
|
||||
if (can_report_location_) {
|
||||
CHECK(dialog_type == DialogType::Channel);
|
||||
CHECK(!can_share_phone_number && !can_block_user && !can_add_contact && !can_report_spam && !can_invite_members);
|
||||
CHECK(!can_share_phone_number_ && !can_block_user_ && !can_add_contact_ && !can_report_spam_ &&
|
||||
!can_invite_members_);
|
||||
return td_api::make_object<td_api::chatActionBarReportUnrelatedLocation>();
|
||||
}
|
||||
if (can_invite_members) {
|
||||
CHECK(!can_share_phone_number && !can_block_user && !can_add_contact && !can_report_spam);
|
||||
if (can_invite_members_) {
|
||||
CHECK(!can_share_phone_number_ && !can_block_user_ && !can_add_contact_ && !can_report_spam_);
|
||||
return td_api::make_object<td_api::chatActionBarInviteMembers>();
|
||||
}
|
||||
if (can_share_phone_number) {
|
||||
if (can_share_phone_number_) {
|
||||
CHECK(dialog_type == DialogType::User);
|
||||
CHECK(!can_block_user && !can_add_contact && !can_report_spam);
|
||||
CHECK(!can_block_user_ && !can_add_contact_ && !can_report_spam_);
|
||||
return td_api::make_object<td_api::chatActionBarSharePhoneNumber>();
|
||||
}
|
||||
if (hide_unarchive) {
|
||||
if (can_add_contact) {
|
||||
if (can_add_contact_) {
|
||||
return td_api::make_object<td_api::chatActionBarAddContact>();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (can_block_user) {
|
||||
if (can_block_user_) {
|
||||
CHECK(dialog_type == DialogType::User);
|
||||
CHECK(can_report_spam && can_add_contact);
|
||||
return td_api::make_object<td_api::chatActionBarReportAddBlock>(can_unarchive, distance);
|
||||
CHECK(can_report_spam_ && can_add_contact_);
|
||||
return td_api::make_object<td_api::chatActionBarReportAddBlock>(can_unarchive_, distance_);
|
||||
}
|
||||
if (can_add_contact) {
|
||||
if (can_add_contact_) {
|
||||
CHECK(dialog_type == DialogType::User);
|
||||
CHECK(!can_report_spam);
|
||||
CHECK(!can_report_spam_);
|
||||
return td_api::make_object<td_api::chatActionBarAddContact>();
|
||||
}
|
||||
if (can_report_spam) {
|
||||
return td_api::make_object<td_api::chatActionBarReportSpam>(can_unarchive);
|
||||
if (can_report_spam_) {
|
||||
return td_api::make_object<td_api::chatActionBarReportSpam>(can_unarchive_);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool DialogActionBar::on_dialog_unarchived() {
|
||||
if (!can_unarchive) {
|
||||
if (!can_unarchive_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
can_unarchive = false;
|
||||
can_report_spam = false;
|
||||
can_block_user = false;
|
||||
// keep can_add_contact
|
||||
can_unarchive_ = false;
|
||||
can_report_spam_ = false;
|
||||
can_block_user_ = false;
|
||||
// keep can_add_contact_
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DialogActionBar::on_user_contact_added() {
|
||||
if (!can_block_user && !can_add_contact) {
|
||||
if (!can_block_user_ && !can_add_contact_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
can_block_user = false;
|
||||
can_add_contact = false;
|
||||
// keep can_unarchive
|
||||
distance = -1;
|
||||
can_block_user_ = false;
|
||||
can_add_contact_ = false;
|
||||
// keep can_unarchive_
|
||||
distance_ = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DialogActionBar::on_user_deleted() {
|
||||
if (!can_share_phone_number && !can_block_user && !can_add_contact && distance < 0) {
|
||||
if (!can_share_phone_number_ && !can_block_user_ && !can_add_contact_ && distance_ < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
can_share_phone_number = false;
|
||||
can_block_user = false;
|
||||
can_add_contact = false;
|
||||
distance = -1;
|
||||
can_share_phone_number_ = false;
|
||||
can_block_user_ = false;
|
||||
can_add_contact_ = false;
|
||||
distance_ = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DialogActionBar::on_outgoing_message() {
|
||||
if (distance < 0) {
|
||||
if (distance_ < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
distance = -1;
|
||||
distance_ = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -239,10 +240,10 @@ bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogA
|
||||
if (rhs == nullptr) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
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_;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -17,23 +17,34 @@ namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
struct DialogActionBar {
|
||||
int32 distance = -1; // distance to the peer
|
||||
class DialogActionBar {
|
||||
int32 distance_ = -1; // distance to the peer
|
||||
|
||||
bool can_report_spam = false;
|
||||
bool can_add_contact = false;
|
||||
bool can_block_user = false;
|
||||
bool can_share_phone_number = false;
|
||||
bool can_report_location = false;
|
||||
bool can_unarchive = false;
|
||||
bool can_invite_members = false;
|
||||
bool can_report_spam_ = false;
|
||||
bool can_add_contact_ = false;
|
||||
bool can_block_user_ = false;
|
||||
bool can_share_phone_number_ = false;
|
||||
bool can_report_location_ = false;
|
||||
bool can_unarchive_ = false;
|
||||
bool can_invite_members_ = 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);
|
||||
|
||||
bool is_empty() const;
|
||||
|
||||
bool can_report_spam() const {
|
||||
return can_report_spam_;
|
||||
}
|
||||
|
||||
bool can_unarchive() const {
|
||||
return can_unarchive_;
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::ChatActionBar> get_chat_action_bar_object(DialogType dialog_type,
|
||||
bool hide_unarchive) const;
|
||||
|
||||
@ -49,19 +60,19 @@ struct DialogActionBar {
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
bool has_distance = distance >= 0;
|
||||
bool has_distance = distance_ >= 0;
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(can_report_spam);
|
||||
STORE_FLAG(can_add_contact);
|
||||
STORE_FLAG(can_block_user);
|
||||
STORE_FLAG(can_share_phone_number);
|
||||
STORE_FLAG(can_report_location);
|
||||
STORE_FLAG(can_unarchive);
|
||||
STORE_FLAG(can_invite_members);
|
||||
STORE_FLAG(can_report_spam_);
|
||||
STORE_FLAG(can_add_contact_);
|
||||
STORE_FLAG(can_block_user_);
|
||||
STORE_FLAG(can_share_phone_number_);
|
||||
STORE_FLAG(can_report_location_);
|
||||
STORE_FLAG(can_unarchive_);
|
||||
STORE_FLAG(can_invite_members_);
|
||||
STORE_FLAG(has_distance);
|
||||
END_STORE_FLAGS();
|
||||
if (has_distance) {
|
||||
td::store(distance, storer);
|
||||
td::store(distance_, storer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,17 +80,17 @@ struct DialogActionBar {
|
||||
void parse(ParserT &parser) {
|
||||
bool has_distance;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(can_report_spam);
|
||||
PARSE_FLAG(can_add_contact);
|
||||
PARSE_FLAG(can_block_user);
|
||||
PARSE_FLAG(can_share_phone_number);
|
||||
PARSE_FLAG(can_report_location);
|
||||
PARSE_FLAG(can_unarchive);
|
||||
PARSE_FLAG(can_invite_members);
|
||||
PARSE_FLAG(can_report_spam_);
|
||||
PARSE_FLAG(can_add_contact_);
|
||||
PARSE_FLAG(can_block_user_);
|
||||
PARSE_FLAG(can_share_phone_number_);
|
||||
PARSE_FLAG(can_report_location_);
|
||||
PARSE_FLAG(can_unarchive_);
|
||||
PARSE_FLAG(can_invite_members_);
|
||||
PARSE_FLAG(has_distance);
|
||||
END_PARSE_FLAGS();
|
||||
if (has_distance) {
|
||||
td::parse(distance, parser);
|
||||
td::parse(distance_, parser);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -8151,7 +8151,7 @@ void MessagesManager::report_dialog(DialogId dialog_id, const vector<MessageId>
|
||||
}
|
||||
}
|
||||
is_dialog_spam_report = user_d->know_action_bar;
|
||||
can_report_spam = user_d->action_bar != nullptr && user_d->action_bar->can_report_spam;
|
||||
can_report_spam = user_d->action_bar != nullptr && user_d->action_bar->can_report_spam();
|
||||
}
|
||||
|
||||
if (is_dialog_spam_report && can_report_spam) {
|
||||
@ -30372,7 +30372,7 @@ void MessagesManager::do_set_dialog_folder_id(Dialog *d, FolderId folder_id) {
|
||||
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
|
||||
if (d->is_update_new_chat_sent && user_id.is_valid()) {
|
||||
const Dialog *user_d = get_dialog(DialogId(user_id));
|
||||
if (user_d != nullptr && user_d->action_bar != nullptr && user_d->action_bar->can_unarchive) {
|
||||
if (user_d != nullptr && user_d->action_bar != nullptr && user_d->action_bar->can_unarchive()) {
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateChatActionBar>(d->dialog_id.get(), get_chat_action_bar_object(d)));
|
||||
|
@ -86,7 +86,7 @@ namespace td {
|
||||
|
||||
struct BinlogEvent;
|
||||
struct Dependencies;
|
||||
struct DialogActionBar;
|
||||
class DialogActionBar;
|
||||
class DialogFilter;
|
||||
class DraftMessage;
|
||||
struct InputMessageContent;
|
||||
|
Loading…
Reference in New Issue
Block a user