Add td_api::setSavedMessagesTagLabel.
This commit is contained in:
parent
e7953c067c
commit
956c35d6e0
@ -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
|
||||
|
@ -200,6 +200,36 @@ class GetSavedReactionTagsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class UpdateSavedReactionTagQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit UpdateSavedReactionTagQuery(Promise<Unit> &&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<telegram_api::messages_updateSavedReactionTag>(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<telegram_api::savedReactionTag> &&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<Unit> &&promise) {
|
||||
get_saved_messages_tags(PromiseCreator::lambda(
|
||||
[promise = std::move(promise)](Result<td_api::object_ptr<td_api::savedMessagesTags>> result) mutable {
|
||||
promise.set_value(Unit());
|
||||
}));
|
||||
}
|
||||
|
||||
void ReactionManager::set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise<Unit> &&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<Unit> 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<UpdateSavedReactionTagQuery>(std::move(query_promise))->send(reaction_type, title);
|
||||
}
|
||||
|
||||
void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
|
@ -68,7 +68,9 @@ class ReactionManager final : public Actor {
|
||||
|
||||
void get_saved_messages_tags(Promise<td_api::object_ptr<td_api::savedMessagesTags>> &&promise);
|
||||
|
||||
void on_update_saved_reaction_tags();
|
||||
void on_update_saved_reaction_tags(Promise<Unit> &&promise);
|
||||
|
||||
void set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise<Unit> &&promise);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &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_;
|
||||
|
@ -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_);
|
||||
|
@ -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);
|
||||
|
@ -3713,7 +3713,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentReactions
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedReactionTags> update, Promise<Unit> &&promise) {
|
||||
td_->reaction_manager_->on_update_saved_reaction_tags();
|
||||
td_->reaction_manager_->on_update_saved_reaction_tags(Promise<Unit>());
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
|
@ -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<td_api::getSavedMessagesTags>());
|
||||
} else if (op == "ssmtl") {
|
||||
string reaction;
|
||||
string label;
|
||||
get_args(args, reaction, label);
|
||||
send_request(td_api::make_object<td_api::setSavedMessagesTagLabel>(as_reaction_type(reaction), label));
|
||||
} else if (op == "gmpf") {
|
||||
ChatId chat_id;
|
||||
MessageId message_id;
|
||||
|
Loading…
Reference in New Issue
Block a user