From 36518625c34742610aec3c0676998ebaf1f510fe Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 3 Jul 2023 16:03:28 +0300 Subject: [PATCH] Add storer and parser for Story. --- CMakeLists.txt | 1 + td/telegram/StoryInteractionInfo.h | 6 +++ td/telegram/StoryInteractionInfo.hpp | 42 +++++++++++++++ td/telegram/StoryManager.cpp | 79 ++++++++++++++++++++++++++++ td/telegram/StoryManager.h | 6 +++ 5 files changed, 134 insertions(+) create mode 100644 td/telegram/StoryInteractionInfo.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e0ac94c4..5006b4d37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -841,6 +841,7 @@ set(TDLIB_SOURCE td/telegram/StickerMaskPosition.hpp td/telegram/StickerPhotoSize.hpp td/telegram/StickersManager.hpp + td/telegram/StoryInteractionInfo.hpp td/telegram/TranscriptionInfo.hpp td/telegram/VideoNotesManager.hpp td/telegram/VideosManager.hpp diff --git a/td/telegram/StoryInteractionInfo.h b/td/telegram/StoryInteractionInfo.h index 66504411d..ae8410abb 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -53,6 +53,12 @@ class StoryInteractionInfo { void set_recent_viewer_user_ids(vector &&user_ids); td_api::object_ptr get_story_interaction_info_object(Td *td) const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); }; bool operator==(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs); diff --git a/td/telegram/StoryInteractionInfo.hpp b/td/telegram/StoryInteractionInfo.hpp new file mode 100644 index 000000000..9501d4b08 --- /dev/null +++ b/td/telegram/StoryInteractionInfo.hpp @@ -0,0 +1,42 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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/StoryInteractionInfo.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void StoryInteractionInfo::store(StorerT &storer) const { + using td::store; + bool has_recent_viewer_user_ids = !recent_viewer_user_ids_.empty(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_recent_viewer_user_ids); + END_STORE_FLAGS(); + store(view_count_, storer); + if (has_recent_viewer_user_ids) { + store(recent_viewer_user_ids_, storer); + } +} + +template +void StoryInteractionInfo::parse(ParserT &parser) { + using td::parse; + bool has_recent_viewer_user_ids; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_recent_viewer_user_ids); + END_PARSE_FLAGS(); + parse(view_count_, parser); + if (has_recent_viewer_user_ids) { + parse(recent_viewer_user_ids_, parser); + } +} + +} // namespace td diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 3d9b8d0ac..d18c19ea3 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -21,6 +21,7 @@ #include "td/telegram/OptionManager.h" #include "td/telegram/ReportReason.h" #include "td/telegram/StoryContent.h" +#include "td/telegram/StoryInteractionInfo.hpp" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" #include "td/telegram/telegram_api.h" @@ -690,6 +691,84 @@ StoryManager::PendingStory::PendingStory(DialogId dialog_id, StoryId story_id, u , story_(std::move(story)) { } +template +void StoryManager::Story::store(StorerT &storer) const { + using td::store; + bool has_receive_date = receive_date_ != 0; + bool has_interaction_info = !interaction_info_.is_empty(); + bool has_privacy_rules = privacy_rules_ != UserPrivacySettingRules(); + bool has_content = content_ != nullptr; + bool has_caption = !caption_.text.empty(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_edited_); + STORE_FLAG(is_pinned_); + STORE_FLAG(is_public_); + STORE_FLAG(is_for_close_friends_); + STORE_FLAG(noforwards_); + STORE_FLAG(has_receive_date); + STORE_FLAG(has_interaction_info); + STORE_FLAG(has_privacy_rules); + STORE_FLAG(has_content); + STORE_FLAG(has_caption); + END_STORE_FLAGS(); + store(date_, storer); + store(expire_date_, storer); + if (has_receive_date) { + store(receive_date_, storer); + } + if (has_interaction_info) { + store(interaction_info_, storer); + } + if (has_privacy_rules) { + store(privacy_rules_, storer); + } + if (has_content) { + store_story_content(content_.get(), storer); + } + if (has_caption) { + store(caption_, storer); + } +} + +template +void StoryManager::Story::parse(ParserT &parser) { + using td::parse; + bool has_receive_date; + bool has_interaction_info; + bool has_privacy_rules; + bool has_content; + bool has_caption; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_edited_); + PARSE_FLAG(is_pinned_); + PARSE_FLAG(is_public_); + PARSE_FLAG(is_for_close_friends_); + PARSE_FLAG(noforwards_); + PARSE_FLAG(has_receive_date); + PARSE_FLAG(has_interaction_info); + PARSE_FLAG(has_privacy_rules); + PARSE_FLAG(has_content); + PARSE_FLAG(has_caption); + END_PARSE_FLAGS(); + parse(date_, parser); + parse(expire_date_, parser); + if (has_receive_date) { + parse(receive_date_, parser); + } + if (has_interaction_info) { + parse(interaction_info_, parser); + } + if (has_privacy_rules) { + parse(privacy_rules_, parser); + } + if (has_content) { + parse_story_content(content_, parser); + } + if (has_caption) { + parse(caption_, parser); + } +} + StoryManager::StoryManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { upload_media_callback_ = std::make_shared(); diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 89e4a8d24..d63632858 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -60,6 +60,12 @@ class StoryManager final : public Actor { FormattedText caption_; mutable int64 edit_generation_ = 0; int64 global_id_ = 0; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); }; struct BeingEditedStory {