Add storer and parser for Story.

This commit is contained in:
levlam 2023-07-03 16:03:28 +03:00
parent b04eeb4d87
commit 36518625c3
5 changed files with 134 additions and 0 deletions

View File

@ -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

View File

@ -53,6 +53,12 @@ class StoryInteractionInfo {
void set_recent_viewer_user_ids(vector<UserId> &&user_ids);
td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs);

View File

@ -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 <class StorerT>
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 <class ParserT>
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

View File

@ -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 <class StorerT>
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 <class ParserT>
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<UploadMediaCallback>();

View File

@ -60,6 +60,12 @@ class StoryManager final : public Actor {
FormattedText caption_;
mutable int64 edit_generation_ = 0;
int64 global_id_ = 0;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
struct BeingEditedStory {