Improve get_draft_message.

This commit is contained in:
levlam 2023-05-31 17:19:31 +03:00
parent ad5655d359
commit 978eb97c72
4 changed files with 18 additions and 12 deletions

View File

@ -212,18 +212,19 @@ unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
}
}
Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id,
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) {
if (draft_message == nullptr) {
return nullptr;
}
auto result = make_unique<DraftMessage>();
result->date = G()->unix_time();
result->reply_to_message_id = MessageId(draft_message->reply_to_message_id_);
if (result->reply_to_message_id != MessageId() && !result->reply_to_message_id.is_valid()) {
return Status::Error(400, "Invalid reply_to_message_id specified");
}
result->reply_to_message_id = td->messages_manager_->get_reply_to_message_id(dialog_id, top_thread_message_id,
result->reply_to_message_id, true);
auto input_message_content = std::move(draft_message->input_message_text_);
if (input_message_content != nullptr) {
@ -235,6 +236,11 @@ Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id,
result->input_message_text = std::move(message_content);
}
if (!result->reply_to_message_id.is_valid() && result->input_message_text.text.text.empty()) {
return nullptr;
}
result->date = G()->unix_time();
return std::move(result);
}

View File

@ -39,7 +39,7 @@ td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_p
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
telegram_api::object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id,
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);
void save_draft_message(Td *td, DialogId dialog_id, const unique_ptr<DraftMessage> &draft_message,

View File

@ -18932,15 +18932,7 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id, MessageId t
TRY_STATUS(can_use_top_thread_message_id(d, top_thread_message_id, MessageId()));
TRY_RESULT(new_draft_message, get_draft_message(td_, dialog_id, std::move(draft_message)));
if (new_draft_message != nullptr) {
new_draft_message->reply_to_message_id =
get_reply_to_message_id(d, top_thread_message_id, new_draft_message->reply_to_message_id, true);
if (!new_draft_message->reply_to_message_id.is_valid() && new_draft_message->input_message_text.text.text.empty()) {
new_draft_message = nullptr;
}
}
TRY_RESULT(new_draft_message, get_draft_message(td_, dialog_id, top_thread_message_id, std::move(draft_message)));
if (top_thread_message_id != MessageId()) {
CHECK(top_thread_message_id.is_valid());
@ -24166,6 +24158,11 @@ DialogId MessagesManager::get_dialog_default_send_message_as_dialog_id(DialogId
return d->default_send_message_as_dialog_id;
}
MessageId MessagesManager::get_reply_to_message_id(DialogId dialog_id, MessageId top_thread_message_id,
MessageId message_id, bool for_draft) {
return get_reply_to_message_id(get_dialog(dialog_id), top_thread_message_id, message_id, for_draft);
}
int64 MessagesManager::generate_new_random_id(const Dialog *d) {
int64 random_id;
do {

View File

@ -441,6 +441,9 @@ class MessagesManager final : public Actor {
DialogId get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const;
MessageId get_reply_to_message_id(DialogId dialog_id, MessageId top_thread_message_id, MessageId message_id,
bool for_draft);
Result<td_api::object_ptr<td_api::message>> send_message(
DialogId dialog_id, MessageId top_thread_message_id, MessageId reply_to_message_id,
tl_object_ptr<td_api::messageSendOptions> &&options, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup,