diff --git a/CMakeLists.txt b/CMakeLists.txt index f2fdaf00..a1d5504b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -611,6 +611,7 @@ set(TDLIB_SOURCE td/telegram/PollManager.h td/telegram/PrivacyManager.h td/telegram/PtsManager.h + td/telegram/PublicDialogType.h td/telegram/QueryCombiner.h td/telegram/ReplyMarkup.h td/telegram/RequestActor.h diff --git a/SplitSource.php b/SplitSource.php index 74e454ef..09c6878d 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -274,6 +274,7 @@ function split_file($file, $chunks, $undo) { 'get_erase_logevent_promise|parse_time|store_time' => 'logevent/LogEventHelper', 'messages_manager[_(-][^.]|MessagesManager' => 'MessagesManager', 'notification_manager[_(-][^.]|NotificationManager|notifications[)]' => 'NotificationManager', + 'PublicDialogType|get_public_dialog_type' => 'PublicDialogType', 'SecretChatActor' => 'SecretChatActor', 'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager', 'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 472e95ac..bfceb9b2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -667,6 +667,15 @@ chatInviteLink invite_link:string = ChatInviteLink; chatInviteLinkInfo chat_id:int53 type:ChatType title:string photo:chatPhoto member_count:int32 member_user_ids:vector is_public:Bool = ChatInviteLinkInfo; +//@class PublicChatType @description Describes a type of public chats + +//@description The chat is public, because it has username +publicChatTypeHasUsername = PublicChatType; + +//@description The chat is public, because it is a location-based supergroup +publicChatTypeIsLocationBased = PublicChatType; + + //@class ChatActionBar @description Describes actions which should be possible to do through a chat action bar //@description The chat can be reported as spam using the method reportChat with the reason chatReportReasonSpam @@ -3115,8 +3124,8 @@ clearRecentlyFoundChats = Ok; //@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created @username Username to be checked checkChatUsername chat_id:int53 username:string = CheckChatUsernameResult; -//@description Returns a list of public chats with username created by the user -getCreatedPublicChats = Chats; +//@description Returns a list of public chats of the specified type, owned by the user @type Type of the public chats to return +getCreatedPublicChats type:PublicChatType = Chats; //@description Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Basic group chats need to be first upgraded to supergroups before they can be set as a discussion group getSuitableDiscussionChats = Chats; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index aef1b682..f18975ad 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 18fb7b9f..bf8b03c8 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1969,13 +1969,20 @@ class MigrateChatQuery : public Td::ResultHandler { class GetCreatedPublicChannelsQuery : public Td::ResultHandler { Promise promise_; + PublicDialogType type_; public: explicit GetCreatedPublicChannelsQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send() { - send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_getAdminedPublicChannels()))); + void send(PublicDialogType type) { + type_ = type; + int32 flags = 0; + if (type_ == PublicDialogType::IsLocationBased) { + flags |= telegram_api::channels_getAdminedPublicChannels::BY_LOCATION_MASK; + } + send_query(G()->net_query_creator().create( + create_storer(telegram_api::channels_getAdminedPublicChannels(flags, false /*ignored*/, false /*ignored*/)))); } void on_result(uint64 id, BufferSlice packet) override { @@ -1990,13 +1997,13 @@ class GetCreatedPublicChannelsQuery : public Td::ResultHandler { switch (constructor_id) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); - td->contacts_manager_->on_get_created_public_channels(std::move(chats->chats_)); + td->contacts_manager_->on_get_created_public_channels(type_, std::move(chats->chats_)); break; } case telegram_api::messages_chatsSlice::ID: { auto chats = move_tl_object_as(chats_ptr); LOG(ERROR) << "Receive chatsSlice in result of GetCreatedPublicChannelsQuery"; - td->contacts_manager_->on_get_created_public_channels(std::move(chats->chats_)); + td->contacts_manager_->on_get_created_public_channels(type_, std::move(chats->chats_)); break; } default: @@ -5780,23 +5787,26 @@ vector ContactsManager::get_dialog_ids(vector ContactsManager::get_created_public_dialogs(Promise &&promise) { - if (created_public_channels_inited_) { +vector ContactsManager::get_created_public_dialogs(PublicDialogType type, Promise &&promise) { + int32 index = static_cast(type); + if (created_public_channels_inited_[index]) { promise.set_value(Unit()); - return transform(created_public_channels_, [&](ChannelId channel_id) { + return transform(created_public_channels_[index], [&](ChannelId channel_id) { DialogId dialog_id(channel_id); td_->messages_manager_->force_create_dialog(dialog_id, "get_created_public_dialogs"); return dialog_id; }); } - td_->create_handler(std::move(promise))->send(); + td_->create_handler(std::move(promise))->send(type); return {}; } -void ContactsManager::on_get_created_public_channels(vector> &&chats) { - created_public_channels_inited_ = true; - created_public_channels_ = get_channel_ids(std::move(chats), "on_get_created_public_channels"); +void ContactsManager::on_get_created_public_channels(PublicDialogType type, + vector> &&chats) { + int32 index = static_cast(type); + created_public_channels_[index] = get_channel_ids(std::move(chats), "on_get_created_public_channels"); + created_public_channels_inited_[index] = true; } vector ContactsManager::get_dialogs_for_discussion(Promise &&promise) { @@ -7736,12 +7746,12 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from } } if (c->is_username_changed) { - if (c->status.is_creator() && created_public_channels_inited_) { + if (c->status.is_creator() && created_public_channels_inited_[0]) { if (c->username.empty()) { - td::remove(created_public_channels_, channel_id); + td::remove(created_public_channels_[0], channel_id); } else { - if (!td::contains(created_public_channels_, channel_id)) { - created_public_channels_.push_back(channel_id); + if (!td::contains(created_public_channels_[0], channel_id)) { + created_public_channels_[0].push_back(channel_id); } } } @@ -10183,14 +10193,19 @@ void ContactsManager::on_update_channel_title(Channel *c, ChannelId channel_id, void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status) { if (c->status != status) { LOG(INFO) << "Update " << channel_id << " status from " << c->status << " to " << status; - bool reget_channel_full = c->status.is_creator() != status.is_creator(); + bool is_ownership_transferred = c->status.is_creator() != status.is_creator(); bool drop_invite_link = c->status.is_administrator() != status.is_administrator() || c->status.is_member() != status.is_member(); c->status = status; c->is_status_changed = true; c->is_changed = true; invalidate_channel_full(channel_id, drop_invite_link); - if (reget_channel_full) { + if (is_ownership_transferred) { + for (size_t i = 0; i < 2; i++) { + created_public_channels_inited_[i] = false; + created_public_channels_[i].clear(); + } + auto input_channel = get_input_channel(channel_id); if (input_channel != nullptr) { send_get_channel_full_query(channel_id, std::move(input_channel), Auto(), "update channel creator"); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 4e6e6d18..2a5e4d78 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -21,6 +21,7 @@ #include "td/telegram/Location.h" #include "td/telegram/MessageId.h" #include "td/telegram/Photo.h" +#include "td/telegram/PublicDialogType.h" #include "td/telegram/QueryCombiner.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/StickerSetId.h" @@ -218,7 +219,7 @@ class ContactsManager : public Actor { void invalidate_invite_link_info(const string &invite_link); - void on_get_created_public_channels(vector> &&chats); + void on_get_created_public_channels(PublicDialogType type, vector> &&chats); void on_get_dialogs_for_discussion(vector> &&chats); @@ -363,7 +364,7 @@ class ContactsManager : public Actor { ChannelId migrate_chat_to_megagroup(ChatId chat_id, Promise &promise); - vector get_created_public_dialogs(Promise &&promise); + vector get_created_public_dialogs(PublicDialogType type, Promise &&promise); vector get_dialogs_for_discussion(Promise &&promise); @@ -1306,8 +1307,8 @@ class ContactsManager : public Actor { std::unordered_map channel_invite_links_; // in-memory cache for invite links std::unordered_map> invite_link_infos_; - bool created_public_channels_inited_ = false; - vector created_public_channels_; + bool created_public_channels_inited_[2] = {false, false}; + vector created_public_channels_[2]; bool dialogs_for_discussion_inited_ = false; vector dialogs_for_discussion_; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 11372258..34add5c6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -67,6 +67,7 @@ #include "td/telegram/PhotoSizeSource.h" #include "td/telegram/PollManager.h" #include "td/telegram/PrivacyManager.h" +#include "td/telegram/PublicDialogType.h" #include "td/telegram/RequestActor.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatsManager.h" @@ -1031,9 +1032,10 @@ class GetGroupsInCommonRequest : public RequestActor<> { class GetCreatedPublicChatsRequest : public RequestActor<> { vector dialog_ids_; + PublicDialogType type_; void do_run(Promise &&promise) override { - dialog_ids_ = td->contacts_manager_->get_created_public_dialogs(std::move(promise)); + dialog_ids_ = td->contacts_manager_->get_created_public_dialogs(type_, std::move(promise)); } void do_send_result() override { @@ -1041,7 +1043,8 @@ class GetCreatedPublicChatsRequest : public RequestActor<> { } public: - GetCreatedPublicChatsRequest(ActorShared td, uint64 request_id) : RequestActor(std::move(td), request_id) { + GetCreatedPublicChatsRequest(ActorShared td, uint64 request_id, PublicDialogType type) + : RequestActor(std::move(td), request_id), type_(type) { } }; @@ -5498,7 +5501,7 @@ void Td::on_request(uint64 id, td_api::checkChatUsername &request) { void Td::on_request(uint64 id, const td_api::getCreatedPublicChats &request) { CHECK_IS_USER(); - CREATE_NO_ARGS_REQUEST(GetCreatedPublicChatsRequest); + CREATE_REQUEST(GetCreatedPublicChatsRequest, get_public_dialog_type(request.type_)); } void Td::on_request(uint64 id, const td_api::getSuitableDiscussionChats &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1f9e81dc..6147bf69 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3275,6 +3275,9 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_supergroup_id(args))); } else if (op == "gcpc") { send_request(td_api::make_object()); + } else if (op == "gcpcl") { + send_request(td_api::make_object( + td_api::make_object())); } else if (op == "gsdc") { send_request(td_api::make_object()); } else if (op == "cpc") {