Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-12-21 19:58:06 +01:00
commit 27898cfb16
3 changed files with 42 additions and 23 deletions

View File

@ -13423,8 +13423,10 @@ void ContactsManager::on_channel_status_changed(Channel *c, ChannelId channel_id
if (old_status.is_member() != new_status.is_member() || new_status.is_banned()) {
remove_dialog_access_by_invite_link(DialogId(channel_id));
if (new_status.is_member()) {
reload_channel_full(channel_id, Promise<Unit>(), "on_channel_status_changed");
if (new_status.is_member() || new_status.is_creator()) {
reload_channel_full(channel_id,
PromiseCreator::lambda([channel_id](Unit) { LOG(INFO) << "Reloaded full " << channel_id; }),
"on_channel_status_changed");
}
}
if (need_reload_group_call) {

View File

@ -5305,8 +5305,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
bool has_flags3 = true;
bool has_pending_join_requests = pending_join_request_count != 0;
bool has_action_bar = action_bar != nullptr;
bool has_default_send_message_as_dialog_id =
default_send_message_as_dialog_id.is_valid() && !need_drop_default_send_message_as_dialog_id;
bool has_default_send_message_as_dialog_id = default_send_message_as_dialog_id.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_draft_message);
STORE_FLAG(has_last_database_message);
@ -5382,6 +5381,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
STORE_FLAG(need_repair_action_bar);
STORE_FLAG(has_action_bar);
STORE_FLAG(has_default_send_message_as_dialog_id);
STORE_FLAG(need_drop_default_send_message_as_dialog_id);
END_STORE_FLAGS();
}
@ -5620,6 +5620,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
PARSE_FLAG(need_repair_action_bar);
PARSE_FLAG(has_action_bar);
PARSE_FLAG(has_default_send_message_as_dialog_id);
PARSE_FLAG(need_drop_default_send_message_as_dialog_id);
END_PARSE_FLAGS();
} else {
need_repair_action_bar = false;
@ -20198,7 +20199,8 @@ void MessagesManager::open_dialog(Dialog *d) {
CHECK(d->default_send_message_as_dialog_id.is_valid());
d->need_drop_default_send_message_as_dialog_id = false;
d->default_send_message_as_dialog_id = DialogId();
LOG(INFO) << "Set default message sender in " << d->dialog_id << " to " << d->default_send_message_as_dialog_id;
LOG(INFO) << "Set message sender in " << d->dialog_id << " to " << d->default_send_message_as_dialog_id;
on_dialog_updated(dialog_id, "open_dialog");
send_update_chat_default_message_sender_id(d);
}
@ -24295,11 +24297,10 @@ void MessagesManager::set_dialog_default_send_message_as_dialog_id(DialogId dial
}
break;
default:
UNREACHABLE();
return promise.set_error(Status::Error(400, "Invalid default participant identifier specified"));
return promise.set_error(Status::Error(400, "Invalid message sender specified"));
}
if (!have_input_peer(message_sender_dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access specified default message sender chat"));
return promise.set_error(Status::Error(400, "Can't access specified message sender chat"));
}
{
@ -29685,7 +29686,6 @@ void MessagesManager::send_update_chat_default_message_sender_id(const Dialog *d
CHECK(!td_->auth_manager_->is_bot());
CHECK(d != nullptr);
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_default_message_sender_id";
on_dialog_updated(d->dialog_id, "send_update_chat_default_message_sender_id");
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatDefaultMessageSenderId>(d->dialog_id.get(),
get_default_sender_id_object(d)));
@ -31068,7 +31068,7 @@ void MessagesManager::on_update_dialog_default_send_message_as_dialog_id(DialogI
auto dialog_type = dialog_id.get_type();
if (dialog_type != DialogType::Channel || is_broadcast_channel(dialog_id)) {
if (default_send_as_dialog_id != DialogId()) {
LOG(ERROR) << "Receive default sender " << default_send_as_dialog_id << " in " << dialog_id;
LOG(ERROR) << "Receive message sender " << default_send_as_dialog_id << " in " << dialog_id;
}
return;
}
@ -31093,16 +31093,19 @@ void MessagesManager::on_update_dialog_default_send_message_as_dialog_id(DialogI
}
if (d->default_send_message_as_dialog_id != default_send_as_dialog_id) {
if (force || default_send_as_dialog_id.is_valid() || created_public_broadcasts_.empty()) {
LOG(INFO) << "Set default message sender in " << dialog_id << " to " << default_send_as_dialog_id;
if (force || default_send_as_dialog_id.is_valid() ||
(created_public_broadcasts_inited_ && !created_public_broadcasts_.empty())) {
LOG(INFO) << "Set message sender in " << dialog_id << " to " << default_send_as_dialog_id;
d->need_drop_default_send_message_as_dialog_id = false;
d->default_send_message_as_dialog_id = default_send_as_dialog_id;
send_update_chat_default_message_sender_id(d);
} else {
LOG(INFO) << "Postpone removal of message sender in " << dialog_id;
d->need_drop_default_send_message_as_dialog_id = true;
on_dialog_updated(d->dialog_id, "on_update_dialog_default_send_message_as_dialog_id");
}
on_dialog_updated(d->dialog_id, "on_update_dialog_default_send_message_as_dialog_id");
} else if (default_send_as_dialog_id.is_valid() && d->need_drop_default_send_message_as_dialog_id) {
LOG(INFO) << "Don't remove message sender in " << dialog_id;
d->need_drop_default_send_message_as_dialog_id = false;
on_dialog_updated(d->dialog_id, "on_update_dialog_default_send_message_as_dialog_id");
}
@ -34983,6 +34986,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
d->default_join_group_call_as_dialog_id = DialogId();
}
DialogId default_send_message_as_dialog_id = d->default_send_message_as_dialog_id;
bool need_drop_default_send_message_as_dialog_id = d->need_drop_default_send_message_as_dialog_id;
if (default_send_message_as_dialog_id != dialog_id &&
default_send_message_as_dialog_id.get_type() != DialogType::User &&
!have_dialog(default_send_message_as_dialog_id)) {
@ -35029,7 +35033,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
fix_new_dialog(dialog, std::move(last_database_message), last_database_message_id, order, last_clear_history_date,
last_clear_history_message_id, default_join_group_call_as_dialog_id, default_send_message_as_dialog_id,
is_loaded_from_database);
need_drop_default_send_message_as_dialog_id, is_loaded_from_database);
return dialog;
}
@ -35038,7 +35042,8 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
MessageId last_database_message_id, int64 order, int32 last_clear_history_date,
MessageId last_clear_history_message_id,
DialogId default_join_group_call_as_dialog_id,
DialogId default_send_message_as_dialog_id, bool is_loaded_from_database) {
DialogId default_send_message_as_dialog_id,
bool need_drop_default_send_message_as_dialog_id, bool is_loaded_from_database) {
CHECK(d != nullptr);
auto dialog_id = d->dialog_id;
auto dialog_type = dialog_id.get_type();
@ -35190,7 +35195,14 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
pending_add_default_send_message_as_dialog_id_.erase(it);
for (auto &pending_dialog_id : pending_dialog_ids) {
on_update_dialog_default_send_message_as_dialog_id(pending_dialog_id, dialog_id, false);
Dialog *pending_d = get_dialog(pending_dialog_id.first);
CHECK(pending_d != nullptr);
if (!pending_d->default_send_message_as_dialog_id.is_valid()) {
LOG(INFO) << "Set postponed message sender in " << pending_dialog_id << " to " << dialog_id;
pending_d->need_drop_default_send_message_as_dialog_id = pending_dialog_id.second;
pending_d->default_send_message_as_dialog_id = dialog_id;
send_update_chat_default_message_sender_id(pending_d);
}
}
}
}
@ -35281,6 +35293,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
if (default_join_group_call_as_dialog_id != d->default_join_group_call_as_dialog_id) {
CHECK(default_join_group_call_as_dialog_id.is_valid());
CHECK(default_join_group_call_as_dialog_id.get_type() != DialogType::User);
CHECK(!d->default_join_group_call_as_dialog_id.is_valid());
if (!have_dialog(default_join_group_call_as_dialog_id)) {
LOG(INFO) << "Postpone adding of default join voice chat as " << default_join_group_call_as_dialog_id << " in "
@ -35293,13 +35306,17 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
if (default_send_message_as_dialog_id != d->default_send_message_as_dialog_id) {
CHECK(default_send_message_as_dialog_id.is_valid());
CHECK(default_send_message_as_dialog_id.get_type() != DialogType::User);
CHECK(!d->default_send_message_as_dialog_id.is_valid());
if (!have_dialog(default_send_message_as_dialog_id)) {
LOG(INFO) << "Postpone adding of default join voice chat as " << default_send_message_as_dialog_id << " in "
<< dialog_id;
pending_add_default_send_message_as_dialog_id_[default_send_message_as_dialog_id].push_back(dialog_id);
LOG(INFO) << "Postpone setting of message sender " << default_send_message_as_dialog_id << " in " << dialog_id;
pending_add_default_send_message_as_dialog_id_[default_send_message_as_dialog_id].emplace_back(
dialog_id, need_drop_default_send_message_as_dialog_id);
} else {
on_update_dialog_default_send_message_as_dialog_id(dialog_id, default_send_message_as_dialog_id, false);
LOG(INFO) << "Set message sender in " << dialog_id << " to " << default_send_message_as_dialog_id;
d->need_drop_default_send_message_as_dialog_id = need_drop_default_send_message_as_dialog_id;
d->default_send_message_as_dialog_id = default_send_message_as_dialog_id;
send_update_chat_default_message_sender_id(d);
}
}

View File

@ -2585,7 +2585,7 @@ class MessagesManager final : public Actor {
void fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_database_message, MessageId last_database_message_id,
int64 order, int32 last_clear_history_date, MessageId last_clear_history_message_id,
DialogId default_join_group_call_as_dialog_id, DialogId default_send_message_as_dialog_id,
bool is_loaded_from_database);
bool need_drop_default_send_message_as_dialog_id, bool is_loaded_from_database);
void add_dialog_last_database_message(Dialog *d, unique_ptr<Message> &&last_database_message);
@ -3517,8 +3517,8 @@ class MessagesManager final : public Actor {
std::unordered_map<DialogId, vector<DialogId>, DialogIdHash>
pending_add_default_join_group_call_as_dialog_id_; // dialog_id -> dependent dialogs
std::unordered_map<DialogId, vector<DialogId>, DialogIdHash>
pending_add_default_send_message_as_dialog_id_; // dialog_id -> dependent dialogs
std::unordered_map<DialogId, vector<std::pair<DialogId, bool>>, DialogIdHash>
pending_add_default_send_message_as_dialog_id_; // dialog_id -> [dependent dialog, need_drop]
struct MessageIds {
std::unordered_set<MessageId, MessageIdHash> message_ids;