diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ba28b4340..c7c028e42 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3750,9 +3750,6 @@ setChatDraftMessage chat_id:int53 draft_message:draftMessage = Ok; //@chat_id Chat identifier @notification_settings New notification settings for the chat. If the chat is muted for more than 1 week, it is considered to be muted forever setChatNotificationSettings chat_id:int53 notification_settings:chatNotificationSettings = Ok; -//@description Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/archive chat list @chat_id Chat identifier @is_pinned True, if the chat is pinned -toggleChatIsPinned chat_id:int53 is_pinned:Bool = Ok; - //@description Changes the marked as unread state of a chat @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread toggleChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Ok; @@ -3834,6 +3831,10 @@ setScopeNotificationSettings scope:NotificationSettingsScope notification_settin resetAllNotificationSettings = Ok; +//@description Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/arhive chat list +//@chat_list Chat list in which to change the pinned state of the chat @chat_id Chat identifier @is_pinned True, if the chat is pinned +toggleChatIsPinned chat_list:ChatList chat_id:int53 is_pinned:Bool = Ok; + //@description Changes the order of pinned chats @chat_list Chat list in which to change the order of pinned chats @chat_ids The new list of pinned chats setPinnedChats chat_list:ChatList chat_ids:vector = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 479a4dea1..e55ab5b44 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ada9c3b0e..9a487d480 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15527,7 +15527,7 @@ vector MessagesManager::remove_secret_chat_dialog_ids(vector return dialog_ids; } -Status MessagesManager::toggle_dialog_is_pinned(DialogId dialog_id, bool is_pinned) { +Status MessagesManager::toggle_dialog_is_pinned(FolderId folder_id, DialogId dialog_id, bool is_pinned) { if (td_->auth_manager_->is_bot()) { return Status::Error(6, "Bots can't change chat pin state"); } @@ -15543,13 +15543,19 @@ Status MessagesManager::toggle_dialog_is_pinned(DialogId dialog_id, bool is_pinn return Status::Error(6, "The chat can't be pinned"); } - bool was_pinned = get_dialog_pinned_order(d->folder_id, dialog_id) != DEFAULT_ORDER; + if (get_dialog_list(folder_id) == nullptr) { + return Status::Error(6, "Chat list not found"); + } + + bool was_pinned = get_dialog_pinned_order(folder_id, dialog_id) != DEFAULT_ORDER; if (is_pinned == was_pinned) { return Status::OK(); } if (is_pinned) { - auto pinned_dialog_ids = get_pinned_dialog_ids(d->folder_id); + set_dialog_folder_id(d, folder_id); + + auto pinned_dialog_ids = get_pinned_dialog_ids(folder_id); auto pinned_dialog_count = pinned_dialog_ids.size(); auto secret_pinned_dialog_count = std::count_if(pinned_dialog_ids.begin(), pinned_dialog_ids.end(), @@ -15558,12 +15564,12 @@ Status MessagesManager::toggle_dialog_is_pinned(DialogId dialog_id, bool is_pinn ? secret_pinned_dialog_count : pinned_dialog_count - secret_pinned_dialog_count; - if (dialog_count >= static_cast(get_pinned_dialogs_limit(d->folder_id))) { + if (dialog_count >= static_cast(get_pinned_dialogs_limit(folder_id))) { return Status::Error(400, "Maximum number of pinned chats exceeded"); } } - if (set_dialog_is_pinned(d->folder_id, d, is_pinned)) { + if (set_dialog_is_pinned(folder_id, d, is_pinned)) { toggle_dialog_is_pinned_on_server(dialog_id, is_pinned, 0); } return Status::OK(); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 1a0b54837..79a905b69 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -571,7 +571,7 @@ class MessagesManager : public Actor { void set_dialog_is_pinned(DialogId dialog_id, bool is_pinned); - Status toggle_dialog_is_pinned(DialogId dialog_id, bool is_pinned) TD_WARN_UNUSED_RESULT; + Status toggle_dialog_is_pinned(FolderId folder_id, DialogId dialog_id, bool is_pinned) TD_WARN_UNUSED_RESULT; Status toggle_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) TD_WARN_UNUSED_RESULT; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 54ea4ef31..e7628ee11 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5943,7 +5943,8 @@ void Td::on_request(uint64 id, td_api::setChatDraftMessage &request) { void Td::on_request(uint64 id, const td_api::toggleChatIsPinned &request) { CHECK_IS_USER(); - answer_ok_query(id, messages_manager_->toggle_dialog_is_pinned(DialogId(request.chat_id_), request.is_pinned_)); + answer_ok_query(id, messages_manager_->toggle_dialog_is_pinned(FolderId(request.chat_list_), + DialogId(request.chat_id_), request.is_pinned_)); } void Td::on_request(uint64 id, const td_api::toggleChatIsMarkedAsUnread &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 8bf58cdc4..08f0addb9 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2842,11 +2842,12 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_chat_id(chat_id), std::move(draft_message))); } else if (op == "cadm") { send_request(td_api::make_object()); - } else if (op == "tcip") { + } else if (op == "tcip" || op == "tcipa") { string chat_id; string is_pinned; std::tie(chat_id, is_pinned) = split(args); - send_request(td_api::make_object(as_chat_id(chat_id), as_bool(is_pinned))); + send_request( + td_api::make_object(as_chat_list(op), as_chat_id(chat_id), as_bool(is_pinned))); } else if (op == "tcimar") { string chat_id; string is_marked_as_read;