Move DraftMessage to separate files.

GitOrigin-RevId: acf4722d7c1328ee4048f8ca162060923e0be6fe
This commit is contained in:
levlam 2018-09-29 02:45:43 +03:00
parent 4cf6aba717
commit b6a8624c60
9 changed files with 142 additions and 81 deletions

View File

@ -353,6 +353,7 @@ set(TDLIB_SOURCE
td/telegram/DialogId.cpp
td/telegram/DialogParticipant.cpp
td/telegram/DocumentsManager.cpp
td/telegram/DraftMessage.cpp
td/telegram/files/FileDb.cpp
td/telegram/files/FileDownloader.cpp
td/telegram/files/FileFromBytes.cpp
@ -466,6 +467,7 @@ set(TDLIB_SOURCE
td/telegram/DialogId.h
td/telegram/DialogParticipant.h
td/telegram/DocumentsManager.h
td/telegram/DraftMessage.h
td/telegram/files/FileDb.h
td/telegram/files/FileDownloader.h
td/telegram/files/FileFromBytes.h
@ -561,6 +563,7 @@ set(TDLIB_SOURCE
td/telegram/AudiosManager.hpp
td/telegram/AuthManager.hpp
td/telegram/DocumentsManager.hpp
td/telegram/DraftMessage.hpp
td/telegram/files/FileId.hpp
td/telegram/files/FileManager.hpp
td/telegram/Game.hpp

View File

@ -0,0 +1,67 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// 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/DraftMessage.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/misc.h"
#include "td/utils/logging.h"
namespace td {
td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_ptr<DraftMessage> &draft_message) {
if (draft_message == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::draftMessage>(draft_message->reply_to_message_id.get(),
get_input_message_text_object(draft_message->input_message_text));
}
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr) {
if (draft_message_ptr == nullptr) {
return nullptr;
}
auto constructor_id = draft_message_ptr->get_id();
switch (constructor_id) {
case telegram_api::draftMessageEmpty::ID:
return nullptr;
case telegram_api::draftMessage::ID: {
auto draft = move_tl_object_as<telegram_api::draftMessage>(draft_message_ptr);
auto flags = draft->flags_;
auto result = make_unique<DraftMessage>();
result->date = draft->date_;
if ((flags & telegram_api::draftMessage::REPLY_TO_MSG_ID_MASK) != 0) {
result->reply_to_message_id = MessageId(ServerMessageId(draft->reply_to_msg_id_));
if (!result->reply_to_message_id.is_valid()) {
LOG(ERROR) << "Receive " << result->reply_to_message_id << " as reply_to_message_id in the draft";
result->reply_to_message_id = MessageId();
}
}
auto entities = get_message_entities(contacts_manager, std::move(draft->entities_), "draftMessage");
auto status = fix_formatted_text(draft->message_, entities, true, true, true, true);
if (status.is_error()) {
LOG(ERROR) << "Receive error " << status << " while parsing draft " << draft->message_;
if (!clean_input_string(draft->message_)) {
draft->message_.clear();
}
entities.clear();
}
result->input_message_text.text = FormattedText{std::move(draft->message_), std::move(entities)};
result->input_message_text.disable_web_page_preview = (flags & telegram_api::draftMessage::NO_WEBPAGE_MASK) != 0;
result->input_message_text.clear_draft = false;
return result;
}
default:
UNREACHABLE();
return nullptr;
}
}
} // namespace td

View File

@ -0,0 +1,31 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// 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)
//
#pragma once
#include "td/telegram/InputMessageText.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/td_api.h"
#include "td/utils/common.h"
namespace td {
class ContactsManager;
class DraftMessage {
public:
int32 date;
MessageId reply_to_message_id;
InputMessageText input_message_text;
};
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,
tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
} // namespace td

View File

@ -0,0 +1,31 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// 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)
//
#pragma once
#include "td/telegram/DraftMessage.h"
#include "td/telegram/InputMessageText.hpp"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void store(const DraftMessage &draft_message, StorerT &storer) {
store(draft_message.date, storer);
store(draft_message.reply_to_message_id, storer);
store(draft_message.input_message_text, storer);
}
template <class ParserT>
void parse(DraftMessage &draft_message, ParserT &parser) {
parse(draft_message.date, parser);
parse(draft_message.reply_to_message_id, parser);
parse(draft_message.input_message_text, parser);
}
} // namespace td

View File

@ -8,6 +8,8 @@
#include "td/telegram/MessageEntity.h"
#include "td/utils/logging.h"
namespace td {
bool operator==(const InputMessageText &lhs, const InputMessageText &rhs) {

View File

@ -15,7 +15,7 @@
namespace td {
template <class StorerT>
static void store(const InputMessageText &input_message_text, StorerT &storer) {
void store(const InputMessageText &input_message_text, StorerT &storer) {
BEGIN_STORE_FLAGS();
STORE_FLAG(input_message_text.disable_web_page_preview);
STORE_FLAG(input_message_text.clear_draft);
@ -24,7 +24,7 @@ static void store(const InputMessageText &input_message_text, StorerT &storer) {
}
template <class ParserT>
static void parse(InputMessageText &input_message_text, ParserT &parser) {
void parse(InputMessageText &input_message_text, ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(input_message_text.disable_web_page_preview);
PARSE_FLAG(input_message_text.clear_draft);

View File

@ -55,6 +55,7 @@
#include "td/utils/format.h"
#include "td/utils/HttpUrl.h"
#include "td/utils/logging.h"
#include "td/utils/MimeType.h"
#include "td/utils/misc.h"
#include "td/utils/PathView.h"

View File

@ -11,14 +11,17 @@
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogDb.h"
#include "td/telegram/DraftMessage.h"
#include "td/telegram/DraftMessage.hpp"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InlineQueriesManager.h"
#include "td/telegram/InputMessageText.hpp"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.hpp"
#include "td/telegram/MessagesDb.h"
#include "td/telegram/misc.h"
@ -3899,20 +3902,6 @@ static void parse(ScopeNotificationSettings &notification_settings, ParserT &par
}
}
template <class StorerT>
static void store(const DraftMessage &draft_message, StorerT &storer) {
store(draft_message.date, storer);
store(draft_message.reply_to_message_id, storer);
store(draft_message.input_message_text, storer);
}
template <class ParserT>
static void parse(DraftMessage &draft_message, ParserT &parser) {
parse(draft_message.date, parser);
parse(draft_message.reply_to_message_id, parser);
parse(draft_message.input_message_text, parser);
}
template <class StorerT>
void MessagesManager::Dialog::store(StorerT &storer) const {
using td::store;
@ -12355,15 +12344,6 @@ void MessagesManager::close_dialog(Dialog *d) {
}
}
tl_object_ptr<td_api::draftMessage> MessagesManager::get_draft_message_object(
const unique_ptr<DraftMessage> &draft_message) const {
if (draft_message == nullptr) {
return nullptr;
}
return make_tl_object<td_api::draftMessage>(draft_message->reply_to_message_id.get(),
get_input_message_text_object(draft_message->input_message_text));
}
tl_object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
@ -12698,49 +12678,6 @@ void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_
td_->create_handler<ResetNotifySettingsQuery>(get_erase_logevent_promise(logevent_id))->send();
}
unique_ptr<DraftMessage> MessagesManager::get_draft_message(
ContactsManager *contacts_manager, tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr) {
if (draft_message_ptr == nullptr) {
return nullptr;
}
auto constructor_id = draft_message_ptr->get_id();
switch (constructor_id) {
case telegram_api::draftMessageEmpty::ID:
return nullptr;
case telegram_api::draftMessage::ID: {
auto draft = move_tl_object_as<telegram_api::draftMessage>(draft_message_ptr);
auto flags = draft->flags_;
auto result = make_unique<DraftMessage>();
result->date = draft->date_;
if ((flags & SEND_MESSAGE_FLAG_IS_REPLY) != 0) {
result->reply_to_message_id = MessageId(ServerMessageId(draft->reply_to_msg_id_));
if (!result->reply_to_message_id.is_valid()) {
LOG(ERROR) << "Receive " << result->reply_to_message_id << " as reply_to_message_id in the draft";
result->reply_to_message_id = MessageId();
}
}
auto entities = get_message_entities(contacts_manager, std::move(draft->entities_), "draftMessage");
auto status = fix_formatted_text(draft->message_, entities, true, true, true, true);
if (status.is_error()) {
LOG(ERROR) << "Receive error " << status << " while parsing draft " << draft->message_;
if (!clean_input_string(draft->message_)) {
draft->message_.clear();
}
entities.clear();
}
result->input_message_text.text = FormattedText{std::move(draft->message_), std::move(entities)};
result->input_message_text.disable_web_page_preview = (flags & SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW) != 0;
result->input_message_text.clear_draft = false;
return result;
}
default:
UNREACHABLE();
return nullptr;
}
}
tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dialog_id, MessageId from_message_id,
int32 offset, int32 limit, int left_tries,
bool only_local, Promise<Unit> &&promise) {

View File

@ -25,7 +25,6 @@
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageId.h"
@ -63,12 +62,7 @@ class Td;
class MultiSequenceDispatcher;
class DraftMessage {
public:
int32 date;
MessageId reply_to_message_id;
InputMessageText input_message_text;
};
class DraftMessage;
class DialogNotificationSettings {
public:
@ -1675,8 +1669,6 @@ class MessagesManager : public Actor {
void add_dialog_last_database_message(Dialog *d, unique_ptr<Message> &&last_database_message);
tl_object_ptr<td_api::draftMessage> get_draft_message_object(const unique_ptr<DraftMessage> &draft_message) const;
tl_object_ptr<td_api::ChatType> get_chat_type_object(DialogId dialog_id) const;
tl_object_ptr<td_api::chat> get_chat_object(const Dialog *d) const;
@ -1748,9 +1740,6 @@ class MessagesManager : public Actor {
const ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope) const;
static unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
tl_object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
vector<FileId> get_message_file_ids(const Message *message) const;
void cancel_upload_message_content_files(const MessageContent *content);