Add chat_list to toggleChatIsPinned.

GitOrigin-RevId: ffc8a124677f22f8367009e006a4f1ad17953f22
This commit is contained in:
levlam 2020-05-19 04:21:50 +03:00
parent a8e570fd65
commit ffb9dd2c6c
6 changed files with 21 additions and 12 deletions

View File

@ -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<int53> = Ok;

Binary file not shown.

View File

@ -15527,7 +15527,7 @@ vector<DialogId> MessagesManager::remove_secret_chat_dialog_ids(vector<DialogId>
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<size_t>(get_pinned_dialogs_limit(d->folder_id))) {
if (dialog_count >= static_cast<size_t>(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();

View File

@ -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;

View File

@ -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) {

View File

@ -2842,11 +2842,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setChatDraftMessage>(as_chat_id(chat_id), std::move(draft_message)));
} else if (op == "cadm") {
send_request(td_api::make_object<td_api::clearAllDraftMessages>());
} 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<td_api::toggleChatIsPinned>(as_chat_id(chat_id), as_bool(is_pinned)));
send_request(
td_api::make_object<td_api::toggleChatIsPinned>(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;