Remove class AvailableReaction.

This commit is contained in:
levlam 2022-09-08 17:45:19 +03:00
parent 43109ecc96
commit c6d5bbb151
7 changed files with 29 additions and 49 deletions

View File

@ -10,20 +10,17 @@
namespace td {
AvailableReactionType get_reaction_type(const vector<AvailableReaction> &available_reactions, const string &reaction) {
AvailableReactionType get_reaction_type(const vector<string> &available_reactions, const string &reaction) {
if (reaction[0] == '#') {
return AvailableReactionType::NeedsPremium;
}
for (auto &available_reaction : available_reactions) {
if (available_reaction.reaction_ == reaction) {
return AvailableReactionType::Available;
}
if (contains(available_reactions, reaction)) {
return AvailableReactionType::Available;
}
return AvailableReactionType::Unavailable;
}
ChatReactions get_active_reactions(const ChatReactions &available_reactions,
const vector<AvailableReaction> &active_reactions) {
ChatReactions get_active_reactions(const ChatReactions &available_reactions, const vector<string> &active_reactions) {
if (available_reactions.reactions_.empty()) {
// fast path
return available_reactions;
@ -33,15 +30,11 @@ ChatReactions get_active_reactions(const ChatReactions &available_reactions,
vector<string> result;
for (const auto &active_reaction : active_reactions) {
if (td::contains(available_reactions.reactions_, active_reaction.reaction_)) {
result.push_back(active_reaction.reaction_);
if (td::contains(available_reactions.reactions_, active_reaction)) {
result.push_back(active_reaction);
}
}
return ChatReactions(std::move(result));
}
bool operator==(const AvailableReaction &lhs, const AvailableReaction &rhs) {
return lhs.reaction_ == rhs.reaction_;
}
} // namespace td

View File

@ -13,24 +13,10 @@
namespace td {
struct AvailableReaction {
string reaction_;
explicit AvailableReaction(const string &reaction) : reaction_(reaction) {
}
};
bool operator==(const AvailableReaction &lhs, const AvailableReaction &rhs);
inline bool operator!=(const AvailableReaction &lhs, const AvailableReaction &rhs) {
return !(lhs == rhs);
}
enum class AvailableReactionType : int32 { Unavailable, Available, NeedsPremium };
AvailableReactionType get_reaction_type(const vector<AvailableReaction> &reactions, const string &reaction);
AvailableReactionType get_reaction_type(const vector<string> &reactions, const string &reaction);
ChatReactions get_active_reactions(const ChatReactions &available_reactions,
const vector<AvailableReaction> &active_reactions);
ChatReactions get_active_reactions(const ChatReactions &available_reactions, const vector<string> &active_reactions);
} // namespace td

View File

@ -7,6 +7,7 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/AvailableReaction.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
@ -8236,7 +8237,7 @@ void MessagesManager::hide_dialog_message_reactions(Dialog *d) {
}
}
void MessagesManager::set_active_reactions(vector<AvailableReaction> active_reactions) {
void MessagesManager::set_active_reactions(vector<string> active_reactions) {
if (active_reactions == active_reactions_) {
return;
}
@ -8246,8 +8247,8 @@ void MessagesManager::set_active_reactions(vector<AvailableReaction> active_reac
active_reaction_pos_.clear();
bool is_changed = old_active_reactions.size() != active_reactions_.size();
for (size_t i = 0; i < active_reactions_.size(); i++) {
active_reaction_pos_[active_reactions_[i].reaction_] = i;
if (!is_changed && active_reactions_[i].reaction_ != old_active_reactions[i].reaction_) {
active_reaction_pos_[active_reactions_[i]] = i;
if (!is_changed && active_reactions_[i] != old_active_reactions[i]) {
is_changed = true;
}
}
@ -24458,7 +24459,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
set_promises(promises);
}
Result<vector<AvailableReaction>> MessagesManager::get_message_available_reactions(FullMessageId full_message_id) {
Result<vector<string>> MessagesManager::get_message_available_reactions(FullMessageId full_message_id) {
auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id, "get_message_available_reactions");
if (d == nullptr) {
@ -24472,7 +24473,7 @@ Result<vector<AvailableReaction>> MessagesManager::get_message_available_reactio
return get_message_available_reactions(d, m);
}
vector<AvailableReaction> MessagesManager::get_message_available_reactions(const Dialog *d, const Message *m) {
vector<string> MessagesManager::get_message_available_reactions(const Dialog *d, const Message *m) {
CHECK(d != nullptr);
CHECK(m != nullptr);
auto active_reactions = get_message_active_reactions(d, m);
@ -24490,7 +24491,7 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
}
}
vector<AvailableReaction> result;
vector<string> result;
if (can_use_reactions) {
int64 reactions_uniq_max = td_->option_manager_->get_option_integer("reactions_uniq_max", 11);
bool can_add_new_reactions =
@ -24498,10 +24499,10 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
// can add only active available reactions or remove previously set reaction
for (const auto &active_reaction : active_reactions_) {
// can add the reaction if it has already been used for the message or is available in the chat
bool is_set = (m->reactions != nullptr && m->reactions->get_reaction(active_reaction.reaction_) != nullptr);
if (is_set || (can_add_new_reactions && (active_reactions.allow_all_ ||
td::contains(active_reactions.reactions_, active_reaction.reaction_)))) {
result.emplace_back(active_reaction.reaction_);
bool is_set = (m->reactions != nullptr && m->reactions->get_reaction(active_reaction) != nullptr);
if (is_set || (can_add_new_reactions &&
(active_reactions.allow_all_ || td::contains(active_reactions.reactions_, active_reaction)))) {
result.push_back(active_reaction);
}
}
}
@ -24511,7 +24512,7 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
get_reaction_type(result, reaction.get_reaction()) == AvailableReactionType::Unavailable) {
CHECK(!can_use_reactions ||
get_reaction_type(active_reactions_, reaction.get_reaction()) == AvailableReactionType::Unavailable);
result.emplace_back(reaction.get_reaction());
result.push_back(reaction.get_reaction());
}
}
}

View File

@ -8,7 +8,6 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AffectedHistory.h"
#include "td/telegram/AvailableReaction.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChatReactions.h"
#include "td/telegram/DialogAction.h"
@ -538,7 +537,7 @@ class MessagesManager final : public Actor {
void set_dialog_description(DialogId dialog_id, const string &description, Promise<Unit> &&promise);
void set_active_reactions(vector<AvailableReaction> active_reactions);
void set_active_reactions(vector<string> active_reactions);
void set_dialog_available_reactions(DialogId dialog_id,
td_api::object_ptr<td_api::ChatAvailableReactions> &&available_reactions_ptr,
@ -806,7 +805,7 @@ class MessagesManager final : public Actor {
vector<MessageId> get_dialog_scheduled_messages(DialogId dialog_id, bool force, bool ignore_result,
Promise<Unit> &&promise);
Result<vector<AvailableReaction>> get_message_available_reactions(FullMessageId full_message_id);
Result<vector<string>> get_message_available_reactions(FullMessageId full_message_id);
void set_message_reaction(FullMessageId full_message_id, string reaction, bool is_big, bool add_to_recent,
Promise<Unit> &&promise);
@ -2688,7 +2687,7 @@ class MessagesManager final : public Actor {
bool update_dialog_silent_send_message(Dialog *d, bool silent_send_message);
vector<AvailableReaction> get_message_available_reactions(const Dialog *d, const Message *m);
vector<string> get_message_available_reactions(const Dialog *d, const Message *m);
void on_set_message_reaction(FullMessageId full_message_id, Result<Unit> result, Promise<Unit> promise);
@ -3735,7 +3734,7 @@ class MessagesManager final : public Actor {
};
FlatHashMap<FullMessageId, PendingReaction, FullMessageIdHash> pending_reactions_;
vector<AvailableReaction> active_reactions_;
vector<string> active_reactions_;
FlatHashMap<string, size_t> active_reaction_pos_;
uint32 scheduled_messages_sync_generation_ = 1;

View File

@ -8,7 +8,6 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/AvailableReaction.h"
#include "td/telegram/ConfigManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
@ -3699,7 +3698,7 @@ void StickersManager::load_reactions() {
}
void StickersManager::update_active_reactions() {
vector<AvailableReaction> active_reactions;
vector<string> active_reactions;
for (auto &reaction : reactions_.reactions_) {
if (reaction.is_active_) {
active_reactions.emplace_back(reaction.reaction_);

View File

@ -5206,8 +5206,7 @@ void Td::on_request(uint64 id, const td_api::getMessageAvailableReactions &reque
if (r_reactions.is_error()) {
send_closure(actor_id(this), &Td::send_error, id, r_reactions.move_as_error());
} else {
auto reactions =
transform(r_reactions.ok(), [](auto &reaction) { return get_reaction_type_object(reaction.reaction_); });
auto reactions = transform(r_reactions.ok(), [](auto &reaction) { return get_reaction_type_object(reaction); });
send_closure(actor_id(this), &Td::send_result, id,
td_api::make_object<td_api::availableReactions>(std::move(reactions)));
}

View File

@ -101,6 +101,7 @@ class FileDb final : public FileDbInterface {
pmc.commit_transaction().ensure();
}
void store_file_data(FileDbId id, const string &file_data, const string &remote_key, const string &local_key,
const string &generate_key) {
auto &pmc = file_pmc();
@ -125,6 +126,7 @@ class FileDb final : public FileDbInterface {
pmc.commit_transaction().ensure();
}
void store_file_data_ref(FileDbId id, FileDbId new_id) {
auto &pmc = file_pmc();
pmc.begin_write_transaction().ensure();
@ -202,6 +204,7 @@ class FileDb final : public FileDbInterface {
}
send_closure(file_db_actor_, &FileDbActor::clear_file_data, id, remote_key, local_key, generate_key);
}
void set_file_data(FileDbId id, const FileData &file_data, bool new_remote, bool new_local, bool new_generate) final {
string remote_key;
if (file_data.remote_.type() == RemoteFileLocation::Type::Full && new_remote) {