tdlight/td/telegram/MessageInputReplyTo.cpp

103 lines
3.8 KiB
C++
Raw Normal View History

2023-06-08 16:27:24 +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/MessageInputReplyTo.h"
#include "td/telegram/ContactsManager.h"
2023-07-01 15:22:01 +02:00
#include "td/telegram/DialogId.h"
2023-10-24 14:02:57 +02:00
#include "td/telegram/MessagesManager.h"
2023-07-01 15:22:01 +02:00
#include "td/telegram/StoryId.h"
2023-06-08 16:27:24 +02:00
#include "td/telegram/Td.h"
2023-07-01 15:22:01 +02:00
#include "td/utils/logging.h"
2023-06-08 16:27:24 +02:00
namespace td {
2023-09-05 18:31:14 +02:00
/*
MessageInputReplyTo::MessageInputReplyTo(const td_api::object_ptr<td_api::InputMessageReplyTo> &reply_to_ptr) {
2023-06-08 16:27:24 +02:00
if (reply_to_ptr == nullptr) {
return;
}
switch (reply_to_ptr->get_id()) {
case td_api::inputMessageReplyToMessage::ID: {
auto reply_to = static_cast<const td_api::inputMessageReplyToMessage *>(reply_to_ptr.get());
2023-06-08 16:27:24 +02:00
message_id_ = MessageId(reply_to->message_id_);
break;
}
case td_api::inputMessageReplyToStory::ID: {
auto reply_to = static_cast<const td_api::inputMessageReplyToStory *>(reply_to_ptr.get());
story_full_id_ = {DialogId(reply_to->story_sender_chat_id_), StoryId(reply_to->story_id_)};
2023-06-08 16:27:24 +02:00
break;
}
default:
UNREACHABLE();
}
}
2023-09-05 18:31:14 +02:00
*/
2023-06-08 16:27:24 +02:00
telegram_api::object_ptr<telegram_api::InputReplyTo> MessageInputReplyTo::get_input_reply_to(
Td *td, MessageId top_thread_message_id) const {
if (story_full_id_.is_valid()) {
auto dialog_id = story_full_id_.get_dialog_id();
CHECK(dialog_id.get_type() == DialogType::User);
auto r_input_user = td->contacts_manager_->get_input_user(dialog_id.get_user_id());
if (r_input_user.is_error()) {
LOG(ERROR) << "Failed to get input user for " << story_full_id_;
return nullptr;
}
return telegram_api::make_object<telegram_api::inputReplyToStory>(r_input_user.move_as_ok(),
story_full_id_.get_story_id().get());
}
auto reply_to_message_id = message_id_;
if (reply_to_message_id == MessageId()) {
if (top_thread_message_id == MessageId()) {
return nullptr;
}
reply_to_message_id = top_thread_message_id;
}
CHECK(reply_to_message_id.is_server());
int32 flags = 0;
if (top_thread_message_id != MessageId()) {
CHECK(top_thread_message_id.is_server());
flags |= telegram_api::inputReplyToMessage::TOP_MSG_ID_MASK;
}
return telegram_api::make_object<telegram_api::inputReplyToMessage>(
2023-09-28 15:13:36 +02:00
flags, reply_to_message_id.get_server_message_id().get(), top_thread_message_id.get_server_message_id().get(),
nullptr, string(), Auto());
2023-06-08 16:27:24 +02:00
}
2023-10-24 14:02:57 +02:00
td_api::object_ptr<td_api::InputMessageReplyTo> MessageInputReplyTo::get_input_message_reply_to_object(
Td *td, DialogId dialog_id) const {
CHECK(dialog_id.is_valid());
if (story_full_id_.is_valid()) {
return td_api::make_object<td_api::inputMessageReplyToStory>(
td->messages_manager_->get_chat_id_object(story_full_id_.get_dialog_id(), "inputMessageReplyToStory"),
story_full_id_.get_story_id().get());
}
if (!message_id_.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::inputMessageReplyToMessage>(message_id_.get());
}
bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) {
return lhs.message_id_ == rhs.message_id_ && lhs.story_full_id_ == rhs.story_full_id_;
}
bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) {
return !(lhs == rhs);
}
2023-06-08 16:27:24 +02:00
StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to) {
if (input_reply_to.message_id_.is_valid()) {
return string_builder << input_reply_to.message_id_;
}
if (input_reply_to.story_full_id_.is_valid()) {
return string_builder << input_reply_to.story_full_id_;
}
return string_builder << "nothing";
}
} // namespace td