diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index b908d8528..03a50c28f 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -607,8 +607,8 @@ channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant; channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant; channelParticipantCreator#447dca4b flags:# user_id:int admin_rights:ChatAdminRights rank:flags.0?string = ChannelParticipant; channelParticipantAdmin#ccbebbaf flags:# can_edit:flags.0?true self:flags.1?true user_id:int inviter_id:flags.1?int promoted_by:int date:int admin_rights:ChatAdminRights rank:flags.2?string = ChannelParticipant; -channelParticipantBanned#1c0facaf flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; -channelParticipantLeft#c3c6796b user_id:int = ChannelParticipant; +channelParticipantBanned#50a1dfd6 flags:# left:flags.0?true peer:Peer kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; +channelParticipantLeft#1b03f006 peer:Peer = ChannelParticipant; channelParticipantsRecent#de3f3c79 = ChannelParticipantsFilter; channelParticipantsAdmins#b4608969 = ChannelParticipantsFilter; @@ -619,10 +619,10 @@ channelParticipantsSearch#656ac4b q:string = ChannelParticipantsFilter; channelParticipantsContacts#bb6ae88d q:string = ChannelParticipantsFilter; channelParticipantsMentions#e04b5ceb flags:# q:flags.0?string top_msg_id:flags.1?int = ChannelParticipantsFilter; -channels.channelParticipants#f56ee2a8 count:int participants:Vector users:Vector = channels.ChannelParticipants; +channels.channelParticipants#9ab0feaf count:int participants:Vector chats:Vector users:Vector = channels.ChannelParticipants; channels.channelParticipantsNotModified#f0173fe9 = channels.ChannelParticipants; -channels.channelParticipant#d0d9b163 participant:ChannelParticipant users:Vector = channels.ChannelParticipant; +channels.channelParticipant#dfb80317 participant:ChannelParticipant chats:Vector users:Vector = channels.ChannelParticipant; help.termsOfService#780a0310 flags:# popup:flags.0?true id:DataJSON text:string entities:Vector min_age_confirm:flags.1?int = help.TermsOfService; @@ -1544,7 +1544,7 @@ channels.deleteUserHistory#d10dd71b channel:InputChannel user_id:InputUser = mes channels.reportSpam#fe087810 channel:InputChannel user_id:InputUser id:Vector = Bool; channels.getMessages#ad8c9a23 channel:InputChannel id:Vector = messages.Messages; channels.getParticipants#123e05e9 channel:InputChannel filter:ChannelParticipantsFilter offset:int limit:int hash:int = channels.ChannelParticipants; -channels.getParticipant#546dd7a6 channel:InputChannel user_id:InputUser = channels.ChannelParticipant; +channels.getParticipant#a0ab6cc6 channel:InputChannel participant:InputPeer = channels.ChannelParticipant; channels.getChannels#a7f6bbb id:Vector = messages.Chats; channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull; channels.createChannel#3d5fb10f flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string = Updates; @@ -1560,7 +1560,7 @@ channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; channels.exportMessageLink#e63fadeb flags:# grouped:flags.0?true thread:flags.1?true channel:InputChannel id:int = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.getAdminedPublicChannels#f8b036af flags:# by_location:flags.0?true check_limit:flags.1?true = messages.Chats; -channels.editBanned#72796912 channel:InputChannel user_id:InputUser banned_rights:ChatBannedRights = Updates; +channels.editBanned#96e6cd81 channel:InputChannel participant:InputPeer banned_rights:ChatBannedRights = Updates; channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector max_id:long min_id:long limit:int = channels.AdminLogResults; channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = Bool; channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ef5230fa8..9035a6bbd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2346,12 +2346,12 @@ class EditChannelBannedQuery : public Td::ResultHandler { explicit EditChannelBannedQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(ChannelId channel_id, tl_object_ptr &&input_user, DialogParticipantStatus status) { + void send(ChannelId channel_id, tl_object_ptr &&input_peer, DialogParticipantStatus status) { channel_id_ = channel_id; auto input_channel = td->contacts_manager_->get_input_channel(channel_id); CHECK(input_channel != nullptr); send_query(G()->net_query_creator().create(telegram_api::channels_editBanned( - std::move(input_channel), std::move(input_user), status.get_chat_banned_rights()))); + std::move(input_channel), std::move(input_peer), status.get_chat_banned_rights()))); } void on_result(uint64 id, BufferSlice packet) override { @@ -2911,18 +2911,18 @@ class GetChannelParticipantQuery : public Td::ResultHandler { explicit GetChannelParticipantQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(ChannelId channel_id, UserId user_id, tl_object_ptr &&input_user) { + void send(ChannelId channel_id, UserId user_id, tl_object_ptr &&input_peer) { auto input_channel = td->contacts_manager_->get_input_channel(channel_id); if (input_channel == nullptr) { return promise_.set_error(Status::Error(3, "Supergroup not found")); } - CHECK(input_user != nullptr); + CHECK(input_peer != nullptr); channel_id_ = channel_id; user_id_ = user_id; send_query(G()->net_query_creator().create( - telegram_api::channels_getParticipant(std::move(input_channel), std::move(input_user)))); + telegram_api::channels_getParticipant(std::move(input_channel), std::move(input_peer)))); } void on_result(uint64 id, BufferSlice packet) override { @@ -2935,6 +2935,7 @@ class GetChannelParticipantQuery : public Td::ResultHandler { LOG(INFO) << "Receive result for GetChannelParticipantQuery: " << to_string(participant); td->contacts_manager_->on_get_users(std::move(participant->users_), "GetChannelParticipantQuery"); + td->contacts_manager_->on_get_chats(std::move(participant->chats_), "GetChannelParticipantQuery"); DialogParticipant result(std::move(participant->participant_)); if (!result.is_valid()) { LOG(ERROR) << "Receive invalid " << result; @@ -3035,6 +3036,7 @@ class GetChannelAdministratorsQuery : public Td::ResultHandler { case telegram_api::channels_channelParticipants::ID: { auto participants = telegram_api::move_object_as(participants_ptr); td->contacts_manager_->on_get_users(std::move(participants->users_), "GetChannelAdministratorsQuery"); + td->contacts_manager_->on_get_chats(std::move(participants->chats_), "GetChannelAdministratorsQuery"); vector administrators; administrators.reserve(participants->participants_.size()); for (auto &participant : participants->participants_) { @@ -4530,6 +4532,10 @@ tl_object_ptr ContactsManager::get_input_peer_user(User } const User *u = get_user(user_id); if (!have_input_peer_user(u, access_rights)) { + if ((u == nullptr || u->access_hash == -1 || u->is_min_access_hash) && td_->auth_manager_->is_bot() && + user_id.is_valid()) { + return make_tl_object(user_id.get(), 0); + } return nullptr; } @@ -6842,8 +6848,8 @@ void ContactsManager::change_channel_participant_status(ChannelId channel_id, Us return promise.set_error(Status::Error(6, "Chat info not found")); } - auto input_user = get_input_user(user_id); - if (input_user == nullptr) { + auto input_peer = get_input_peer_user(user_id, AccessRights::Read); + if (input_peer == nullptr) { return promise.set_error(Status::Error(6, "User not found")); } @@ -6866,7 +6872,7 @@ void ContactsManager::change_channel_participant_status(ChannelId channel_id, Us }); td_->create_handler(std::move(on_result_promise)) - ->send(channel_id, user_id, std::move(input_user)); + ->send(channel_id, user_id, std::move(input_peer)); } void ContactsManager::change_channel_participant_status_impl(ChannelId channel_id, UserId user_id, @@ -7390,8 +7396,8 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, UserId return promise.set_error(Status::Error(3, "Not in the chat")); } } - auto input_user = get_input_user(user_id); - if (input_user == nullptr) { + auto input_peer = get_input_peer_user(user_id, AccessRights::Read); + if (input_peer == nullptr) { return promise.set_error(Status::Error(3, "User not found")); } @@ -7442,7 +7448,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, UserId } speculative_add_channel_user(channel_id, user_id, status, old_status); - td_->create_handler(std::move(promise))->send(channel_id, std::move(input_user), status); + td_->create_handler(std::move(promise))->send(channel_id, std::move(input_peer), status); } ChannelId ContactsManager::migrate_chat_to_megagroup(ChatId chat_id, Promise &promise) { @@ -11591,6 +11597,7 @@ void ContactsManager::on_get_channel_participants( } on_get_users(std::move(channel_participants->users_), "on_get_channel_participants"); + on_get_chats(std::move(channel_participants->chats_), "on_get_channel_participants"); int32 total_count = channel_participants->count_; auto participants = std::move(channel_participants->participants_); LOG(INFO) << "Receive " << participants.size() << " members in " << channel_id; @@ -14763,8 +14770,8 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id, return result; } - auto input_user = get_input_user(user_id); - if (input_user == nullptr) { + auto input_peer = get_input_peer_user(user_id, AccessRights::Read); + if (input_peer == nullptr) { promise.set_error(Status::Error(6, "User not found")); return DialogParticipant(); } @@ -14776,7 +14783,7 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id, if (force) { LOG(ERROR) << "Can't find cached BotInfo"; } else { - send_get_user_full_query(user_id, std::move(input_user), std::move(promise), "get_channel_participant"); + send_get_user_full_query(user_id, get_input_user(user_id), std::move(promise), "get_channel_participant"); return DialogParticipant(); } } @@ -14807,7 +14814,7 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id, }); td_->create_handler(std::move(on_result_promise)) - ->send(channel_id, user_id, std::move(input_user)); + ->send(channel_id, user_id, std::move(input_peer)); return DialogParticipant(); } diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index 339ea3a37..28a069f05 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -683,6 +683,15 @@ DialogParticipant::DialogParticipant(tl_object_ptr &&participant_ptr) { CHECK(participant_ptr != nullptr); + + auto get_peer_user_id = [](const tl_object_ptr &peer) { + DialogId dialog_id(peer); + if (dialog_id.get_type() == DialogType::User) { + return dialog_id.get_user_id(); + } + return UserId(); + }; + switch (participant_ptr->get_id()) { case telegram_api::channelParticipant::ID: { auto participant = move_tl_object_as(participant_ptr); @@ -712,13 +721,13 @@ DialogParticipant::DialogParticipant(tl_object_ptr(participant_ptr); - *this = {UserId(participant->user_id_), UserId(), 0, DialogParticipantStatus::Left()}; + *this = {get_peer_user_id(participant->peer_), UserId(), 0, DialogParticipantStatus::Left()}; break; } case telegram_api::channelParticipantBanned::ID: { auto participant = move_tl_object_as(participant_ptr); auto is_member = (participant->flags_ & telegram_api::channelParticipantBanned::LEFT_MASK) == 0; - *this = {UserId(participant->user_id_), UserId(participant->kicked_by_), participant->date_, + *this = {get_peer_user_id(participant->peer_), UserId(participant->kicked_by_), participant->date_, get_dialog_participant_status(is_member, std::move(participant->banned_rights_))}; break; } diff --git a/td/telegram/Version.h b/td/telegram/Version.h index 86bbcc059..4a54ad214 100644 --- a/td/telegram/Version.h +++ b/td/telegram/Version.h @@ -8,7 +8,7 @@ namespace td { -constexpr int32 MTPROTO_LAYER = 125; +constexpr int32 MTPROTO_LAYER = 126; enum class Version : int32 { Initial, // 0