diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f319502c1..7d6892c58 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7682,6 +7682,9 @@ setDefaultReactionType reaction_type:ReactionType = Ok; //@description Returns tags used in Saved Messages getSavedMessagesTags = SavedMessagesTags; +//@description Changes label of a Saved Messages tag; for Telegram Premium users only @tag The tag @label New label for the tag; 0-12 characters +setSavedMessagesTagLabel tag:ReactionType label:string = Ok; + //@description Searches for a given quote in a text. Returns found quote start position in UTF-16 code units. Returns a 404 error if the quote is not found. Can be called synchronously //@text Text in which to search for the quote diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index 30f8d1dd2..1f934c277 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -200,6 +200,36 @@ class GetSavedReactionTagsQuery final : public Td::ResultHandler { } }; +class UpdateSavedReactionTagQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit UpdateSavedReactionTagQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(const ReactionType &reaction_type, const string &title) { + int32 flags = 0; + if (!title.empty()) { + flags |= telegram_api::messages_updateSavedReactionTag::TITLE_MASK; + } + send_query(G()->net_query_creator().create( + telegram_api::messages_updateSavedReactionTag(flags, reaction_type.get_input_reaction(), title))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + ReactionManager::SavedReactionTag::SavedReactionTag(telegram_api::object_ptr &&tag) : reaction_type_(tag->reaction_), title_(std::move(tag->title_)), count_(tag->count_) { } @@ -794,8 +824,28 @@ void ReactionManager::send_update_saved_messages_tags() { send_closure(G()->td(), &Td::send_update, get_update_saved_messages_tags_object()); } -void ReactionManager::on_update_saved_reaction_tags() { - get_saved_messages_tags(Auto()); +void ReactionManager::on_update_saved_reaction_tags(Promise &&promise) { + get_saved_messages_tags(PromiseCreator::lambda( + [promise = std::move(promise)](Result> result) mutable { + promise.set_value(Unit()); + })); +} + +void ReactionManager::set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise &&promise) { + if (reaction_type.is_empty()) { + return promise.set_error(Status::Error(400, "Reaction type must be non-empty")); + } + title = clean_name(title, MAX_TAG_TITLE_LENGTH); + + auto query_promise = + PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Result result) mutable { + if (result.is_ok()) { + send_closure(actor_id, &ReactionManager::on_update_saved_reaction_tags, std::move(promise)); + } else { + promise.set_error(result.move_as_error()); + } + }); + td_->create_handler(std::move(query_promise))->send(reaction_type, title); } void ReactionManager::get_current_state(vector> &updates) const { diff --git a/td/telegram/ReactionManager.h b/td/telegram/ReactionManager.h index 768b1ffd0..eeee58f77 100644 --- a/td/telegram/ReactionManager.h +++ b/td/telegram/ReactionManager.h @@ -68,7 +68,9 @@ class ReactionManager final : public Actor { void get_saved_messages_tags(Promise> &&promise); - void on_update_saved_reaction_tags(); + void on_update_saved_reaction_tags(Promise &&promise); + + void set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise &&promise); void get_current_state(vector> &updates) const; @@ -123,6 +125,8 @@ class ReactionManager final : public Actor { void parse(ParserT &parser); }; + static constexpr int32 MAX_TAG_TITLE_LENGTH = 12; + struct SavedReactionTag { ReactionType reaction_type_; string title_; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7297476a3..699a929f1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5466,6 +5466,14 @@ void Td::on_request(uint64 id, const td_api::getSavedMessagesTags &request) { reaction_manager_->get_saved_messages_tags(std::move(promise)); } +void Td::on_request(uint64 id, td_api::setSavedMessagesTagLabel &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.label_); + CREATE_OK_REQUEST_PROMISE(); + reaction_manager_->set_saved_messages_tag_title(ReactionType(request.tag_), std::move(request.label_), + std::move(promise)); +} + void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.offset_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 3dea2ce85..b5919cdf2 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -795,6 +795,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getSavedMessagesTags &request); + void on_request(uint64 id, td_api::setSavedMessagesTagLabel &request); + void on_request(uint64 id, td_api::getMessagePublicForwards &request); void on_request(uint64 id, td_api::getStoryPublicForwards &request); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 79f05ab96..55ded440b 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -3713,7 +3713,7 @@ void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - td_->reaction_manager_->on_update_saved_reaction_tags(); + td_->reaction_manager_->on_update_saved_reaction_tags(Promise()); promise.set_value(Unit()); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 77d9323c3..5d13a3f96 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2866,6 +2866,11 @@ class CliClient final : public Actor { chat_id, message_id, as_reaction_type(reaction), offset, as_limit(limit))); } else if (op == "gsmts") { send_request(td_api::make_object()); + } else if (op == "ssmtl") { + string reaction; + string label; + get_args(args, reaction, label); + send_request(td_api::make_object(as_reaction_type(reaction), label)); } else if (op == "gmpf") { ChatId chat_id; MessageId message_id;