Use MessageSender to represent recent repliers.

GitOrigin-RevId: 2078a6b936d2087a1672eb96851494508f28a465
This commit is contained in:
levlam 2020-10-18 00:07:39 +03:00
parent 9fb26c4ea2
commit 30c17d200b
5 changed files with 25 additions and 11 deletions

View File

@ -652,11 +652,11 @@ messageForwardInfo origin:MessageForwardOrigin date:int32 public_service_announc
//@description Contains information about message replies
//@reply_count Number of times the message was directly or indirectly replied
//@recent_replier_user_ids User identifiers of the recent repliers to the message; available in channels with a discussion supergroup
//@recent_repliers Recent repliers to the message; available in channels with a discussion supergroup
//@last_read_inbox_message_id Identifier of the last read incoming reply to the message
//@last_read_outbox_message_id Identifier of the last read outgoing reply to the message
//@last_message_id Identifier of the last reply to the message
messageReplyInfo reply_count:int32 recent_replier_user_ids:vector<int32> last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 last_message_id:int53 = MessageReplyInfo;
messageReplyInfo reply_count:int32 recent_repliers:vector<MessageSender> last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 last_message_id:int53 = MessageReplyInfo;
//@description Contains information about interactions with a message
//@view_count Number of times the message was viewed

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include "td/telegram/MessageReplyInfo.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/ServerMessageId.h"
#include "td/utils/logging.h"
@ -40,6 +41,7 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
for (const auto &peer : reply_info->recent_repliers_) {
DialogId dialog_id(peer);
if (dialog_id.is_valid()) {
// save all valid dialog_id, despite we can have no info about some of them
recent_replier_dialog_ids.push_back(dialog_id);
} else {
LOG(ERROR) << "Receive " << dialog_id << " as a recent replier";
@ -125,20 +127,28 @@ void MessageReplyInfo::add_reply(DialogId replier_dialog_id, MessageId reply_mes
}
td_api::object_ptr<td_api::messageReplyInfo> MessageReplyInfo::get_message_reply_info_object(
ContactsManager *contacts_manager) const {
ContactsManager *contacts_manager, const MessagesManager *messages_manager) const {
if (is_empty()) {
return nullptr;
}
vector<UserId> recent_replier_user_ids;
vector<td_api::object_ptr<td_api::MessageSender>> recent_repliers;
for (auto recent_replier_dialog_id : recent_replier_dialog_ids) {
if (recent_replier_dialog_id.get_type() == DialogType::User) {
recent_replier_user_ids.push_back(recent_replier_dialog_id.get_user_id());
auto user_id = recent_replier_dialog_id.get_user_id();
if (contacts_manager->have_min_user(user_id)) {
recent_repliers.push_back(td_api::make_object<td_api::messageSenderUser>(
contacts_manager->get_user_id_object(user_id, "get_message_reply_info_object")));
}
} else {
if (messages_manager->have_dialog(recent_replier_dialog_id)) {
recent_repliers.push_back(td_api::make_object<td_api::messageSenderChat>(recent_replier_dialog_id.get()));
}
}
}
return td_api::make_object<td_api::messageReplyInfo>(
reply_count, contacts_manager->get_user_ids_object(recent_replier_user_ids, "get_message_reply_info_object"),
last_read_inbox_message_id.get(), last_read_outbox_message_id.get(), max_message_id.get());
return td_api::make_object<td_api::messageReplyInfo>(reply_count, std::move(recent_repliers),
last_read_inbox_message_id.get(),
last_read_outbox_message_id.get(), max_message_id.get());
}
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) {

View File

@ -19,6 +19,7 @@
namespace td {
class ContactsManager;
class MessagesManager;
struct MessageReplyInfo {
int32 reply_count = -1;
@ -47,7 +48,8 @@ struct MessageReplyInfo {
void add_reply(DialogId replier_dialog_id, MessageId reply_message_id);
td_api::object_ptr<td_api::messageReplyInfo> get_message_reply_info_object(ContactsManager *contacts_manager) const;
td_api::object_ptr<td_api::messageReplyInfo> get_message_reply_info_object(
ContactsManager *contacts_manager, const MessagesManager *messages_manager) const;
template <class StorerT>
void store(StorerT &storer) const {

View File

@ -6577,7 +6577,7 @@ td_api::object_ptr<td_api::messageInteractionInfo> MessagesManager::get_message_
td_api::object_ptr<td_api::messageReplyInfo> reply_info;
if (is_visible_reply_info) {
reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get());
reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get(), this);
CHECK(reply_info != nullptr);
}
@ -16108,7 +16108,7 @@ td_api::object_ptr<td_api::messageThreadInfo> MessagesManager::get_message_threa
auto message = get_message_object(d->dialog_id, m);
if (message != nullptr) {
if (message->interaction_info_ != nullptr && message->interaction_info_->reply_info_ != nullptr) {
reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get());
reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get(), this);
CHECK(reply_info != nullptr);
}
messages.push_back(std::move(message));
@ -22368,6 +22368,8 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo
for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
if (recent_replier_dialog_id.get_type() == DialogType::User) {
dependencies.user_ids.insert(recent_replier_dialog_id.get_user_id());
} else {
add_dialog_and_dependencies(dependencies, recent_replier_dialog_id);
}
}
add_message_content_dependencies(dependencies, m->content.get());