Add inputMessageReplyToMessage.chat_id.

This commit is contained in:
levlam 2023-10-29 00:50:33 +03:00
parent 25eebd3d6f
commit 6e217d1aac
11 changed files with 87 additions and 48 deletions

View File

@ -1245,9 +1245,10 @@ messageReplyToStory story_sender_chat_id:int53 story_id:int32 = MessageReplyTo;
//@class InputMessageReplyTo @description Contains information about the message or the story to be replied
//@description Describes a message to be replied
//@chat_id The identifier of the chat to which the message to be replied belongs; pass 0 if the replied message is in the same chat
//@message_id The identifier of the message to be replied in the same chat
//@quote Manually chosen quote from the replied message; pass null if none; 0-getOption("message_reply_quote_length_max") characters
inputMessageReplyToMessage message_id:int53 quote:formattedText = InputMessageReplyTo;
inputMessageReplyToMessage chat_id:int53 message_id:int53 quote:formattedText = InputMessageReplyTo;
//@description Describes a story to be replied @story_sender_chat_id The identifier of the sender of the story. Currently, stories can be replied only in the sender's chat @story_id The identifier of the story
inputMessageReplyToStory story_sender_chat_id:int53 story_id:int32 = InputMessageReplyTo;

View File

@ -165,10 +165,9 @@ void DraftMessage::add_dependencies(Dependencies &dependencies) const {
input_message_text_.add_dependencies(dependencies);
}
td_api::object_ptr<td_api::draftMessage> DraftMessage::get_draft_message_object(Td *td, DialogId dialog_id) const {
return td_api::make_object<td_api::draftMessage>(
message_input_reply_to_.get_input_message_reply_to_object(td, dialog_id), date_,
input_message_text_.get_input_message_text_object());
td_api::object_ptr<td_api::draftMessage> DraftMessage::get_draft_message_object(Td *td) const {
return td_api::make_object<td_api::draftMessage>(message_input_reply_to_.get_input_message_reply_to_object(td), date_,
input_message_text_.get_input_message_text_object());
}
DraftMessage::DraftMessage(Td *td, telegram_api::object_ptr<telegram_api::draftMessage> &&draft_message) {
@ -253,12 +252,12 @@ void add_draft_message_dependencies(Dependencies &dependencies, const unique_ptr
draft_message->add_dependencies(dependencies);
}
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td, DialogId dialog_id,
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td,
const unique_ptr<DraftMessage> &draft_message) {
if (draft_message == nullptr) {
return nullptr;
}
return draft_message->get_draft_message_object(td, dialog_id);
return draft_message->get_draft_message_object(td);
}
unique_ptr<DraftMessage> get_draft_message(Td *td,

View File

@ -42,7 +42,7 @@ class DraftMessage {
void add_dependencies(Dependencies &dependencies) const;
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td, DialogId dialog_id) const;
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td) const;
static Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id, MessageId top_thread_message_id,
td_api::object_ptr<td_api::draftMessage> &&draft_message);
@ -59,7 +59,7 @@ bool need_update_draft_message(const unique_ptr<DraftMessage> &old_draft_message
void add_draft_message_dependencies(Dependencies &dependencies, const unique_ptr<DraftMessage> &draft_message);
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td, DialogId dialog_id,
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(Td *td,
const unique_ptr<DraftMessage> &draft_message);
unique_ptr<DraftMessage> get_draft_message(Td *td,

View File

@ -49,7 +49,7 @@ void DraftMessage::parse(ParserT &parser) {
if (has_legacy_reply_to_message_id) {
MessageId legacy_reply_to_message_id;
td::parse(legacy_reply_to_message_id, parser);
message_input_reply_to_ = MessageInputReplyTo(legacy_reply_to_message_id, FormattedText());
message_input_reply_to_ = MessageInputReplyTo{legacy_reply_to_message_id, DialogId(), FormattedText()};
}
if (has_input_message_text) {
td::parse(input_message_text_, parser);

View File

@ -70,7 +70,7 @@ td_api::object_ptr<td_api::forumTopic> ForumTopic::get_forum_topic_object(Td *td
// TODO draft_message = can_send_message(dialog_id, info_.get_top_thread_message_id()).is_ok() ? ... : nullptr;
auto last_message =
td->messages_manager_->get_message_object({dialog_id, last_message_id_}, "get_forum_topic_object");
auto draft_message = get_draft_message_object(td, dialog_id, draft_message_);
auto draft_message = get_draft_message_object(td, draft_message_);
return td_api::make_object<td_api::forumTopic>(
info.get_forum_topic_info_object(td), std::move(last_message), is_pinned_, unread_count_,
last_read_inbox_message_id_.get(), last_read_outbox_message_id_.get(), unread_mention_count_,

View File

@ -49,11 +49,13 @@ MessageInputReplyTo::MessageInputReplyTo(Td *td,
DialogId dialog_id;
if (reply_to->reply_to_peer_id_ != nullptr) {
dialog_id = InputDialogId(reply_to->reply_to_peer_id_).get_dialog_id();
if (!dialog_id.is_valid()) {
if (!dialog_id.is_valid() || !td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
return;
}
td->messages_manager_->force_create_dialog(dialog_id, "inputReplyToMessage");
}
message_id_ = message_id;
dialog_id_ = dialog_id;
if (!reply_to->quote_text_.empty()) {
auto entities = get_message_entities(td->contacts_manager_.get(), std::move(reply_to->quote_entities_),
@ -100,6 +102,15 @@ telegram_api::object_ptr<telegram_api::InputReplyTo> MessageInputReplyTo::get_in
CHECK(top_thread_message_id.is_server());
flags |= telegram_api::inputReplyToMessage::TOP_MSG_ID_MASK;
}
telegram_api::object_ptr<telegram_api::InputPeer> input_peer;
if (dialog_id_ != DialogId()) {
input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
if (input_peer == nullptr) {
LOG(INFO) << "Failed to get input peer for " << dialog_id_;
return nullptr;
}
flags |= telegram_api::inputReplyToMessage::REPLY_TO_PEER_ID_MASK;
}
if (!quote_.text.empty()) {
flags |= telegram_api::inputReplyToMessage::QUOTE_TEXT_MASK;
}
@ -109,12 +120,11 @@ telegram_api::object_ptr<telegram_api::InputReplyTo> MessageInputReplyTo::get_in
}
return telegram_api::make_object<telegram_api::inputReplyToMessage>(
flags, reply_to_message_id.get_server_message_id().get(), top_thread_message_id.get_server_message_id().get(),
nullptr, quote_.text, std::move(quote_entities));
std::move(input_peer), quote_.text, std::move(quote_entities));
}
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());
// only for draft messages
td_api::object_ptr<td_api::InputMessageReplyTo> MessageInputReplyTo::get_input_message_reply_to_object(Td *td) const {
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"),
@ -127,22 +137,26 @@ td_api::object_ptr<td_api::InputMessageReplyTo> MessageInputReplyTo::get_input_m
if (!quote_.text.empty()) {
quote = get_formatted_text_object(quote_, true, -1);
}
return td_api::make_object<td_api::inputMessageReplyToMessage>(message_id_.get(), std::move(quote));
return td_api::make_object<td_api::inputMessageReplyToMessage>(
message_id_.get(), td->messages_manager_->get_chat_id_object(dialog_id_, "inputMessageReplyToMessage"),
std::move(quote));
}
MessageId MessageInputReplyTo::get_same_chat_reply_to_message_id() const {
return message_id_.is_valid() || message_id_.is_valid_scheduled() ? message_id_ : MessageId();
return dialog_id_ == DialogId() && (message_id_.is_valid() || message_id_.is_valid_scheduled()) ? message_id_
: MessageId();
}
MessageFullId MessageInputReplyTo::get_reply_message_full_id(DialogId owner_dialog_id) const {
if (!message_id_.is_valid() && !message_id_.is_valid_scheduled()) {
return {};
}
return {owner_dialog_id, message_id_};
return {dialog_id_ != DialogId() ? dialog_id_ : owner_dialog_id, message_id_};
}
bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) {
return lhs.message_id_ == rhs.message_id_ && lhs.story_full_id_ == rhs.story_full_id_ && lhs.quote_ == rhs.quote_;
return lhs.message_id_ == rhs.message_id_ && lhs.dialog_id_ == rhs.dialog_id_ &&
lhs.story_full_id_ == rhs.story_full_id_ && lhs.quote_ == rhs.quote_;
}
bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) {
@ -152,6 +166,9 @@ bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs)
StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to) {
if (input_reply_to.message_id_.is_valid() || input_reply_to.message_id_.is_valid_scheduled()) {
string_builder << input_reply_to.message_id_;
if (input_reply_to.dialog_id_ != DialogId()) {
string_builder << " in " << input_reply_to.dialog_id_;
}
if (!input_reply_to.quote_.text.empty()) {
string_builder << " with " << input_reply_to.quote_.text.size() << " quoted bytes";
}

View File

@ -23,6 +23,7 @@ class Td;
class MessageInputReplyTo {
MessageId message_id_;
DialogId dialog_id_;
FormattedText quote_;
// or
StoryFullId story_full_id_;
@ -41,7 +42,8 @@ class MessageInputReplyTo {
MessageInputReplyTo &operator=(MessageInputReplyTo &&) = default;
~MessageInputReplyTo();
MessageInputReplyTo(MessageId message_id, FormattedText &&quote) : message_id_(message_id), quote_(std::move(quote)) {
MessageInputReplyTo(MessageId message_id, DialogId dialog_id, FormattedText &&quote)
: message_id_(message_id), dialog_id_(dialog_id), quote_(std::move(quote)) {
}
explicit MessageInputReplyTo(StoryFullId story_full_id) : story_full_id_(story_full_id) {
@ -64,7 +66,7 @@ class MessageInputReplyTo {
telegram_api::object_ptr<telegram_api::InputReplyTo> get_input_reply_to(Td *td,
MessageId top_thread_message_id) const;
td_api::object_ptr<td_api::InputMessageReplyTo> get_input_message_reply_to_object(Td *td, DialogId dialog_id) const;
td_api::object_ptr<td_api::InputMessageReplyTo> get_input_message_reply_to_object(Td *td) const;
void set_message_id(MessageId new_message_id) {
CHECK(message_id_.is_valid() || message_id_.is_valid_scheduled());

View File

@ -19,10 +19,12 @@ void MessageInputReplyTo::store(StorerT &storer) const {
bool has_message_id = message_id_.is_valid();
bool has_story_full_id = story_full_id_.is_valid();
bool has_quote = !quote_.text.empty();
bool has_dialog_id = dialog_id_.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_message_id);
STORE_FLAG(has_story_full_id);
STORE_FLAG(has_quote);
STORE_FLAG(has_dialog_id);
END_STORE_FLAGS();
if (has_message_id) {
td::store(message_id_, storer);
@ -33,6 +35,9 @@ void MessageInputReplyTo::store(StorerT &storer) const {
if (has_quote) {
td::store(quote_, storer);
}
if (has_dialog_id) {
td::store(dialog_id_, storer);
}
}
template <class ParserT>
@ -40,10 +45,12 @@ void MessageInputReplyTo::parse(ParserT &parser) {
bool has_message_id;
bool has_story_full_id;
bool has_quote;
bool has_dialog_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_message_id);
PARSE_FLAG(has_story_full_id);
PARSE_FLAG(has_quote);
PARSE_FLAG(has_dialog_id);
END_PARSE_FLAGS();
if (has_message_id) {
td::parse(message_id_, parser);
@ -54,6 +61,9 @@ void MessageInputReplyTo::parse(ParserT &parser) {
if (has_quote) {
td::parse(quote_, parser);
}
if (has_dialog_id) {
td::parse(dialog_id_, parser);
}
}
} // namespace td

View File

@ -5168,7 +5168,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
if (reply_to_story_full_id.is_valid()) {
input_reply_to = MessageInputReplyTo(reply_to_story_full_id);
} else if (legacy_reply_to_message_id.is_valid()) {
input_reply_to = MessageInputReplyTo{legacy_reply_to_message_id, FormattedText()};
input_reply_to = MessageInputReplyTo{legacy_reply_to_message_id, DialogId(), FormattedText()};
}
}
if (has_replied_message_info) {
@ -18056,7 +18056,7 @@ td_api::object_ptr<td_api::messageThreadInfo> MessagesManager::get_message_threa
if (can_send_message(d->dialog_id).is_ok()) {
const Message *m = get_message_force(d, top_thread_message_id, "get_message_thread_info_object 2");
if (m != nullptr && !m->reply_info.is_comment_ && is_active_message_reply_info(d->dialog_id, m->reply_info)) {
draft_message = get_draft_message_object(td_, d->dialog_id, m->thread_draft_message);
draft_message = get_draft_message_object(td_, m->thread_draft_message);
}
}
}
@ -20737,9 +20737,8 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
auto chat_source = is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr;
auto can_delete = can_delete_dialog(d);
// TODO hide/show draft message when need_hide_dialog_draft_message changes
auto draft_message = !need_hide_dialog_draft_message(d->dialog_id)
? get_draft_message_object(td_, d->dialog_id, d->draft_message)
: nullptr;
auto draft_message =
!need_hide_dialog_draft_message(d->dialog_id) ? get_draft_message_object(td_, d->draft_message) : nullptr;
auto available_reactions = get_dialog_active_reactions(d).get_chat_available_reactions_object();
auto is_translatable = d->is_translatable && is_premium;
auto block_list_id = BlockListId(d->is_blocked, d->is_blocked_for_stories);
@ -24491,7 +24490,7 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to(
}
if (reply_to == nullptr) {
if (!for_draft && top_thread_message_id.is_valid() && top_thread_message_id.is_server()) {
return MessageInputReplyTo{top_thread_message_id, FormattedText()};
return MessageInputReplyTo{top_thread_message_id, DialogId(), FormattedText()};
}
return {};
}
@ -24519,12 +24518,20 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to(
if (!message_id.is_valid()) {
if (!for_draft && message_id == MessageId() && top_thread_message_id.is_valid() &&
top_thread_message_id.is_server()) {
return MessageInputReplyTo{top_thread_message_id, FormattedText()};
return MessageInputReplyTo{top_thread_message_id, DialogId(), FormattedText()};
}
return {};
}
message_id = get_persistent_message_id(d, message_id);
if (message_id == MessageId(ServerMessageId(1)) && d->dialog_id.get_type() == DialogType::Channel) {
auto *reply_d = d;
auto reply_dialog_id = DialogId(reply_to_message->chat_id_);
if (reply_dialog_id != DialogId()) {
reply_d = get_dialog_force(reply_dialog_id, "get_message_input_reply_to");
if (reply_d == nullptr) {
return {};
}
}
message_id = get_persistent_message_id(reply_d, message_id);
if (message_id == MessageId(ServerMessageId(1)) && reply_d->dialog_id.get_type() == DialogType::Channel) {
return {};
}
FormattedText quote;
@ -24533,25 +24540,25 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to(
if (r_quote.is_ok()) {
quote = r_quote.move_as_ok();
}
const Message *m = get_message_force(d, message_id, "get_message_input_reply_to 2");
const Message *m = get_message_force(reply_d, message_id, "get_message_input_reply_to 2");
if (m == nullptr || m->message_id.is_yet_unsent() ||
(m->message_id.is_local() && d->dialog_id.get_type() != DialogType::SecretChat)) {
if (message_id.is_server() && d->dialog_id.get_type() != DialogType::SecretChat &&
message_id > d->last_new_message_id &&
(d->notification_info != nullptr &&
message_id <= d->notification_info->max_push_notification_message_id_)) {
(m->message_id.is_local() && reply_d->dialog_id.get_type() != DialogType::SecretChat)) {
if (message_id.is_server() && reply_d->dialog_id.get_type() != DialogType::SecretChat &&
message_id > reply_d->last_new_message_id &&
(reply_d->notification_info != nullptr &&
message_id <= reply_d->notification_info->max_push_notification_message_id_)) {
// allow to reply yet unreceived server message
return MessageInputReplyTo{message_id, std::move(quote)};
return MessageInputReplyTo{message_id, reply_dialog_id, std::move(quote)};
}
if (!for_draft && top_thread_message_id.is_valid() && top_thread_message_id.is_server()) {
return MessageInputReplyTo{top_thread_message_id, FormattedText()};
return MessageInputReplyTo{top_thread_message_id, DialogId(), FormattedText()};
}
// TODO local replies to local messages can be allowed
// TODO replies to yet unsent messages can be allowed with special handling of them on application restart
return {};
}
return MessageInputReplyTo{m->message_id, std::move(quote)};
return MessageInputReplyTo{m->message_id, reply_dialog_id, std::move(quote)};
}
default:
UNREACHABLE();
@ -24653,8 +24660,8 @@ void MessagesManager::cancel_send_message_query(DialogId dialog_id, Message *m)
const auto *input_reply_to = get_message_input_reply_to(replied_m);
CHECK(input_reply_to != nullptr);
CHECK(input_reply_to->get_reply_message_full_id(reply_d->dialog_id) == MessageFullId(dialog_id, m->message_id));
set_message_reply(reply_d, replied_m, MessageInputReplyTo{replied_m->top_thread_message_id, FormattedText()},
true);
set_message_reply(reply_d, replied_m,
MessageInputReplyTo{replied_m->top_thread_message_id, DialogId(), FormattedText()}, true);
}
replied_yet_unsent_messages_.erase(it);
}
@ -28171,7 +28178,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
if (!input_reply_to.is_valid() && copied_message.original_reply_to_message_id.is_valid() && is_secret) {
auto it = forwarded_message_id_to_new_message_id.find(copied_message.original_reply_to_message_id);
if (it != forwarded_message_id_to_new_message_id.end()) {
input_reply_to = MessageInputReplyTo{it->second, FormattedText()};
input_reply_to = MessageInputReplyTo{it->second, DialogId(), FormattedText()};
}
}
@ -30236,7 +30243,7 @@ void MessagesManager::send_update_chat_draft_message(const Dialog *d) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatDraftMessage>(
get_chat_id_object(d->dialog_id, "updateChatDraftMessage"),
get_draft_message_object(td_, d->dialog_id, d->draft_message), get_chat_positions_object(d)));
get_draft_message_object(td_, d->draft_message), get_chat_positions_object(d)));
}
}
@ -39212,7 +39219,7 @@ void MessagesManager::restore_message_reply_to_message_id(Dialog *d, Message *m)
if (message_id.is_valid() || message_id.is_valid_scheduled()) {
update_message_reply_to_message_id(d, m, message_id, false);
} else {
set_message_reply(d, m, MessageInputReplyTo(m->top_thread_message_id, FormattedText()), false);
set_message_reply(d, m, MessageInputReplyTo{m->top_thread_message_id, DialogId(), FormattedText()}, false);
}
}

View File

@ -156,6 +156,9 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_
quote_ = input_reply_to.quote_;
is_quote_manual_ = true;
}
if (input_reply_to.dialog_id_ != DialogId()) {
dialog_id_ = input_reply_to.dialog_id_;
}
}
bool RepliedMessageInfo::need_reget() const {
@ -290,8 +293,8 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag
}
MessageInputReplyTo RepliedMessageInfo::get_input_reply_to() const {
if (message_id_.is_valid() && dialog_id_ == DialogId()) {
return MessageInputReplyTo{message_id_, FormattedText{quote_}};
if (message_id_.is_valid()) {
return MessageInputReplyTo{message_id_, dialog_id_, FormattedText{quote_}};
}
return {};
}

View File

@ -942,7 +942,7 @@ class CliClient final : public Actor {
return nullptr;
}
if (message_id != 0) {
return td_api::make_object<td_api::inputMessageReplyToMessage>(message_id, nullptr);
return td_api::make_object<td_api::inputMessageReplyToMessage>(0, message_id, nullptr);
} else {
return td_api::make_object<td_api::inputMessageReplyToStory>(user_id, story_id);
}