Allow read access to linked channels.

GitOrigin-RevId: 24003a60c80a8e61354ba647fb616e92f88c6e48
This commit is contained in:
levlam 2019-09-13 05:40:02 +03:00
parent 4cd9255643
commit 9bf6b2c78a
3 changed files with 23 additions and 11 deletions

View File

@ -2951,20 +2951,21 @@ tl_object_ptr<telegram_api::InputPeer> ContactsManager::get_input_peer_chat(Chat
bool ContactsManager::have_input_peer_channel(ChannelId channel_id, AccessRights access_rights) const {
const Channel *c = get_channel(channel_id);
return have_input_peer_channel(c, access_rights);
return have_input_peer_channel(c, channel_id, access_rights);
}
tl_object_ptr<telegram_api::InputPeer> ContactsManager::get_input_peer_channel(ChannelId channel_id,
AccessRights access_rights) const {
const Channel *c = get_channel(channel_id);
if (!have_input_peer_channel(c, access_rights)) {
if (!have_input_peer_channel(c, channel_id, access_rights)) {
return nullptr;
}
return make_tl_object<telegram_api::inputPeerChannel>(channel_id.get(), c->access_hash);
}
bool ContactsManager::have_input_peer_channel(const Channel *c, AccessRights access_rights) {
bool ContactsManager::have_input_peer_channel(const Channel *c, ChannelId channel_id, AccessRights access_rights,
bool from_linked) const {
if (c == nullptr) {
return false;
}
@ -2974,9 +2975,18 @@ bool ContactsManager::have_input_peer_channel(const Channel *c, AccessRights acc
if (c->status.is_banned()) {
return false;
}
if (!c->username.empty() && access_rights == AccessRights::Read) {
if (access_rights == AccessRights::Read) {
if (!c->username.empty()) {
return true;
}
if (!from_linked && c->has_linked_channel) {
auto channel_full = get_channel_full(channel_id);
if (channel_full == nullptr || have_input_peer_channel(get_channel(channel_full->linked_channel_id),
channel_full->linked_channel_id, access_rights, true)) {
return true;
}
}
}
if (!c->status.is_member()) {
return false;
}
@ -6476,7 +6486,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
save_channel(c, channel_id, from_binlog);
}
bool have_read_access = have_input_peer_channel(c, AccessRights::Read);
bool have_read_access = have_input_peer_channel(c, channel_id, AccessRights::Read);
bool is_member = c->status.is_member();
if (c->had_read_access && !have_read_access) {
send_closure_later(G()->messages_manager(), &MessagesManager::delete_dialog, DialogId(channel_id));
@ -6488,8 +6498,8 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
c->had_read_access = have_read_access;
c->was_member = is_member;
if (c->cache_version != Channel::CACHE_VERSION && !c->is_repaired && have_input_peer_channel(c, AccessRights::Read) &&
!G()->close_flag()) {
if (c->cache_version != Channel::CACHE_VERSION && !c->is_repaired &&
have_input_peer_channel(c, channel_id, AccessRights::Read) && !G()->close_flag()) {
c->is_repaired = true;
LOG(INFO) << "Repairing cache of " << channel_id;
@ -7718,7 +7728,7 @@ bool ContactsManager::on_get_channel_error(ChannelId channel_id, const Status &s
on_update_channel_username(c, channel_id, "");
update_channel(c, channel_id);
}
LOG_IF(ERROR, have_input_peer_channel(c, AccessRights::Read))
LOG_IF(ERROR, have_input_peer_channel(c, channel_id, AccessRights::Read))
<< "Have read access to channel after receiving CHANNEL_PRIVATE. Channel state: "
<< oneline(to_string(get_supergroup_object(channel_id, c)))
<< ". Previous channel state: " << debug_channel_object;

View File

@ -843,7 +843,8 @@ class ContactsManager : public Actor {
static bool have_input_peer_user(const User *u, AccessRights access_rights);
static bool have_input_peer_chat(const Chat *c, AccessRights access_rights);
static bool have_input_peer_channel(const Channel *c, AccessRights access_rights);
bool have_input_peer_channel(const Channel *c, ChannelId channel_id, AccessRights access_rights,
bool from_linked = false) const;
static bool have_input_encrypted_peer(const SecretChat *secret_chat, AccessRights access_rights);
const User *get_user(UserId user_id) const;

View File

@ -26307,6 +26307,7 @@ MessagesManager::Dialog *MessagesManager::on_load_dialog_from_database(DialogId
return old_d;
}
LOG(INFO) << "Add new " << dialog_id << " from database";
return add_new_dialog(parse_dialog(dialog_id, value), true);
}