From 46ed86557099332400f22fccd2ee88ddff362e98 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 7 Dec 2019 23:38:05 +0300 Subject: [PATCH] Add chatAdministrator.is_owner. GitOrigin-RevId: 8ba5a2e7b175cb5595a4d26e8050311960063938 --- td/generate/scheme/td_api.tl | 6 +++--- td/generate/scheme/td_api.tlo | Bin 165104 -> 165140 bytes td/telegram/ContactsManager.cpp | 22 ++++++++++++++-------- td/telegram/DialogAdministrator.cpp | 4 ++-- td/telegram/DialogAdministrator.h | 13 +++++++++++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 21579e7c..c1b13fb6 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -320,8 +320,8 @@ userProfilePhotos total_count:int32 photos:vector = UserProfil users total_count:int32 user_ids:vector = Users; -//@description Contains information about a chat administrator @user_id User identifier of the administrator @custom_title Custom title of the administrator -chatAdministrator user_id:int32 custom_title:string = ChatAdministrator; +//@description Contains information about a chat administrator @user_id User identifier of the administrator @custom_title Custom title of the administrator @is_owner True, if the user is the owner of the chat +chatAdministrator user_id:int32 custom_title:string is_owner:Bool = ChatAdministrator; //@description Represents a list of chat administrators @administrators A list of chat administrators chatAdministrators administrators:vector = ChatAdministrators; @@ -3564,7 +3564,7 @@ setChatMemberStatus chat_id:int53 user_id:int32 status:ChatMemberStatus = Ok; //@description Checks whether the current session can be used to transfer a chat ownership to another user canTransferOwnership = CanTransferOwnershipResult; -//@description Changes owner of a chat. The current user must be a current owner of the chat. Use the method canTransferOwnership to check whether the ownership can be transferred from the current session. Available only for supergroups and channel chats +//@description Changes the owner of a chat. The current user must be a current owner of the chat. Use the method canTransferOwnership to check whether the ownership can be transferred from the current session. Available only for supergroups and channel chats //@chat_id Chat identifier @user_id Identifier of the user to which transfer the ownership. The ownership can't be transferred to a bot or to a deleted user @password The password of the current user transferChatOwnership chat_id:int53 user_id:int32 password:string = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 1cec874059b73e07ea88fcb7ed5bd8c5a30cca1c..29e64297c8dadd580f1b9fec7797e50867ba8218 100644 GIT binary patch delta 101 zcmey+$u*^mYr_;)mUC%bvYThH-tm(Gu>_Md5=$IYax?QXi%W_UOY(~t7(n9F8*Ve| wOx_csGWmlAD@SH=e13UeYSHA2PvpS{OnwuR0A@4?gtiBSGHwqDWm=#Q0LphJpa1{> delta 97 zcmbQz#r2_+Yr_;)mQypnet_query_creator().create(create_storer(telegram_api::channels_getParticipants( @@ -2537,7 +2537,8 @@ class GetChannelAdministratorsQuery : public Td::ResultHandler { << " as an administrator of " << channel_id_; continue; } - administrators.emplace_back(dialog_participant.user_id, dialog_participant.status.get_rank()); + administrators.emplace_back(dialog_participant.user_id, dialog_participant.status.get_rank(), + dialog_participant.status.is_creator()); } td->contacts_manager_->on_update_channel_administrator_count(channel_id_, @@ -8037,7 +8038,7 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, bool for (const auto &participant : chat_full->participants) { auto user_id = participant.user_id; if (participant.status.is_administrator()) { - administrators.emplace_back(user_id, participant.status.get_rank()); + administrators.emplace_back(user_id, participant.status.get_rank(), participant.status.is_creator()); } if (is_user_bot(user_id)) { bot_user_ids.push_back(user_id); @@ -9356,7 +9357,8 @@ void ContactsManager::on_get_channel_participants_success( if (filter.is_recent()) { for (const auto &participant : result) { if (participant.status.is_administrator()) { - administrators.emplace_back(participant.user_id, participant.status.get_rank()); + administrators.emplace_back(participant.user_id, participant.status.get_rank(), + participant.status.is_creator()); } if (is_user_bot(participant.user_id)) { bot_user_ids.push_back(participant.user_id); @@ -9370,7 +9372,8 @@ void ContactsManager::on_get_channel_participants_success( } } else if (filter.is_administrators()) { for (const auto &participant : result) { - administrators.emplace_back(participant.user_id, participant.status.get_rank()); + administrators.emplace_back(participant.user_id, participant.status.get_rank(), + participant.status.is_creator()); } } else if (filter.is_bots()) { bot_user_ids = transform(result, [](const DialogParticipant &participant) { return participant.user_id; }); @@ -9557,15 +9560,16 @@ void ContactsManager::speculative_add_channel_user(ChannelId channel_id, UserId for (auto &administrator : administrators) { if (administrator.get_user_id() == user_id) { is_found = true; - if (administrator.get_rank() != new_status.get_rank()) { - administrator = DialogAdministrator(user_id, new_status.get_rank()); + if (administrator.get_rank() != new_status.get_rank() || + administrator.is_creator() != new_status.is_creator()) { + administrator = DialogAdministrator(user_id, new_status.get_rank(), new_status.is_creator()); on_update_dialog_administrators(dialog_id, std::move(administrators), true); } break; } } if (!is_found) { - administrators.emplace_back(user_id, new_status.get_rank()); + administrators.emplace_back(user_id, new_status.get_rank(), new_status.is_creator()); on_update_dialog_administrators(dialog_id, std::move(administrators), true); } } else { @@ -10506,6 +10510,8 @@ void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, if (input_channel != nullptr) { send_get_channel_full_query(nullptr, channel_id, std::move(input_channel), Auto(), "update channel owner"); } + + reload_dialog_administrators(DialogId(channel_id), 0, Auto()); } } } diff --git a/td/telegram/DialogAdministrator.cpp b/td/telegram/DialogAdministrator.cpp index 583bf6e0..0107e562 100644 --- a/td/telegram/DialogAdministrator.cpp +++ b/td/telegram/DialogAdministrator.cpp @@ -15,12 +15,12 @@ td_api::object_ptr DialogAdministrator::get_chat_admi CHECK(contacts_manager != nullptr); CHECK(user_id_.is_valid()); return td_api::make_object( - contacts_manager->get_user_id_object(user_id_, "get_chat_administrator_object"), rank_); + contacts_manager->get_user_id_object(user_id_, "get_chat_administrator_object"), rank_, is_creator_); } StringBuilder &operator<<(StringBuilder &string_builder, const DialogAdministrator &administrator) { return string_builder << "DialogAdministrator[" << administrator.user_id_ << ", title = " << administrator.rank_ - << "]"; + << ", is_owner = " << administrator.is_creator_ << "]"; } } // namespace td diff --git a/td/telegram/DialogAdministrator.h b/td/telegram/DialogAdministrator.h index 8dc3ff3d..468e28fb 100644 --- a/td/telegram/DialogAdministrator.h +++ b/td/telegram/DialogAdministrator.h @@ -20,13 +20,15 @@ class ContactsManager; class DialogAdministrator { UserId user_id_; string rank_; + bool is_creator_ = false; friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogAdministrator &location); public: DialogAdministrator() = default; - DialogAdministrator(UserId user_id, const string &rank) : user_id_(user_id), rank_(rank) { + DialogAdministrator(UserId user_id, const string &rank, bool is_creator) + : user_id_(user_id), rank_(rank), is_creator_(is_creator) { } td_api::object_ptr get_chat_administrator_object( @@ -40,12 +42,17 @@ class DialogAdministrator { return rank_; } + bool is_creator() const { + return is_creator_; + } + template void store(StorerT &storer) const { using td::store; bool has_rank = !rank_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_rank); + STORE_FLAG(is_creator_); END_STORE_FLAGS(); store(user_id_, storer); if (has_rank) { @@ -59,6 +66,7 @@ class DialogAdministrator { bool has_rank; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_rank); + PARSE_FLAG(is_creator_); END_PARSE_FLAGS(); parse(user_id_, parser); if (has_rank) { @@ -68,7 +76,8 @@ class DialogAdministrator { }; inline bool operator==(const DialogAdministrator &lhs, const DialogAdministrator &rhs) { - return lhs.get_user_id() == rhs.get_user_id() && lhs.get_rank() == rhs.get_rank(); + return lhs.get_user_id() == rhs.get_user_id() && lhs.get_rank() == rhs.get_rank() && + lhs.is_creator() == rhs.is_creator(); } inline bool operator!=(const DialogAdministrator &lhs, const DialogAdministrator &rhs) {