Add MessageReplyInfo.{cpp,h}.

GitOrigin-RevId: 0f5b18fdbaac549d4c5a963b067056824d373c4e
This commit is contained in:
levlam 2020-09-07 14:07:40 +03:00
parent 4655be3052
commit 3aee352751
5 changed files with 139 additions and 100 deletions

View File

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

View File

@ -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<telegram_api::messageReplies> &&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

View File

@ -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<UserId> recent_replier_user_ids;
ChannelId channel_id;
bool is_comment = false;
MessageReplyInfo() = default;
MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &&reply_info, bool is_bot);
bool is_empty() const {
return reply_count < 0;
}
bool need_update_to(const MessageReplyInfo &other) const;
template <class StorerT>
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 <class ParserT>
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

View File

@ -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]};

View File

@ -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 <array>
@ -141,102 +141,6 @@ class updateSentMessage : public telegram_api::Update {
}
};
struct MessageReplyInfo {
int32 reply_count = -1;
int32 pts = -1;
vector<UserId> recent_replier_user_ids;
ChannelId channel_id;
bool is_comment = false;
MessageReplyInfo() = default;
MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &&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 <class StorerT>
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 <class ParserT>
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;