2016-05-31 09:46:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-05-31 09:46:31 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-05-31 09:46:31 +00:00
|
|
|
*/
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_drafts.h"
|
2016-05-31 09:46:31 +00:00
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-06-29 10:27:09 +00:00
|
|
|
#include "history/history_widget.h"
|
2016-06-03 18:24:27 +00:00
|
|
|
#include "mainwidget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-06-03 18:24:27 +00:00
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
namespace Data {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
Draft::Draft(
|
|
|
|
const TextWithTags &textWithTags,
|
|
|
|
MsgId msgId,
|
|
|
|
const MessageCursor &cursor,
|
|
|
|
bool previewCancelled,
|
|
|
|
mtpRequestId saveRequestId)
|
|
|
|
: textWithTags(textWithTags)
|
|
|
|
, msgId(msgId)
|
|
|
|
, cursor(cursor)
|
|
|
|
, previewCancelled(previewCancelled)
|
|
|
|
, saveRequestId(saveRequestId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Draft::Draft(
|
|
|
|
not_null<const Ui::FlatTextarea*> field,
|
|
|
|
MsgId msgId,
|
|
|
|
bool previewCancelled,
|
|
|
|
mtpRequestId saveRequestId)
|
|
|
|
: textWithTags(field->getTextWithTags())
|
|
|
|
, msgId(msgId)
|
|
|
|
, cursor(field)
|
|
|
|
, previewCancelled(previewCancelled) {
|
2016-11-15 11:56:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
|
2016-06-03 18:24:27 +00:00
|
|
|
auto history = App::history(peerId);
|
2017-07-06 11:37:42 +00:00
|
|
|
auto text = TextWithEntities { qs(draft.vmessage), draft.has_entities() ? TextUtilities::EntitiesFromMTP(draft.ventities.v) : EntitiesInText() };
|
|
|
|
auto textWithTags = TextWithTags { TextUtilities::ApplyEntities(text), ConvertEntitiesToTextTags(text.entities) };
|
|
|
|
auto replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : MsgId(0);
|
2017-02-21 13:45:56 +00:00
|
|
|
auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage());
|
2018-02-03 19:52:35 +00:00
|
|
|
cloudDraft->date = draft.vdate.v;
|
2016-06-03 18:24:27 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
history->setCloudDraft(std::move(cloudDraft));
|
2016-06-03 18:24:27 +00:00
|
|
|
history->createLocalDraftFromCloud();
|
|
|
|
history->updateChatListSortPosition();
|
|
|
|
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->applyCloudDraft(history);
|
|
|
|
}
|
2016-05-31 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:31:10 +00:00
|
|
|
void clearPeerCloudDraft(PeerId peerId) {
|
|
|
|
auto history = App::history(peerId);
|
|
|
|
|
|
|
|
history->clearCloudDraft();
|
|
|
|
history->clearLocalDraft();
|
|
|
|
|
|
|
|
history->updateChatListSortPosition();
|
|
|
|
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->applyCloudDraft(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
} // namespace Data
|