Add td_api::addChatFolderNewChats.

This commit is contained in:
levlam 2023-04-04 16:35:31 +03:00
parent e6cc743c33
commit 758926bbed
6 changed files with 70 additions and 2 deletions

View File

@ -6850,6 +6850,9 @@ addChatFolderByInviteLink invite_link:string chat_ids:vector<int53> = Ok;
//@description Returns new chats added to a shareable chat folder by its owner. The method should be called at most once an hour for the given chat folder @chat_folder_id Chat folder identifier
getChatFolderNewChats chat_folder_id:int32 = Chats;
//@description Adds new chats added to a shareable chat folder by its owner to the user's chat folder @chat_folder_id Chat folder identifier @chat_ids Identifiers of the new chats added to the chat folder. The chats are automatically joined if they aren't joined yet
addChatFolderNewChats chat_folder_id:int32 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

@ -401,6 +401,35 @@ class GetChatlistUpdatesQuery final : public Td::ResultHandler {
}
};
class JoinChatlistUpdatesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit JoinChatlistUpdatesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogFilterId dialog_filter_id, vector<DialogId> dialog_ids) {
send_query(G()->net_query_creator().create(telegram_api::chatlists_joinChatlistUpdates(
dialog_filter_id.get_input_chatlist(),
td_->messages_manager_->get_input_peers(dialog_ids, AccessRights::Read))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::chatlists_joinChatlistUpdates>(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 JoinChatlistUpdatesQuery: " << 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;
@ -1925,7 +1954,7 @@ void DialogFilterManager::add_dialog_filter_by_invite_link(const string &invite_
}
void DialogFilterManager::get_dialog_filter_new_chats(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> promise) {
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"));
@ -1936,6 +1965,24 @@ void DialogFilterManager::get_dialog_filter_new_chats(DialogFilterId dialog_filt
td_->create_handler<GetChatlistUpdatesQuery>(std::move(promise))->send(dialog_filter_id);
}
void DialogFilterManager::add_dialog_filter_new_chats(DialogFilterId dialog_filter_id, vector<DialogId> dialog_ids,
Promise<Unit> &&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"));
}
if (!dialog_filter->is_shareable()) {
return promise.set_error(Status::Error(400, "Chat folder must be shareable"));
}
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"));
}
}
td_->create_handler<JoinChatlistUpdatesQuery>(std::move(promise))->send(dialog_filter_id, std::move(dialog_ids));
}
void DialogFilterManager::set_dialog_filter_has_my_invite_links(DialogFilterId dialog_filter_id,
bool has_my_invite_links) {
auto dialog_filter = get_dialog_filter(dialog_filter_id);

View File

@ -99,7 +99,11 @@ class DialogFilterManager final : public Actor {
void add_dialog_filter_by_invite_link(const string &invite_link, vector<DialogId> dialog_ids,
Promise<Unit> &&promise);
void get_dialog_filter_new_chats(DialogFilterId dialog_filter_id, Promise<td_api::object_ptr<td_api::chats>> promise);
void get_dialog_filter_new_chats(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void add_dialog_filter_new_chats(DialogFilterId dialog_filter_id, vector<DialogId> dialog_ids,
Promise<Unit> &&promise);
void on_get_dialog_filter(telegram_api::object_ptr<telegram_api::DialogFilter> filter);

View File

@ -6214,6 +6214,13 @@ void Td::on_request(uint64 id, const td_api::getChatFolderNewChats &request) {
dialog_filter_manager_->get_dialog_filter_new_chats(DialogFilterId(request.chat_folder_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::addChatFolderNewChats &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
dialog_filter_manager_->add_dialog_filter_new_chats(DialogFilterId(request.chat_folder_id_),
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

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

View File

@ -4626,6 +4626,11 @@ class CliClient final : public Actor {
ChatFolderId chat_folder_id;
get_args(args, chat_folder_id);
send_request(td_api::make_object<td_api::getChatFolderNewChats>(chat_folder_id));
} else if (op == "acfnc") {
ChatFolderId chat_folder_id;
string chat_ids;
get_args(args, chat_folder_id, chat_ids);
send_request(td_api::make_object<td_api::addChatFolderNewChats>(chat_folder_id, as_chat_ids(chat_ids)));
} else if (op == "grcf") {
send_request(td_api::make_object<td_api::getRecommendedChatFolders>());
} else if (op == "gcfdin") {