Add td_api::getChatsForChatFolderInviteLink.

This commit is contained in:
levlam 2023-04-09 21:54:40 +03:00
parent 33ac156bc0
commit a52b6f025f
10 changed files with 101 additions and 4 deletions

View File

@ -6826,11 +6826,13 @@ getRecommendedChatFolders = RecommendedChatFolders;
//@description Returns default icon name for a folder. Can be called synchronously @folder Chat folder
getChatFolderDefaultIconName folder:chatFolder = ChatFolderIcon;
//@description Returns identifiers of chats from a chat folder, suitable for adding to a chat folder invite link @chat_folder_id Chat folder identifier
getChatsForChatFolderInviteLink chat_folder_id:int32 = Chats;
//@description Creates a new invite link for a chat folder. A link can be created for a chat folder if it has only pinned and included chats
//@chat_folder_id Chat folder identifier
//@name Name of the link; 0-32 characters
//@chat_ids Identifiers of basic group, supergroup, or channel chats to be accessible by the invite link. The chats must be public and could be join without approval by chat administrators,
//-or the user must be able to invite new members to them by an invite link. Basic groups will be automatically converted to supergroups before link creation
//@chat_ids Identifiers of chats to be accessible by the invite link. Use getChatsForChatFolderInviteLink to get suitable chats. Basic groups will be automatically converted to supergroups before link creation
createChatFolderInviteLink chat_folder_id:int32 name:string chat_ids:vector<int53> = ChatFolderInviteLink;
//@description Returns invite links created by the current user for a shareable chat folder @chat_folder_id Chat folder identifier
@ -6840,8 +6842,7 @@ getChatFolderInviteLinks chat_folder_id:int32 = ChatFolderInviteLinks;
//@chat_folder_id Chat folder identifier
//@invite_link Invite link to be edited
//@name New name of the link; 0-32 characters
//@chat_ids New identifiers of basic group, supergroup, or channel chats to be accessible by the invite link. The chats must be public and could be join without approval by chat administrators,
//-or the user must be able to invite new members to them by an invite link. Basic groups will be automatically converted to supergroups before link editing
//@chat_ids New identifiers of chats to be accessible by the invite link. Use getChatsForChatFolderInviteLink to get suitable chats. Basic groups will be automatically converted to supergroups before link editing
editChatFolderInviteLink chat_folder_id:int32 invite_link:string name:string chat_ids:vector<int53> = ChatFolderInviteLink;
//@description Deletes an invite link for a chat folder

View File

@ -16980,6 +16980,14 @@ bool ContactsManager::get_channel_join_to_send(const Channel *c) {
return c->join_to_send || !c->is_megagroup || !c->has_linked_channel;
}
bool ContactsManager::get_channel_join_request(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return false;
}
return get_channel_join_request(c);
}
bool ContactsManager::get_channel_join_request(const Channel *c) {
return c->join_request && c->is_megagroup && (is_channel_public(c) || c->has_linked_channel);
}

View File

@ -634,6 +634,7 @@ class ContactsManager final : public Actor {
int32 get_channel_participant_count(ChannelId channel_id) const;
bool get_channel_sign_messages(ChannelId channel_id) const;
bool get_channel_has_linked_channel(ChannelId channel_id) const;
bool get_channel_join_request(ChannelId channel_id) const;
bool get_channel_can_be_deleted(ChannelId channel_id) const;
ChannelId get_channel_linked_channel_id(ChannelId channel_id);
int32 get_channel_slow_mode_delay(ChannelId channel_id);

View File

@ -695,6 +695,44 @@ void DialogFilter::sort_input_dialog_ids(const Td *td, const char *source) {
});
}
vector<DialogId> DialogFilter::get_dialogs_for_invite_link(Td *td) {
if (!excluded_dialog_ids_.empty() || exclude_muted_ || exclude_read_ || exclude_archived_ || include_contacts_ ||
include_non_contacts_ || include_bots_ || include_groups_ || include_channels_) {
return {};
}
vector<DialogId> result;
for_each_dialog([&](const InputDialogId &input_dialog_id) {
auto dialog_id = input_dialog_id.get_dialog_id();
if (!td->messages_manager_->have_dialog_force(dialog_id, "get_dialogs_for_invite_link")) {
return;
}
bool is_good = false;
switch (dialog_id.get_type()) {
case DialogType::Chat: {
auto chat_id = dialog_id.get_chat_id();
// the user can manage invite links in the chat
is_good = td->contacts_manager_->get_chat_status(chat_id).can_manage_invite_links();
break;
}
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
// the user can manage invite links in the chat
// or the chat is a public chat, which can be joined without administrator approval
is_good = td->contacts_manager_->get_channel_status(channel_id).can_manage_invite_links() ||
(td->contacts_manager_->is_channel_public(channel_id) &&
!td->contacts_manager_->get_channel_join_request(channel_id));
break;
}
default:
break;
}
if (is_good) {
result.push_back(dialog_id);
}
});
return result;
}
vector<FolderId> DialogFilter::get_folder_ids() const {
if (exclude_archived_ && pinned_dialog_ids_.empty() && included_dialog_ids_.empty()) {
return {FolderId::main()};

View File

@ -96,6 +96,8 @@ class DialogFilter {
void sort_input_dialog_ids(const Td *td, const char *source);
vector<DialogId> get_dialogs_for_invite_link(Td *td);
vector<FolderId> get_folder_ids() const;
bool need_dialog(const Td *td, const DialogFilterDialogInfo &dialog_info) const;

View File

@ -1852,6 +1852,34 @@ void DialogFilterManager::save_dialog_filters() {
G()->td_db()->get_binlog_pmc()->set("dialog_filters", log_event_store(log_event).as_slice().str());
}
void DialogFilterManager::get_dialogs_for_dialog_filter_invite_link(
DialogFilterId dialog_filter_id, Promise<td_api::object_ptr<td_api::chats>> promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat folder not found"));
}
auto load_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), dialog_filter_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &DialogFilterManager::do_get_dialogs_for_dialog_filter_invite_link, dialog_filter_id,
std::move(promise));
});
load_dialog_filter(dialog_filter, std::move(load_promise));
}
void DialogFilterManager::do_get_dialogs_for_dialog_filter_invite_link(
DialogFilterId dialog_filter_id, Promise<td_api::object_ptr<td_api::chats>> promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat folder not found"));
}
promise.set_value(MessagesManager::get_chats_object(-1, dialog_filter->get_dialogs_for_invite_link(td_)));
}
void DialogFilterManager::create_dialog_filter_invite_link(
DialogFilterId dialog_filter_id, string invite_link_name, vector<DialogId> dialog_ids,
Promise<td_api::object_ptr<td_api::chatFolderInviteLink>> promise) {

View File

@ -76,6 +76,9 @@ class DialogFilterManager final : public Actor {
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise);
void get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> promise);
void create_dialog_filter_invite_link(DialogFilterId dialog_filter_id, string invite_link_name,
vector<DialogId> dialog_ids,
Promise<td_api::object_ptr<td_api::chatFolderInviteLink>> promise);
@ -209,6 +212,9 @@ class DialogFilterManager final : public Actor {
void delete_dialogs_from_filter(const DialogFilter *dialog_filter, vector<DialogId> &&dialog_ids, const char *source);
void do_get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> promise);
bool is_inited_ = false;
bool are_dialog_filters_being_synchronized_ = false;

View File

@ -6143,6 +6143,13 @@ void Td::on_request(uint64 id, const td_api::reorderChatFolders &request) {
request.main_chat_list_position_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatsForChatFolderInviteLink &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
dialog_filter_manager_->get_dialogs_for_dialog_filter_invite_link(DialogFilterId(request.chat_folder_id_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::createChatFolderInviteLink &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.name_);

View File

@ -927,6 +927,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::reorderChatFolders &request);
void on_request(uint64 id, const td_api::getChatsForChatFolderInviteLink &request);
void on_request(uint64 id, td_api::createChatFolderInviteLink &request);
void on_request(uint64 id, td_api::getChatFolderInviteLinks &request);

View File

@ -4591,6 +4591,10 @@ class CliClient final : public Actor {
get_args(args, main_chat_list_position, chat_folder_ids);
send_request(td_api::make_object<td_api::reorderChatFolders>(as_chat_folder_ids(chat_folder_ids),
main_chat_list_position));
} else if (op == "gcfcfil") {
ChatFolderId chat_folder_id;
get_args(args, chat_folder_id);
send_request(td_api::make_object<td_api::getChatsForChatFolderInviteLink>(chat_folder_id));
} else if (op == "crcfil") {
ChatFolderId chat_folder_id;
string name;