Add td_api::getSavedMessagesTags.

This commit is contained in:
levlam 2024-01-23 16:01:27 +03:00
parent e6611cdb8f
commit 9df2ba6e64
6 changed files with 140 additions and 0 deletions

View File

@ -1624,6 +1624,13 @@ chatAvailableReactionsAll = ChatAvailableReactions;
chatAvailableReactionsSome reactions:vector<ReactionType> = ChatAvailableReactions; chatAvailableReactionsSome reactions:vector<ReactionType> = ChatAvailableReactions;
//@description Represents a tag used in Saved Messages @tag The tag @label Label of the tag; 0-12 characters @count Number of times the tag was used
savedMessagesTag tag:ReactionType label:string count:int32 = SavedMessagesTag;
//@description Contains a list of tags used in Saved Messages @tags List of tags
savedMessagesTags tags:vector<savedMessagesTag> = SavedMessagesTags;
//@description Describes a video chat //@description Describes a video chat
//@group_call_id Group call identifier of an active video chat; 0 if none. Full information about the video chat can be received through the method getGroupCall //@group_call_id Group call identifier of an active video chat; 0 if none. Full information about the video chat can be received through the method getGroupCall
//@has_participants True, if the video chat has participants //@has_participants True, if the video chat has participants
@ -7669,6 +7676,9 @@ getMessageAddedReactions chat_id:int53 message_id:int53 reaction_type:ReactionTy
//@description Changes type of default reaction for the current user @reaction_type New type of the default reaction //@description Changes type of default reaction for the current user @reaction_type New type of the default reaction
setDefaultReactionType reaction_type:ReactionType = Ok; setDefaultReactionType reaction_type:ReactionType = Ok;
//@description Returns tags used in Saved Messages
getSavedMessagesTags = SavedMessagesTags;
//@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 //@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 //@text Text in which to search for the quote

View File

@ -166,6 +166,49 @@ class SetDefaultReactionQuery final : public Td::ResultHandler {
} }
}; };
class GetSavedReactionTagsQuery final : public Td::ResultHandler {
Promise<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> promise_;
public:
explicit GetSavedReactionTagsQuery(
Promise<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> &&promise)
: promise_(std::move(promise)) {
}
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getSavedReactionTags(hash)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getSavedReactionTags>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetSavedReactionTagsQuery: " << to_string(ptr);
promise_.set_value(std::move(ptr));
}
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_) {
}
td_api::object_ptr<td_api::savedMessagesTag> ReactionManager::SavedReactionTag::get_saved_messages_tag_object() const {
return td_api::make_object<td_api::savedMessagesTag>(reaction_type_.get_reaction_type_object(), title_, count_);
}
td_api::object_ptr<td_api::savedMessagesTags> ReactionManager::SavedReactionTags::get_saved_messages_tags_object()
const {
return td_api::make_object<td_api::savedMessagesTags>(
transform(tags_, [](const SavedReactionTag &tag) { return tag.get_saved_messages_tag_object(); }));
}
ReactionManager::ReactionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { ReactionManager::ReactionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
} }
@ -652,6 +695,58 @@ void ReactionManager::send_set_default_reaction_query() {
ReactionType(td_->option_manager_->get_option_string("default_reaction"))); ReactionType(td_->option_manager_->get_option_string("default_reaction")));
} }
void ReactionManager::get_saved_messages_tags(Promise<td_api::object_ptr<td_api::savedMessagesTags>> &&promise) {
if (tags_.is_inited_) {
// return promise.set_value(tags_.get_saved_messages_tags_object());
}
auto &promises = pending_get_saved_reaction_tags_queries_;
promises.push_back(std::move(promise));
if (promises.size() != 1) {
return;
}
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> r_tags) {
send_closure(actor_id, &ReactionManager::on_get_saved_messages_tags, std::move(r_tags));
});
td_->create_handler<GetSavedReactionTagsQuery>(std::move(query_promise))->send(tags_.hash_);
}
void ReactionManager::on_get_saved_messages_tags(
Result<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> &&r_tags) {
G()->ignore_result_if_closing(r_tags);
auto promises = std::move(pending_get_saved_reaction_tags_queries_);
reset_to_empty(pending_get_saved_reaction_tags_queries_);
CHECK(!promises.empty());
if (r_tags.is_error()) {
return fail_promises(promises, r_tags.move_as_error());
}
auto tags_ptr = r_tags.move_as_ok();
switch (tags_ptr->get_id()) {
case telegram_api::messages_savedReactionTagsNotModified::ID:
// nothing to do
break;
case telegram_api::messages_savedReactionTags::ID: {
auto tags = telegram_api::move_object_as<telegram_api::messages_savedReactionTags>(tags_ptr);
vector<SavedReactionTag> saved_reaction_tags;
for (auto &tag : tags->tags_) {
saved_reaction_tags.emplace_back(std::move(tag));
}
tags_.tags_ = std::move(saved_reaction_tags);
tags_.hash_ = tags->hash_;
break;
}
default:
UNREACHABLE();
}
for (auto &promise : promises) {
promise.set_value(tags_.get_saved_messages_tags_object());
}
}
void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const { void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
return; return;

View File

@ -66,6 +66,8 @@ class ReactionManager final : public Actor {
void send_set_default_reaction_query(); void send_set_default_reaction_query();
void get_saved_messages_tags(Promise<td_api::object_ptr<td_api::savedMessagesTags>> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const; void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private: private:
@ -119,6 +121,24 @@ class ReactionManager final : public Actor {
void parse(ParserT &parser); void parse(ParserT &parser);
}; };
struct SavedReactionTag {
ReactionType reaction_type_;
string title_;
int32 count_ = 0;
explicit SavedReactionTag(telegram_api::object_ptr<telegram_api::savedReactionTag> &&tag);
td_api::object_ptr<td_api::savedMessagesTag> get_saved_messages_tag_object() const;
};
struct SavedReactionTags {
vector<SavedReactionTag> tags_;
int64 hash_ = 0;
bool is_inited_ = false;
td_api::object_ptr<td_api::savedMessagesTags> get_saved_messages_tags_object() const;
};
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji) const; td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji) const;
ReactionList &get_reaction_list(ReactionListType reaction_list_type); ReactionList &get_reaction_list(ReactionListType reaction_list_type);
@ -143,6 +163,8 @@ class ReactionManager final : public Actor {
td_api::object_ptr<td_api::updateActiveEmojiReactions> get_update_active_emoji_reactions_object() const; td_api::object_ptr<td_api::updateActiveEmojiReactions> get_update_active_emoji_reactions_object() const;
void on_get_saved_messages_tags(Result<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> &&r_tags);
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;
@ -155,6 +177,9 @@ class ReactionManager final : public Actor {
ReactionList reaction_lists_[MAX_REACTION_LIST_TYPE]; ReactionList reaction_lists_[MAX_REACTION_LIST_TYPE];
SavedReactionTags tags_;
vector<Promise<td_api::object_ptr<td_api::savedMessagesTags>>> pending_get_saved_reaction_tags_queries_;
bool are_reactions_loaded_from_database_ = false; bool are_reactions_loaded_from_database_ = false;
}; };

View File

@ -5460,6 +5460,12 @@ void Td::on_request(uint64 id, const td_api::setDefaultReactionType &request) {
reaction_manager_->set_default_reaction(ReactionType(request.reaction_type_), std::move(promise)); reaction_manager_->set_default_reaction(ReactionType(request.reaction_type_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getSavedMessagesTags &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
reaction_manager_->get_saved_messages_tags(std::move(promise));
}
void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) { void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.offset_); CLEAN_INPUT_STRING(request.offset_);

View File

@ -793,6 +793,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setDefaultReactionType &request); void on_request(uint64 id, const td_api::setDefaultReactionType &request);
void on_request(uint64 id, const td_api::getSavedMessagesTags &request);
void on_request(uint64 id, td_api::getMessagePublicForwards &request); void on_request(uint64 id, td_api::getMessagePublicForwards &request);
void on_request(uint64 id, td_api::getStoryPublicForwards &request); void on_request(uint64 id, td_api::getStoryPublicForwards &request);

View File

@ -2864,6 +2864,8 @@ class CliClient final : public Actor {
get_args(args, chat_id, message_id, reaction, offset, limit); get_args(args, chat_id, message_id, reaction, offset, limit);
send_request(td_api::make_object<td_api::getMessageAddedReactions>( send_request(td_api::make_object<td_api::getMessageAddedReactions>(
chat_id, message_id, as_reaction_type(reaction), offset, as_limit(limit))); 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 == "gmpf") { } else if (op == "gmpf") {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;