Add td_api::addChatFilterByInviteLink.

This commit is contained in:
levlam 2023-03-31 16:48:32 +03:00
parent d47bd927fe
commit cb2ce5d1de
6 changed files with 68 additions and 0 deletions

View File

@ -6830,6 +6830,9 @@ deleteChatFilterInviteLink chat_filter_id:int32 invite_link:string = Ok;
//@description Checks the validity of an invite link for a chat filter and returns information about the corresponding chat filter @invite_link Invite link to be checked
checkChatFilterInviteLink invite_link:string = ChatFilterInviteLinkInfo;
//@description Adds a chat filter by an invite link @invite_link Invite link for the chat filter @chat_ids Identifiers of the chats added to the chat filter. The chats are automatically joined if they aren't joined yet
addChatFilterByInviteLink invite_link:string chat_ids:vector<int53> = Ok;
//@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

@ -19,6 +19,7 @@
#include "td/telegram/OptionManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
#include "td/telegram/UpdatesManager.h"
#include "td/telegram/Version.h"
#include "td/actor/MultiPromise.h"
@ -278,6 +279,35 @@ class CheckChatlistInviteQuery final : public Td::ResultHandler {
}
};
class JoinChatlistInviteQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit JoinChatlistInviteQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &invite_link, vector<DialogId> dialog_ids) {
send_query(G()->net_query_creator().create(telegram_api::chatlists_joinChatlistInvite(
LinkManager::get_dialog_filter_invite_link_slug(invite_link),
td_->messages_manager_->get_input_peers(dialog_ids, AccessRights::Read))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::chatlists_joinChatlistInvite>(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 JoinChatlistInviteQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
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;
@ -1716,10 +1746,27 @@ void DialogFilterManager::on_get_chatlist_invite(
transform(already_dialog_ids, [](DialogId dialog_id) { return dialog_id.get(); })));
}
void DialogFilterManager::add_dialog_filter_by_invite_link(const string &invite_link, vector<DialogId> dialog_ids,
Promise<Unit> &&promise) {
if (!DialogFilterInviteLink::is_valid_invite_link(invite_link)) {
return promise.set_error(Status::Error(400, "Wrong invite link"));
}
for (auto dialog_id : dialog_ids) {
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
}
CHECK(!invite_link.empty());
td_->create_handler<JoinChatlistInviteQuery>(std::move(promise))->send(invite_link, std::move(dialog_ids));
}
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());
}
}
void add_dialog_filter_by_invite_link(const string &invite_link, vector<DialogId> dialog_ids, Promise<Unit> &&promise);
} // namespace td

View File

@ -92,6 +92,9 @@ class DialogFilterManager final : public Actor {
telegram_api::object_ptr<telegram_api::chatlists_ChatlistInvite> &&invite_ptr,
Promise<td_api::object_ptr<td_api::chatFilterInviteLinkInfo>> &&promise);
void add_dialog_filter_by_invite_link(const string &invite_link, vector<DialogId> dialog_ids,
Promise<Unit> &&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

@ -6192,6 +6192,14 @@ void Td::on_request(uint64 id, td_api::checkChatFilterInviteLink &request) {
dialog_filter_manager_->check_dialog_filter_invite_link(std::move(request.invite_link_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::addChatFilterByInviteLink &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_OK_REQUEST_PROMISE();
dialog_filter_manager_->add_dialog_filter_by_invite_link(
std::move(request.invite_link_), DialogId::get_dialog_ids(request.chat_ids_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTitle &request) {
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();

View File

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

View File

@ -4612,6 +4612,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::deleteChatFilterInviteLink>(chat_filter_id, invite_link));
} else if (op == "ccfil") {
send_request(td_api::make_object<td_api::checkChatFilterInviteLink>(args));
} else if (op == "acfbil") {
string invite_link;
string chat_ids;
get_args(args, invite_link, chat_ids);
send_request(td_api::make_object<td_api::addChatFilterByInviteLink>(invite_link, as_chat_ids(chat_ids)));
} else if (op == "grcf") {
send_request(td_api::make_object<td_api::getRecommendedChatFilters>());
} else if (op == "gcfdin") {