tdlight/td/telegram/StoryInteractionInfo.h

87 lines
2.2 KiB
C
Raw Normal View History

2023-05-18 17:41:07 +02:00
//
// 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
2023-05-19 12:41:15 +02:00
#include "td/telegram/td_api.h"
2023-05-18 17:41:07 +02:00
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
2023-07-03 19:03:26 +02:00
class Dependencies;
2023-05-18 17:41:07 +02:00
class Td;
class StoryInteractionInfo {
vector<UserId> recent_viewer_user_ids_;
int32 view_count_ = -1;
int32 reaction_count_ = 0;
bool has_viewers_ = false;
2023-05-18 17:41:07 +02:00
static constexpr size_t MAX_RECENT_VIEWERS = 3;
friend bool operator==(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const StoryInteractionInfo &info);
public:
StoryInteractionInfo() = default;
StoryInteractionInfo(Td *td, telegram_api::object_ptr<telegram_api::storyViews> &&story_views);
bool is_empty() const {
return view_count_ < 0;
}
2023-05-19 12:41:15 +02:00
bool has_hidden_viewers() const {
return view_count_ < 0 || !has_viewers_;
}
2023-07-03 19:03:26 +02:00
void add_dependencies(Dependencies &dependencies) const;
bool set_counts(int32 view_count, int32 reaction_count) {
if (view_count != view_count_ || reaction_count != reaction_count_) {
2023-06-18 22:25:50 +02:00
view_count = view_count_;
reaction_count = reaction_count_;
2023-06-18 22:25:50 +02:00
return true;
}
return false;
}
2023-06-20 14:54:47 +02:00
int32 get_view_count() const {
return view_count_;
}
int32 get_reaction_count() const {
return reaction_count_;
}
2023-07-02 18:10:40 +02:00
bool definitely_has_no_user(UserId user_id) const;
2023-08-07 16:19:12 +02:00
bool set_recent_viewer_user_ids(vector<UserId> &&user_ids);
2023-05-19 12:41:15 +02:00
td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const;
2023-07-03 15:03:28 +02:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2023-05-18 17:41:07 +02:00
};
bool operator==(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs);
inline bool operator!=(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const StoryInteractionInfo &info);
} // namespace td