tdlight/td/telegram/StoryViewer.cpp

61 lines
2.3 KiB
C++
Raw Normal View History

2023-08-07 15:03:10 +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)
//
#include "td/telegram/StoryViewer.h"
2023-08-07 16:19:12 +02:00
#include "td/telegram/BlockListId.h"
2023-08-07 15:03:10 +02:00
#include "td/telegram/ContactsManager.h"
#include "td/utils/algorithm.h"
#include "td/utils/logging.h"
namespace td {
td_api::object_ptr<td_api::storyViewer> StoryViewer::get_story_viewer_object(ContactsManager *contacts_manager) const {
2023-08-07 16:19:12 +02:00
auto block_list_id = BlockListId(is_blocked_, is_blocked_for_stories_);
2023-08-07 15:03:10 +02:00
return td_api::make_object<td_api::storyViewer>(
2023-08-07 16:19:12 +02:00
contacts_manager->get_user_id_object(user_id_, "get_story_viewer_object"), date_,
block_list_id.get_block_list_object(), reaction_type_.get_reaction_type_object());
2023-08-07 15:03:10 +02:00
}
StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &viewer) {
2023-08-07 16:19:12 +02:00
return string_builder << '[' << viewer.user_id_ << " with " << viewer.reaction_type_ << " at " << viewer.date_ << ']';
2023-08-07 15:03:10 +02:00
}
2023-08-07 19:49:31 +02:00
StoryViewers::StoryViewers(int32 total_count, vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views,
2023-08-07 18:40:15 +02:00
string &&next_offset)
2023-08-07 19:49:31 +02:00
: total_count_(total_count), next_offset_(std::move(next_offset)) {
2023-08-07 15:03:10 +02:00
for (auto &story_view : story_views) {
2023-08-07 16:19:12 +02:00
story_viewers_.emplace_back(std::move(story_view));
auto user_id = story_viewers_.back().get_user_id();
2023-08-07 15:03:10 +02:00
if (!user_id.is_valid()) {
2023-08-07 16:19:12 +02:00
LOG(ERROR) << "Receive invalid " << user_id << " as a viewer of a story";
story_viewers_.pop_back();
2023-08-07 15:03:10 +02:00
}
}
}
vector<UserId> StoryViewers::get_user_ids() const {
return transform(story_viewers_, [](auto &viewer) { return viewer.get_user_id(); });
}
td_api::object_ptr<td_api::storyViewers> StoryViewers::get_story_viewers_object(
ContactsManager *contacts_manager) const {
return td_api::make_object<td_api::storyViewers>(
2023-08-07 19:49:31 +02:00
total_count_,
2023-08-07 18:40:15 +02:00
transform(story_viewers_,
[contacts_manager](const StoryViewer &story_viewer) {
return story_viewer.get_story_viewer_object(contacts_manager);
}),
next_offset_);
2023-08-07 15:03:10 +02:00
}
StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewers &viewers) {
return string_builder << viewers.story_viewers_;
}
} // namespace td