tdlight/td/telegram/ChatReactions.h

86 lines
2.5 KiB
C
Raw Normal View History

2022-08-30 10:45:27 +02:00
//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
2022-08-30 10:45:27 +02:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
2023-08-04 17:39:07 +02:00
#include "td/telegram/ReactionType.h"
2022-08-30 10:45:27 +02:00
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
2022-09-08 20:04:23 +02:00
#include "td/utils/FlatHashMap.h"
2022-08-30 10:45:27 +02:00
#include "td/utils/StringBuilder.h"
#include "td/utils/tl_helpers.h"
namespace td {
struct ChatReactions {
2023-08-04 17:39:07 +02:00
vector<ReactionType> reaction_types_;
2022-08-30 10:45:27 +02:00
bool allow_all_ = false; // implies empty reactions
bool allow_custom_ = false; // implies allow_all
ChatReactions() = default;
2023-08-04 17:39:07 +02:00
explicit ChatReactions(vector<ReactionType> &&reactions) : reaction_types_(std::move(reactions)) {
2022-08-30 10:45:27 +02:00
}
explicit ChatReactions(telegram_api::object_ptr<telegram_api::ChatReactions> &&chat_reactions_ptr);
ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions> &&chat_reactions_ptr, bool allow_custom);
ChatReactions(bool allow_all, bool allow_custom) : allow_all_(allow_all), allow_custom_(allow_custom) {
}
2023-08-04 17:39:07 +02:00
ChatReactions get_active_reactions(
const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) const;
2023-08-04 17:39:07 +02:00
bool is_allowed_reaction_type(const ReactionType &reaction) const;
2022-08-30 10:45:27 +02:00
telegram_api::object_ptr<telegram_api::ChatReactions> get_input_chat_reactions() const;
td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const;
bool empty() const {
2023-08-04 17:39:07 +02:00
return reaction_types_.empty() && !allow_all_;
2022-08-30 10:45:27 +02:00
}
template <class StorerT>
void store(StorerT &storer) const {
2023-08-04 17:39:07 +02:00
bool has_reactions = !reaction_types_.empty();
2022-08-30 10:45:27 +02:00
BEGIN_STORE_FLAGS();
STORE_FLAG(allow_all_);
STORE_FLAG(allow_custom_);
STORE_FLAG(has_reactions);
END_STORE_FLAGS();
if (has_reactions) {
2023-08-04 17:39:07 +02:00
td::store(reaction_types_, storer);
2022-08-30 10:45:27 +02:00
}
}
template <class ParserT>
void parse(ParserT &parser) {
bool has_reactions;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(allow_all_);
PARSE_FLAG(allow_custom_);
PARSE_FLAG(has_reactions);
END_PARSE_FLAGS();
if (has_reactions) {
2023-08-04 17:39:07 +02:00
td::parse(reaction_types_, parser);
2022-08-30 10:45:27 +02:00
}
}
};
bool operator==(const ChatReactions &lhs, const ChatReactions &rhs);
inline bool operator!=(const ChatReactions &lhs, const ChatReactions &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const ChatReactions &reactions);
} // namespace td