Replace setChatChatList with addChatToList.

GitOrigin-RevId: c336e0e98b008b1571c4267d466b8cb0f3306957
This commit is contained in:
levlam 2020-05-31 00:48:33 +03:00
parent 1462d1ff3c
commit 5477233af9
7 changed files with 52 additions and 19 deletions

View File

@ -3712,8 +3712,9 @@ createNewSecretChat user_id:int32 = Chat;
upgradeBasicGroupChatToSupergroupChat chat_id:int53 = Chat;
//@description Moves a chat to a different chat list @chat_id Chat identifier @chat_list New chat list of the chat, must be one of chatListMain or chatListArchived. The chat with the current user (Saved Messages) and the chat 777000 (Telegram) can't be moved to the Archive chat list
setChatChatList chat_id:int53 chat_list:ChatList = Ok;
//@description Adds a chat to a chat list. A chat can't be simultaneously in Main and Archive chat lists, so it is automatically removed from another one if needed. The chat with the current user (Saved Messages) and the chat 777000 (Telegram) can't be moved to the Archive chat list
//@chat_id Chat identifier @chat_list The chat list
addChatToList chat_id:int53 chat_list:ChatList = Ok;
//@description Returns information about a chat filter by its identifier @chat_filter_id Chat filter identifier
getChatFilter chat_filter_id:int32 = ChatFilter;

Binary file not shown.

View File

@ -26959,18 +26959,58 @@ SearchMessagesFilter MessagesManager::get_search_messages_filter(
}
}
void MessagesManager::set_dialog_folder_id(DialogId dialog_id, FolderId folder_id, Promise<Unit> &&promise) {
LOG(INFO) << "Receive setChatChatList request to change folder of " << dialog_id << " to " << folder_id;
void MessagesManager::add_dialog_to_list(DialogId dialog_id, DialogListId dialog_list_id, Promise<Unit> &&promise) {
LOG(INFO) << "Receive addChatToList request to add " << dialog_id << " to " << dialog_list_id;
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return promise.set_error(Status::Error(3, "Chat not found"));
}
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(6, "Can't access the chat"));
}
if (d->order == DEFAULT_ORDER) {
return promise.set_error(Status::Error(400, "Chat is not in a chat list"));
}
if (get_dialog_list(dialog_list_id) == nullptr) {
return promise.set_error(Status::Error(400, "Chat list not found"));
}
if (dialog_list_id.is_filter()) {
auto dialog_filter_id = dialog_list_id.get_filter_id();
auto old_dialog_filter = get_dialog_filter(dialog_filter_id);
CHECK(old_dialog_filter != nullptr);
if (InputDialogId::contains(old_dialog_filter->included_dialog_ids, dialog_id) ||
InputDialogId::contains(old_dialog_filter->pinned_dialog_ids, dialog_id)) {
return promise.set_value(Unit());
}
auto new_dialog_filter = make_unique<DialogFilter>(*old_dialog_filter);
new_dialog_filter->included_dialog_ids.push_back(get_input_dialog_id(dialog_id));
td::remove_if(new_dialog_filter->excluded_dialog_ids,
[dialog_id](InputDialogId input_dialog_id) { return dialog_id == input_dialog_id.get_dialog_id(); });
auto status = check_dialog_filter_limits(new_dialog_filter.get());
if (status.is_error()) {
return promise.set_error(std::move(status));
}
sort_dialog_filter_input_dialog_ids(new_dialog_filter.get());
edit_dialog_filter(std::move(new_dialog_filter), "add_dialog_to_list");
save_dialog_filters();
send_update_chat_filters();
if (dialog_id.get_type() != DialogType::SecretChat) {
synchronize_dialog_filters();
}
return promise.set_value(Unit());
}
CHECK(dialog_list_id.is_folder());
auto folder_id = dialog_list_id.get_folder_id();
if (d->folder_id == folder_id) {
return promise.set_value(Unit());
}
@ -26981,10 +27021,6 @@ void MessagesManager::set_dialog_folder_id(DialogId dialog_id, FolderId folder_i
return promise.set_error(Status::Error(400, "Chat can't be archived"));
}
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(6, "Can't access the chat"));
}
set_dialog_folder_id(d, folder_id);
if (dialog_id.get_type() != DialogType::SecretChat) {

View File

@ -447,7 +447,7 @@ class MessagesManager : public Actor {
void send_dialog_action(DialogId dialog_id, const tl_object_ptr<td_api::ChatAction> &action, Promise<Unit> &&promise);
void set_dialog_folder_id(DialogId dialog_id, FolderId folder_id, Promise<Unit> &&promise);
void add_dialog_to_list(DialogId dialog_id, DialogListId dialog_list_id, Promise<Unit> &&promise);
void set_dialog_photo(DialogId dialog_id, const tl_object_ptr<td_api::InputFile> &photo, Promise<Unit> &&promise);

View File

@ -5874,14 +5874,10 @@ void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupCh
CREATE_REQUEST(UpgradeGroupChatToSupergroupChatRequest, request.chat_id_);
}
void Td::on_request(uint64 id, const td_api::setChatChatList &request) {
void Td::on_request(uint64 id, const td_api::addChatToList &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
DialogListId dialog_list_id(request.chat_list_);
if (!dialog_list_id.is_folder()) {
return send_error_raw(id, 400, "Wrong chat list specified");
}
messages_manager_->set_dialog_folder_id(DialogId(request.chat_id_), dialog_list_id.get_folder_id(),
messages_manager_->add_dialog_to_list(DialogId(request.chat_id_), DialogListId(request.chat_list_),
std::move(promise));
}

View File

@ -673,7 +673,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request);
void on_request(uint64 id, const td_api::setChatChatList &request);
void on_request(uint64 id, const td_api::addChatToList &request);
void on_request(uint64 id, const td_api::getChatFilter &request);

View File

@ -3510,9 +3510,9 @@ class CliClient final : public Actor {
std::tie(supergroup_id, force) = split(args);
send_request(td_api::make_object<td_api::createSupergroupChat>(as_supergroup_id(supergroup_id), as_bool(force)));
} else if (op == "sccl" || op == "sccla" || begins_with(op, "sccl-")) {
} else if (op == "actl" || op == "actla" || begins_with(op, "actl-")) {
string chat_id = args;
send_request(td_api::make_object<td_api::setChatChatList>(as_chat_id(chat_id), as_chat_list(op)));
send_request(td_api::make_object<td_api::addChatToList>(as_chat_id(chat_id), as_chat_list(op)));
} else if (op == "gcf") {
send_request(td_api::make_object<td_api::getChatFilter>(as_chat_filter_id(args)));
} else if (op == "ccf") {