From 3aee3527511ce43ae670081f3f65a71e7c92ee2c Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 7 Sep 2020 14:07:40 +0300 Subject: [PATCH] Add MessageReplyInfo.{cpp,h}. GitOrigin-RevId: 0f5b18fdbaac549d4c5a963b067056824d373c4e --- CMakeLists.txt | 2 + td/telegram/MessageReplyInfo.cpp | 56 ++++++++++++++++++ td/telegram/MessageReplyInfo.h | 79 +++++++++++++++++++++++++ td/telegram/MessagesManager.cpp | 4 +- td/telegram/MessagesManager.h | 98 +------------------------------- 5 files changed, 139 insertions(+), 100 deletions(-) create mode 100644 td/telegram/MessageReplyInfo.cpp create mode 100644 td/telegram/MessageReplyInfo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ff647a9f5..10cd30ab8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,6 +444,7 @@ set(TDLIB_SOURCE td/telegram/MessageContentType.cpp td/telegram/MessageEntity.cpp td/telegram/MessageId.cpp + td/telegram/MessageReplyInfo.cpp td/telegram/MessagesDb.cpp td/telegram/MessageSearchFilter.cpp td/telegram/MessagesManager.cpp @@ -617,6 +618,7 @@ set(TDLIB_SOURCE td/telegram/MessageCopyOptions.h td/telegram/MessageEntity.h td/telegram/MessageId.h + td/telegram/MessageReplyInfo.h td/telegram/MessagesDb.h td/telegram/MessageSearchFilter.h td/telegram/MessagesManager.h diff --git a/td/telegram/MessageReplyInfo.cpp b/td/telegram/MessageReplyInfo.cpp new file mode 100644 index 000000000..faa84002b --- /dev/null +++ b/td/telegram/MessageReplyInfo.cpp @@ -0,0 +1,56 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/MessageReplyInfo.h" + +#include "td/utils/logging.h" + +namespace td { + +MessageReplyInfo::MessageReplyInfo(tl_object_ptr &&reply_info, bool is_bot) { + if (reply_info == nullptr) { + return; + } + if (reply_info->replies_ < 0) { + LOG(ERROR) << "Receive wrong " << to_string(reply_info); + return; + } + reply_count = reply_info->replies_; + pts = reply_info->replies_pts_; + + if (!is_bot) { + for (auto &user_id_int : reply_info->recent_repliers_) { + UserId user_id(user_id_int); + if (user_id.is_valid()) { + recent_replier_user_ids.push_back(user_id); + } else { + LOG(ERROR) << "Receive " << user_id << " as a recent replier"; + } + } + } + + is_comment = reply_info->comments_; + if (is_comment) { + channel_id = ChannelId(reply_info->channel_id_); + if (!channel_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << channel_id; + channel_id = ChannelId(); + } + } +} + +bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const { + if (other.pts < pts) { + return false; + } + return true; +} + +StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) { + return string_builder << reply_info.reply_count << " replies by " << reply_info.recent_replier_user_ids; +} + +} // namespace td \ No newline at end of file diff --git a/td/telegram/MessageReplyInfo.h b/td/telegram/MessageReplyInfo.h new file mode 100644 index 000000000..07e4c65c0 --- /dev/null +++ b/td/telegram/MessageReplyInfo.h @@ -0,0 +1,79 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/ChannelId.h" +#include "td/telegram/telegram_api.h" +#include "td/telegram/UserId.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +struct MessageReplyInfo { + int32 reply_count = -1; + int32 pts = -1; + vector recent_replier_user_ids; + ChannelId channel_id; + bool is_comment = false; + + MessageReplyInfo() = default; + + MessageReplyInfo(tl_object_ptr &&reply_info, bool is_bot); + + bool is_empty() const { + return reply_count < 0; + } + + bool need_update_to(const MessageReplyInfo &other) const; + + template + void store(StorerT &storer) const { + CHECK(!is_empty()); + bool has_recent_replier_user_ids = !recent_replier_user_ids.empty(); + bool has_channel_id = channel_id.is_valid(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_comment); + STORE_FLAG(has_recent_replier_user_ids); + STORE_FLAG(has_channel_id); + END_STORE_FLAGS(); + td::store(reply_count, storer); + td::store(pts, storer); + if (has_recent_replier_user_ids) { + td::store(recent_replier_user_ids, storer); + } + if (has_channel_id) { + td::store(channel_id, storer); + } + } + + template + void parse(ParserT &parser) { + CHECK(!is_empty()); + bool has_recent_replier_user_ids = !recent_replier_user_ids.empty(); + bool has_channel_id = channel_id.is_valid(); + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_comment); + PARSE_FLAG(has_recent_replier_user_ids); + PARSE_FLAG(has_channel_id); + END_PARSE_FLAGS(); + td::parse(reply_count, parser); + td::parse(pts, parser); + if (has_recent_replier_user_ids) { + td::parse(recent_replier_user_ids, parser); + } + if (has_channel_id) { + td::parse(channel_id, parser); + } + } +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info); + +} // namespace td \ No newline at end of file diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 46b1c6d4b..19f78f1d1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1281,13 +1281,11 @@ class GetMessagesViewsQuery : public Td::ResultHandler { } auto result = result_ptr.move_as_ok(); - if (!td->auth_manager_->is_bot()) { - td->contacts_manager_->on_get_users(std::move(result->users_), "GetMessagesViewsQuery"); - } auto interaction_infos = std::move(result->views_); if (message_ids_.size() != interaction_infos.size()) { return on_error(id, Status::Error(500, "Wrong number of message views returned")); } + td->contacts_manager_->on_get_users(std::move(result->users_), "GetMessagesViewsQuery"); for (size_t i = 0; i < message_ids_.size(); i++) { FullMessageId full_message_id{dialog_id_, message_ids_[i]}; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 113631980..d2ef8a319 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -27,6 +27,7 @@ #include "td/telegram/MessageContentType.h" #include "td/telegram/MessageCopyOptions.h" #include "td/telegram/MessageId.h" +#include "td/telegram/MessageReplyInfo.h" #include "td/telegram/MessagesDb.h" #include "td/telegram/MessageSearchFilter.h" #include "td/telegram/net/NetQuery.h" @@ -63,7 +64,6 @@ #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" -#include "td/utils/tl_helpers.h" #include "td/utils/tl_storers.h" #include @@ -141,102 +141,6 @@ class updateSentMessage : public telegram_api::Update { } }; -struct MessageReplyInfo { - int32 reply_count = -1; - int32 pts = -1; - vector recent_replier_user_ids; - ChannelId channel_id; - bool is_comment = false; - - MessageReplyInfo() = default; - MessageReplyInfo(tl_object_ptr &&reply_info, bool is_bot) { - if (reply_info == nullptr) { - return; - } - if (reply_info->replies_ < 0) { - LOG(ERROR) << "Receive wrong " << to_string(reply_info); - return; - } - reply_count = reply_info->replies_; - pts = reply_info->replies_pts_; - - if (!is_bot) { - for (auto &user_id_int : reply_info->recent_repliers_) { - UserId user_id(user_id_int); - if (user_id.is_valid()) { - recent_replier_user_ids.push_back(user_id); - } else { - LOG(ERROR) << "Receive " << user_id << " as a recent replier"; - } - } - } - - is_comment = reply_info->comments_; - if (is_comment) { - channel_id = ChannelId(reply_info->channel_id_); - if (!channel_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << channel_id; - channel_id = ChannelId(); - } - } - } - - bool is_empty() const { - return reply_count < 0; - } - - bool need_update_to(const MessageReplyInfo &other) const { - if (other.pts < pts) { - return false; - } - return true; - } - - template - void store(StorerT &storer) const { - CHECK(!is_empty()); - bool has_recent_replier_user_ids = !recent_replier_user_ids.empty(); - bool has_channel_id = channel_id.is_valid(); - BEGIN_STORE_FLAGS(); - STORE_FLAG(is_comment); - STORE_FLAG(has_recent_replier_user_ids); - STORE_FLAG(has_channel_id); - END_STORE_FLAGS(); - td::store(reply_count, storer); - td::store(pts, storer); - if (has_recent_replier_user_ids) { - td::store(recent_replier_user_ids, storer); - } - if (has_channel_id) { - td::store(channel_id, storer); - } - } - - template - void parse(ParserT &parser) { - CHECK(!is_empty()); - bool has_recent_replier_user_ids = !recent_replier_user_ids.empty(); - bool has_channel_id = channel_id.is_valid(); - BEGIN_PARSE_FLAGS(); - PARSE_FLAG(is_comment); - PARSE_FLAG(has_recent_replier_user_ids); - PARSE_FLAG(has_channel_id); - END_PARSE_FLAGS(); - td::parse(reply_count, parser); - td::parse(pts, parser); - if (has_recent_replier_user_ids) { - td::parse(recent_replier_user_ids, parser); - } - if (has_channel_id) { - td::parse(channel_id, parser); - } - } -}; - -inline StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) { - return string_builder << reply_info.reply_count << " replies by " << reply_info.recent_replier_user_ids; -} - class MessagesManager : public Actor { public: // static constexpr int32 MESSAGE_FLAG_IS_UNREAD = 1 << 0;