Add td_api::setPinnedSavedMessagesTopics.

This commit is contained in:
levlam 2024-01-18 19:38:26 +03:00
parent af43242ca7
commit 20c4815a12
6 changed files with 72 additions and 5 deletions

View File

@ -7197,6 +7197,9 @@ deleteSavedMessagesTopicMessagesByDate saved_messages_topic:SavedMessagesTopic m
//@is_pinned Pass true to pin the topic; pass false to unpin it
toggleSavedMessagesTopicIsPinned saved_messages_topic:SavedMessagesTopic is_pinned:Bool = Ok;
//@description Changes the order of pinned Saved Messages topics @saved_messages_topics The new list of pinned Saved Messages topics
setPinnedSavedMessagesTopics saved_messages_topics:vector<SavedMessagesTopic> = Ok;
//@description Returns a list of common group chats with a given user. Chats are sorted by their type and creation date
//@user_id User identifier

View File

@ -383,6 +383,43 @@ class ToggleSavedDialogPinQuery final : public Td::ResultHandler {
}
};
class ReorderPinnedSavedDialogsQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit ReorderPinnedSavedDialogsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const vector<SavedMessagesTopicId> &saved_messages_topic_ids) {
auto order = transform(saved_messages_topic_ids, [td = td_](SavedMessagesTopicId saved_messages_topic_id) {
auto saved_input_peer = saved_messages_topic_id.get_input_dialog_peer(td);
CHECK(saved_input_peer != nullptr);
return saved_input_peer;
});
int32 flags = telegram_api::messages_reorderPinnedSavedDialogs::FORCE_MASK;
send_query(G()->net_query_creator().create(
telegram_api::messages_reorderPinnedSavedDialogs(flags, true /*ignored*/, std::move(order))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_reorderPinnedSavedDialogs>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
if (!result) {
return on_error(Status::Error(400, "Result is false"));
}
td_->messages_manager_->on_update_pinned_saved_messages_topics();
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetDialogUnreadMarksQuery final : public Td::ResultHandler {
public:
void send() {
@ -16332,6 +16369,14 @@ void MessagesManager::toggle_saved_messages_topic_is_pinned(SavedMessagesTopicId
td_->create_handler<ToggleSavedDialogPinQuery>(std::move(promise))->send(saved_messages_topic_id, is_pinned);
}
void MessagesManager::set_pinned_saved_messages_topics(vector<SavedMessagesTopicId> saved_messages_topic_ids,
Promise<Unit> &&promise) {
for (const auto &saved_messages_topic_id : saved_messages_topic_ids) {
TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_status(td_));
}
td_->create_handler<ReorderPinnedSavedDialogsQuery>(std::move(promise))->send(std::move(saved_messages_topic_ids));
}
void MessagesManager::on_update_pinned_saved_messages_topics() {
if (td_->auth_manager_->is_bot()) {
// just in case

View File

@ -552,6 +552,8 @@ class MessagesManager final : public Actor {
void toggle_saved_messages_topic_is_pinned(SavedMessagesTopicId saved_messages_topic_id, bool is_pinned,
Promise<Unit> &&promise);
void set_pinned_saved_messages_topics(vector<SavedMessagesTopicId> saved_messages_topic_ids, Promise<Unit> &&promise);
void on_update_pinned_saved_messages_topics();
vector<DialogId> search_public_dialogs(const string &query, Promise<Unit> &&promise);

View File

@ -5071,6 +5071,14 @@ void Td::on_request(uint64 id, const td_api::toggleSavedMessagesTopicIsPinned &r
request.is_pinned_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setPinnedSavedMessagesTopics &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
auto saved_messages_topic_ids = transform(request.saved_messages_topics_,
[td = this](const auto &topic) { return SavedMessagesTopicId(td, topic); });
messages_manager_->set_pinned_saved_messages_topics(std::move(saved_messages_topic_ids), std::move(promise));
}
void Td::on_request(uint64 id, td_api::searchPublicChat &request) {
CLEAN_INPUT_STRING(request.username_);
CREATE_REQUEST(SearchPublicChatRequest, request.username_);

View File

@ -685,6 +685,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::toggleSavedMessagesTopicIsPinned &request);
void on_request(uint64 id, const td_api::setPinnedSavedMessagesTopics &request);
void on_request(uint64 id, td_api::searchPublicChat &request);
void on_request(uint64 id, td_api::searchPublicChats &request);

View File

@ -946,17 +946,21 @@ class CliClient final : public Actor {
return nullptr;
}
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic() const {
if (saved_messages_topic_ == 0) {
td_api::object_ptr<td_api::SavedMessagesTopic> as_saved_messages_topic(int64 saved_messages_topic) const {
if (saved_messages_topic == 0) {
return nullptr;
}
if (saved_messages_topic_ == my_id_) {
if (saved_messages_topic == my_id_) {
return td_api::make_object<td_api::savedMessagesTopicMyNotes>();
}
if (saved_messages_topic_ == -1) {
if (saved_messages_topic == -1) {
return td_api::make_object<td_api::savedMessagesTopicAuthorHidden>();
}
return td_api::make_object<td_api::savedMessagesTopicSavedFromChat>(saved_messages_topic_);
return td_api::make_object<td_api::savedMessagesTopicSavedFromChat>(saved_messages_topic);
}
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic() const {
return as_saved_messages_topic(saved_messages_topic_);
}
td_api::object_ptr<td_api::linkPreviewOptions> get_link_preview_options() const {
@ -2780,6 +2784,9 @@ class CliClient final : public Actor {
get_args(args, is_pinned);
send_request(
td_api::make_object<td_api::toggleSavedMessagesTopicIsPinned>(get_saved_messages_topic(), is_pinned));
} else if (op == "spsmt") {
send_request(td_api::make_object<td_api::setPinnedSavedMessagesTopics>(
transform(autosplit(args), [this](Slice str) { return as_saved_messages_topic(as_chat_id(str)); })));
} else if (op == "gcc" || op == "GetCommonChats") {
UserId user_id;
ChatId offset_chat_id;