tdlight/td/telegram/MessageReaction.hpp

161 lines
4.7 KiB
C++
Raw Normal View History

2022-01-20 20:54:34 +01:00
//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
2022-01-20 20:54:34 +01: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
#include "td/telegram/MessageReaction.h"
2024-08-01 22:19:31 +02:00
#include "td/telegram/MessageReactor.hpp"
2023-04-25 15:41:04 +02:00
#include "td/telegram/MinChannel.hpp"
2023-08-04 17:39:07 +02:00
#include "td/telegram/ReactionType.hpp"
2022-01-20 20:54:34 +01:00
2023-07-13 12:54:58 +02:00
#include "td/utils/algorithm.h"
2022-01-20 20:54:34 +01:00
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void MessageReaction::store(StorerT &storer) const {
CHECK(!is_empty());
bool has_recent_chooser_dialog_ids = !recent_chooser_dialog_ids_.empty();
bool has_recent_chooser_min_channels = !recent_chooser_min_channels_.empty();
2023-04-27 15:20:54 +02:00
bool has_my_recent_chooser_dialog_id = my_recent_chooser_dialog_id_.is_valid();
2022-01-20 20:54:34 +01:00
BEGIN_STORE_FLAGS();
STORE_FLAG(is_chosen_);
STORE_FLAG(has_recent_chooser_dialog_ids);
STORE_FLAG(has_recent_chooser_min_channels);
2023-04-27 15:20:54 +02:00
STORE_FLAG(has_my_recent_chooser_dialog_id);
2022-01-20 20:54:34 +01:00
END_STORE_FLAGS();
2023-08-04 17:39:07 +02:00
td::store(reaction_type_, storer);
2022-01-20 20:54:34 +01:00
td::store(choose_count_, storer);
if (has_recent_chooser_dialog_ids) {
td::store(recent_chooser_dialog_ids_, storer);
}
if (has_recent_chooser_min_channels) {
td::store(recent_chooser_min_channels_, storer);
2022-01-20 20:54:34 +01:00
}
2023-04-27 15:20:54 +02:00
if (has_my_recent_chooser_dialog_id) {
td::store(my_recent_chooser_dialog_id_, storer);
}
2022-01-20 20:54:34 +01:00
}
template <class ParserT>
void MessageReaction::parse(ParserT &parser) {
bool has_recent_chooser_dialog_ids;
bool has_recent_chooser_min_channels;
2023-04-27 15:20:54 +02:00
bool has_my_recent_chooser_dialog_id;
2022-01-20 20:54:34 +01:00
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_chosen_);
PARSE_FLAG(has_recent_chooser_dialog_ids);
PARSE_FLAG(has_recent_chooser_min_channels);
2023-04-27 15:20:54 +02:00
PARSE_FLAG(has_my_recent_chooser_dialog_id);
2022-01-20 20:54:34 +01:00
END_PARSE_FLAGS();
2023-08-04 17:39:07 +02:00
td::parse(reaction_type_, parser);
2022-01-20 20:54:34 +01:00
td::parse(choose_count_, parser);
if (has_recent_chooser_dialog_ids) {
td::parse(recent_chooser_dialog_ids_, parser);
}
if (has_recent_chooser_min_channels) {
td::parse(recent_chooser_min_channels_, parser);
2022-01-20 20:54:34 +01:00
}
2023-04-27 15:20:54 +02:00
if (has_my_recent_chooser_dialog_id) {
td::parse(my_recent_chooser_dialog_id_, parser);
if (!my_recent_chooser_dialog_id_.is_valid() ||
!td::contains(recent_chooser_dialog_ids_, my_recent_chooser_dialog_id_)) {
return parser.set_error("Invalid recent reaction chooser");
}
2023-04-27 15:20:54 +02:00
}
fix_choose_count();
if (is_empty() || reaction_type_.is_empty()) {
parser.set_error("Invalid message reaction");
}
2022-01-20 20:54:34 +01:00
}
2022-01-28 15:10:17 +01:00
template <class StorerT>
void UnreadMessageReaction::store(StorerT &storer) const {
BEGIN_STORE_FLAGS();
STORE_FLAG(is_big_);
END_STORE_FLAGS();
2023-08-04 17:39:07 +02:00
td::store(reaction_type_, storer);
2022-01-28 15:10:17 +01:00
td::store(sender_dialog_id_, storer);
}
template <class ParserT>
void UnreadMessageReaction::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_big_);
END_PARSE_FLAGS();
2023-08-04 17:39:07 +02:00
td::parse(reaction_type_, parser);
2022-01-28 15:10:17 +01:00
td::parse(sender_dialog_id_, parser);
if (reaction_type_.is_empty()) {
parser.set_error("Invalid unread message reaction");
}
2022-01-28 15:10:17 +01:00
}
2022-01-20 20:54:34 +01:00
template <class StorerT>
void MessageReactions::store(StorerT &storer) const {
bool has_reactions = !reactions_.empty();
2022-01-28 15:10:17 +01:00
bool has_unread_reactions = !unread_reactions_.empty();
2022-09-11 12:35:25 +02:00
bool has_chosen_reaction_order = !chosen_reaction_order_.empty();
2024-08-01 22:19:31 +02:00
bool has_top_reactors = !top_reactors_.empty();
2022-01-20 20:54:34 +01:00
BEGIN_STORE_FLAGS();
STORE_FLAG(is_min_);
STORE_FLAG(need_polling_);
2022-01-30 11:24:27 +01:00
STORE_FLAG(can_get_added_reactions_);
2022-01-28 15:10:17 +01:00
STORE_FLAG(has_unread_reactions);
2022-01-20 20:54:34 +01:00
STORE_FLAG(has_reactions);
2022-09-11 12:35:25 +02:00
STORE_FLAG(has_chosen_reaction_order);
STORE_FLAG(are_tags_);
2024-08-01 22:19:31 +02:00
STORE_FLAG(has_top_reactors);
2022-01-20 20:54:34 +01:00
END_STORE_FLAGS();
if (has_reactions) {
td::store(reactions_, storer);
}
2022-01-28 15:10:17 +01:00
if (has_unread_reactions) {
td::store(unread_reactions_, storer);
}
2022-09-11 12:35:25 +02:00
if (has_chosen_reaction_order) {
td::store(chosen_reaction_order_, storer);
}
2024-08-01 22:19:31 +02:00
if (has_top_reactors) {
td::store(top_reactors_, storer);
}
2022-01-20 20:54:34 +01:00
}
template <class ParserT>
void MessageReactions::parse(ParserT &parser) {
bool has_reactions;
2022-01-28 15:10:17 +01:00
bool has_unread_reactions;
2022-09-11 12:35:25 +02:00
bool has_chosen_reaction_order;
2024-08-01 22:19:31 +02:00
bool has_top_reactors;
2022-01-20 20:54:34 +01:00
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_min_);
PARSE_FLAG(need_polling_);
2022-01-30 11:24:27 +01:00
PARSE_FLAG(can_get_added_reactions_);
2022-01-28 15:10:17 +01:00
PARSE_FLAG(has_unread_reactions);
2022-01-20 20:54:34 +01:00
PARSE_FLAG(has_reactions);
2022-09-11 12:35:25 +02:00
PARSE_FLAG(has_chosen_reaction_order);
PARSE_FLAG(are_tags_);
2024-08-01 22:19:31 +02:00
PARSE_FLAG(has_top_reactors);
2022-01-20 20:54:34 +01:00
END_PARSE_FLAGS();
if (has_reactions) {
td::parse(reactions_, parser);
}
2022-01-28 15:10:17 +01:00
if (has_unread_reactions) {
td::parse(unread_reactions_, parser);
}
2022-09-11 12:35:25 +02:00
if (has_chosen_reaction_order) {
td::parse(chosen_reaction_order_, parser);
}
2024-08-01 22:19:31 +02:00
if (has_top_reactors) {
td::parse(top_reactors_, parser);
}
2022-01-20 20:54:34 +01:00
}
} // namespace td