Add get_draft_message function.
This commit is contained in:
parent
2ce0be4fe7
commit
14c2a990b1
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/DraftMessage.h"
|
#include "td/telegram/DraftMessage.h"
|
||||||
|
|
||||||
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessageEntity.h"
|
#include "td/telegram/MessageEntity.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/ServerMessageId.h"
|
#include "td/telegram/ServerMessageId.h"
|
||||||
@ -23,7 +24,7 @@ td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
||||||
tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr) {
|
telegram_api::object_ptr<telegram_api::DraftMessage> &&draft_message_ptr) {
|
||||||
if (draft_message_ptr == nullptr) {
|
if (draft_message_ptr == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -65,4 +66,30 @@ unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<unique_ptr<DraftMessage>> get_draft_message(ContactsManager *contacts_manager, DialogId dialog_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");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto input_message_content = std::move(draft_message->input_message_text_);
|
||||||
|
if (input_message_content != nullptr) {
|
||||||
|
if (input_message_content->get_id() != td_api::inputMessageText::ID) {
|
||||||
|
return Status::Error(400, "Input message content type must be InputMessageText");
|
||||||
|
}
|
||||||
|
TRY_RESULT(message_content,
|
||||||
|
process_input_message_text(contacts_manager, dialog_id, std::move(input_message_content), false, true));
|
||||||
|
result->input_message_text = std::move(message_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -27,6 +28,9 @@ class DraftMessage {
|
|||||||
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_ptr<DraftMessage> &draft_message);
|
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_ptr<DraftMessage> &draft_message);
|
||||||
|
|
||||||
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
||||||
tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
|
telegram_api::object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
|
||||||
|
|
||||||
|
Result<unique_ptr<DraftMessage>> get_draft_message(ContactsManager *contacts_manager, DialogId dialog_id,
|
||||||
|
td_api::object_ptr<td_api::draftMessage> &&draft_message);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -18559,23 +18559,10 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id, MessageId t
|
|||||||
}
|
}
|
||||||
TRY_STATUS(can_send_message(dialog_id));
|
TRY_STATUS(can_send_message(dialog_id));
|
||||||
|
|
||||||
unique_ptr<DraftMessage> new_draft_message;
|
TRY_RESULT(new_draft_message, get_draft_message(td_->contacts_manager_.get(), dialog_id, std::move(draft_message)));
|
||||||
if (draft_message != nullptr) {
|
if (new_draft_message != nullptr) {
|
||||||
new_draft_message = make_unique<DraftMessage>();
|
|
||||||
new_draft_message->date = G()->unix_time();
|
|
||||||
new_draft_message->reply_to_message_id =
|
new_draft_message->reply_to_message_id =
|
||||||
get_reply_to_message_id(d, top_thread_message_id, MessageId(draft_message->reply_to_message_id_), true);
|
get_reply_to_message_id(d, top_thread_message_id, new_draft_message->reply_to_message_id, true);
|
||||||
|
|
||||||
auto input_message_content = std::move(draft_message->input_message_text_);
|
|
||||||
if (input_message_content != nullptr) {
|
|
||||||
int32 draft_message_content_type = input_message_content->get_id();
|
|
||||||
if (draft_message_content_type != td_api::inputMessageText::ID) {
|
|
||||||
return Status::Error(400, "Input message content type must be InputMessageText");
|
|
||||||
}
|
|
||||||
TRY_RESULT(message_content, process_input_message_text(td_->contacts_manager_.get(), dialog_id,
|
|
||||||
std::move(input_message_content), false, true));
|
|
||||||
new_draft_message->input_message_text = std::move(message_content);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!new_draft_message->reply_to_message_id.is_valid() && new_draft_message->input_message_text.text.text.empty()) {
|
if (!new_draft_message->reply_to_message_id.is_valid() && new_draft_message->input_message_text.text.text.empty()) {
|
||||||
new_draft_message = nullptr;
|
new_draft_message = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user