Add td_api::getChatFilterInviteLinks.

This commit is contained in:
levlam 2023-03-30 17:15:04 +03:00
parent 0ec458ebb1
commit d1c9cacf85
7 changed files with 96 additions and 23 deletions

View File

@ -1321,6 +1321,9 @@ chatFilterInfo id:int32 title:string icon_name:string = ChatFilterInfo;
//@chat_ids Identifiers of chats, included in the link
chatFilterInviteLink invite_link:string name:string chat_ids:vector<int53> = ChatFilterInviteLink;
//@description Represents a list of chat filter invite links @invite_links List of the invite links
chatFilterInviteLinks invite_links:vector<chatFilterInviteLink> = ChatFilterInviteLinks;
//@description Describes a recommended chat filter @filter The chat filter @param_description Chat filter description
recommendedChatFilter filter:chatFilter description:string = RecommendedChatFilter;
@ -6798,6 +6801,9 @@ getChatFilterDefaultIconName filter:chatFilter = Text;
//@chat_ids Identifiers of basic group, supergroup, or channel chats to be accessible by the invite link. The chats must be public, or the user must be able to invite new members by an invite link. Basic groups will be automatically converted to supergroups before link creation
createChatFilterInviteLink chat_filter_id:int32 name:string chat_ids:vector<int53> = ChatFilterInviteLink;
//@description Returns invite links created by the current user for a shareable chat filter @chat_filter_id Chat filter identifier
getChatFilterInviteLinks chat_filter_id:int32 = ChatFilterInviteLinks;
//@description Changes the chat title. Supported only for basic groups, supergroups and channels. Requires can_change_info administrator right
//@chat_id Chat identifier

View File

@ -47,6 +47,10 @@ class DialogFilter {
bool is_empty(bool for_server) const;
bool is_shareable() const {
return is_shareable_;
}
const DialogFilterId &get_dialog_filter_id() const {
return dialog_filter_id_;
}

View File

@ -152,6 +152,42 @@ class ExportChatlistInviteQuery final : public Td::ResultHandler {
}
};
class GetExportedChatlistInvitesQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatFilterInviteLinks>> promise_;
public:
explicit GetExportedChatlistInvitesQuery(Promise<td_api::object_ptr<td_api::chatFilterInviteLinks>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogFilterId dialog_filter_id) {
send_query(G()->net_query_creator().create(
telegram_api::chatlists_getExportedInvites(dialog_filter_id.get_input_chatlist())));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::chatlists_getExportedInvites>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetExportedChatlistInvitesQuery: " << to_string(ptr);
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetExportedChatlistInvitesQuery");
td_->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetExportedChatlistInvitesQuery");
td_api::object_ptr<td_api::chatFilterInviteLinks> result;
for (auto &invite : ptr->invites_) {
result->invite_links_.push_back(
DialogFilterInviteLink(td_, std::move(invite)).get_chat_filter_invite_link_object());
}
promise_.set_value(std::move(result));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetDialogsQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
bool is_single_ = false;
@ -1338,29 +1374,6 @@ void DialogFilterManager::reorder_dialog_filters(vector<DialogFilterId> dialog_f
promise.set_value(Unit());
}
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::chatFilterInviteLink>> promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat filter not found"));
}
vector<tl_object_ptr<telegram_api::InputPeer>> input_peers;
input_peers.reserve(dialog_ids.size());
for (auto &dialog_id : dialog_ids) {
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Have no access to the chat"));
}
input_peers.push_back(std::move(input_peer));
}
if (input_peers.empty()) {
return promise.set_error(Status::Error(400, "At least one chat must be included"));
}
td_->create_handler<ExportChatlistInviteQuery>(std::move(promise))
->send(dialog_filter_id, invite_link_name, std::move(input_peers));
}
void DialogFilterManager::reorder_dialog_filters_on_server(vector<DialogFilterId> dialog_filter_ids,
int32 main_dialog_list_position) {
CHECK(!td_->auth_manager_->is_bot());
@ -1472,6 +1485,41 @@ void DialogFilterManager::save_dialog_filters() {
G()->td_db()->get_binlog_pmc()->set("dialog_filters", log_event_store(log_event).as_slice().str());
}
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::chatFilterInviteLink>> promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat filter not found"));
}
vector<tl_object_ptr<telegram_api::InputPeer>> input_peers;
input_peers.reserve(dialog_ids.size());
for (auto &dialog_id : dialog_ids) {
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Have no access to the chat"));
}
input_peers.push_back(std::move(input_peer));
}
if (input_peers.empty()) {
return promise.set_error(Status::Error(400, "At least one chat must be included"));
}
td_->create_handler<ExportChatlistInviteQuery>(std::move(promise))
->send(dialog_filter_id, invite_link_name, std::move(input_peers));
}
void DialogFilterManager::get_dialog_filter_invite_links(
DialogFilterId dialog_filter_id, Promise<td_api::object_ptr<td_api::chatFilterInviteLinks>> promise) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);
if (dialog_filter == nullptr) {
return promise.set_error(Status::Error(400, "Chat filter not found"));
}
if (!dialog_filter->is_shareable()) {
return promise.set_value(td_api::make_object<td_api::chatFilterInviteLinks>());
}
td_->create_handler<GetExportedChatlistInvitesQuery>(std::move(promise))->send(dialog_filter_id);
}
void DialogFilterManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
if (have_dialog_filters()) {
updates.push_back(get_update_chat_filters_object());

View File

@ -76,6 +76,9 @@ class DialogFilterManager final : public Actor {
vector<DialogId> dialog_ids,
Promise<td_api::object_ptr<td_api::chatFilterInviteLink>> promise);
void get_dialog_filter_invite_links(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chatFilterInviteLinks>> promise);
void on_get_dialog_filter(telegram_api::object_ptr<telegram_api::DialogFilter> filter);
void get_recommended_dialog_filters(Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);

View File

@ -6161,6 +6161,12 @@ void Td::on_request(uint64 id, td_api::createChatFilterInviteLink &request) {
std::move(promise));
}
void Td::on_request(uint64 id, td_api::getChatFilterInviteLinks &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
dialog_filter_manager_->get_dialog_filter_invite_links(DialogFilterId(request.chat_filter_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTitle &request) {
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();

View File

@ -927,6 +927,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::createChatFilterInviteLink &request);
void on_request(uint64 id, td_api::getChatFilterInviteLinks &request);
void on_request(uint64 id, td_api::setChatTitle &request);
void on_request(uint64 id, const td_api::setChatPhoto &request);

View File

@ -4592,6 +4592,10 @@ class CliClient final : public Actor {
get_args(args, chat_filter_id, name, chat_ids);
send_request(
td_api::make_object<td_api::createChatFilterInviteLink>(chat_filter_id, name, as_chat_ids(chat_ids)));
} else if (op == "gcfil") {
ChatFilterId chat_filter_id;
get_args(args, chat_filter_id);
send_request(td_api::make_object<td_api::getChatFilterInviteLinks>(chat_filter_id));
} else if (op == "grcf") {
send_request(td_api::make_object<td_api::getRecommendedChatFilters>());
} else if (op == "gcfdin") {