Add td_api::updateSavedMessagesTags.

This commit is contained in:
levlam 2024-01-23 16:23:35 +03:00
parent 9df2ba6e64
commit 291cd4203a
3 changed files with 49 additions and 1 deletions

View File

@ -6678,6 +6678,9 @@ updateActiveEmojiReactions emojis:vector<string> = Update;
//@description The type of default reaction has changed @reaction_type The new type of the default reaction
updateDefaultReactionType reaction_type:ReactionType = Update;
//@description Used Saved Messages tags has changed @tags The new used tags
updateSavedMessagesTags tags:savedMessagesTags = Update;
//@description The parameters of speech recognition without Telegram Premium subscription has changed
//@max_media_duration The maximum allowed duration of media for speech recognition without Telegram Premium subscription
//@weekly_count The total number of allowed speech recognitions per week; 0 if none

View File

@ -26,6 +26,9 @@
#include "td/utils/ScopeGuard.h"
#include "td/utils/Status.h"
#include <algorithm>
#include <tuple>
namespace td {
class GetAvailableReactionsQuery final : public Td::ResultHandler {
@ -203,6 +206,18 @@ td_api::object_ptr<td_api::savedMessagesTag> ReactionManager::SavedReactionTag::
return td_api::make_object<td_api::savedMessagesTag>(reaction_type_.get_reaction_type_object(), title_, count_);
}
bool operator==(const ReactionManager::SavedReactionTag &lhs, const ReactionManager::SavedReactionTag &rhs) {
return lhs.reaction_type_ == rhs.reaction_type_ && lhs.title_ == rhs.title_ && lhs.count_ == rhs.count_;
}
bool operator!=(const ReactionManager::SavedReactionTag &lhs, const ReactionManager::SavedReactionTag &rhs) {
return !(lhs == rhs);
}
bool operator<(const ReactionManager::SavedReactionTag &lhs, const ReactionManager::SavedReactionTag &rhs) {
return std::tie(lhs.count_, lhs.title_, lhs.reaction_type_) < std::tie(rhs.count_, rhs.title_, rhs.reaction_type_);
}
td_api::object_ptr<td_api::savedMessagesTags> ReactionManager::SavedReactionTags::get_saved_messages_tags_object()
const {
return td_api::make_object<td_api::savedMessagesTags>(
@ -724,6 +739,7 @@ void ReactionManager::on_get_saved_messages_tags(
}
auto tags_ptr = r_tags.move_as_ok();
bool need_send_update = false;
switch (tags_ptr->get_id()) {
case telegram_api::messages_savedReactionTagsNotModified::ID:
// nothing to do
@ -734,19 +750,35 @@ void ReactionManager::on_get_saved_messages_tags(
for (auto &tag : tags->tags_) {
saved_reaction_tags.emplace_back(std::move(tag));
}
tags_.tags_ = std::move(saved_reaction_tags);
std::sort(saved_reaction_tags.begin(), saved_reaction_tags.end());
tags_.hash_ = tags->hash_;
if (saved_reaction_tags != tags_.tags_) {
tags_.tags_ = std::move(saved_reaction_tags);
need_send_update = true;
}
tags_.is_inited_ = true;
break;
}
default:
UNREACHABLE();
}
if (need_send_update) {
send_update_saved_messages_tags();
}
for (auto &promise : promises) {
promise.set_value(tags_.get_saved_messages_tags_object());
}
}
td_api::object_ptr<td_api::updateSavedMessagesTags> ReactionManager::get_update_saved_messages_tags_object() const {
return td_api::make_object<td_api::updateSavedMessagesTags>(tags_.get_saved_messages_tags_object());
}
void ReactionManager::send_update_saved_messages_tags() {
send_closure(G()->td(), &Td::send_update, get_update_saved_messages_tags_object());
}
void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
if (td_->auth_manager_->is_bot()) {
return;
@ -755,6 +787,9 @@ void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update
if (!active_reaction_types_.empty()) {
updates.push_back(get_update_active_emoji_reactions_object());
}
if (tags_.is_inited_) {
updates.push_back(get_update_saved_messages_tags_object());
}
}
} // namespace td

View File

@ -131,6 +131,12 @@ class ReactionManager final : public Actor {
td_api::object_ptr<td_api::savedMessagesTag> get_saved_messages_tag_object() const;
};
friend bool operator==(const SavedReactionTag &lhs, const SavedReactionTag &rhs);
friend bool operator!=(const SavedReactionTag &lhs, const SavedReactionTag &rhs);
friend bool operator<(const SavedReactionTag &lhs, const SavedReactionTag &rhs);
struct SavedReactionTags {
vector<SavedReactionTag> tags_;
int64 hash_ = 0;
@ -165,6 +171,10 @@ class ReactionManager final : public Actor {
void on_get_saved_messages_tags(Result<telegram_api::object_ptr<telegram_api::messages_SavedReactionTags>> &&r_tags);
td_api::object_ptr<td_api::updateSavedMessagesTags> get_update_saved_messages_tags_object() const;
void send_update_saved_messages_tags();
Td *td_;
ActorShared<> parent_;