Avoid sending access hash multiple times if the database is enabled

This commit is contained in:
Andrea Cavalli 2021-08-24 18:31:08 +02:00
parent 268fd8c4a9
commit de789b0d2f

View File

@ -8283,15 +8283,19 @@ class ContactsManager::UserLogEvent {
};
void ContactsManager::save_user(User *u, UserId user_id, bool from_binlog) {
if (u != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_user_access_hash_object(user_id, u)));
}
if (!G()->parameters().use_chat_info_db) {
if (u != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_user_access_hash_object(user_id, u)));
}
return;
}
CHECK(u != nullptr);
if (!u->is_saved || !u->is_status_saved) { // TODO more effective handling of !u->is_status_saved
if (u != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_user_access_hash_object(user_id, u)));
}
if (!from_binlog) {
auto log_event = UserLogEvent(user_id, *u);
auto storer = get_log_event_storer(log_event);
@ -8825,15 +8829,19 @@ class ContactsManager::ChannelLogEvent {
};
void ContactsManager::save_channel(Channel *c, ChannelId channel_id, bool from_binlog) {
if (c != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_channel_access_hash_object(channel_id, c)));
}
if (!G()->parameters().use_chat_info_db) {
if (c != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_channel_access_hash_object(channel_id, c)));
}
return;
}
CHECK(c != nullptr);
if (!c->is_saved) {
if (c != nullptr && G()->shared_config().get_option_boolean("receive_access_hashes", false)) {
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAccessHash>(get_channel_access_hash_object(channel_id, c)));
}
if (!from_binlog) {
auto log_event = ChannelLogEvent(channel_id, *c);
auto storer = get_log_event_storer(log_event);