tdesktop/Telegram/SourceFiles/data/data_drafts.cpp

81 lines
2.0 KiB
C++
Raw Normal View History

2016-05-31 09:46:31 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2016-05-31 09:46:31 +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
*/
#include "data/data_drafts.h"
2016-05-31 09:46:31 +00:00
2019-09-16 11:14:06 +00:00
#include "api/api_text_entities.h"
#include "ui/widgets/input_fields.h"
#include "chat_helpers/message_field.h"
#include "history/history.h"
2017-06-29 10:27:09 +00:00
#include "history/history_widget.h"
2019-01-18 12:27:37 +00:00
#include "data/data_session.h"
#include "mainwidget.h"
2017-03-04 10:23:56 +00:00
#include "storage/localstorage.h"
2016-05-31 09:46:31 +00:00
namespace Data {
namespace {
} // namespace
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(
2018-05-21 21:31:46 +00:00
not_null<const Ui::InputField*> field,
MsgId msgId,
bool previewCancelled,
mtpRequestId saveRequestId)
: textWithTags(field->getTextWithTags())
, msgId(msgId)
, cursor(field)
, previewCancelled(previewCancelled) {
}
2016-05-31 09:46:31 +00:00
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
2019-01-18 12:27:37 +00:00
const auto history = Auth().data().history(peerId);
const auto textWithTags = TextWithTags {
2019-07-05 13:38:38 +00:00
qs(draft.vmessage()),
2019-09-16 11:14:06 +00:00
TextUtilities::ConvertEntitiesToTextTags(
Api::EntitiesFromMTP(draft.ventities().value_or_empty()))
};
2019-07-05 13:38:38 +00:00
auto replyTo = draft.vreply_to_msg_id().value_or_empty();
if (history->skipCloudDraft(textWithTags.text, replyTo, draft.vdate().v)) {
return;
}
auto cloudDraft = std::make_unique<Draft>(
textWithTags,
replyTo,
MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX),
draft.is_no_webpage());
2019-07-05 13:38:38 +00:00
cloudDraft->date = draft.vdate().v;
history->setCloudDraft(std::move(cloudDraft));
2019-03-12 12:54:15 +00:00
history->applyCloudDraft();
2016-05-31 09:46:31 +00:00
}
2018-06-26 13:58:29 +00:00
void clearPeerCloudDraft(PeerId peerId, TimeId date) {
2019-01-18 12:27:37 +00:00
const auto history = Auth().data().history(peerId);
if (history->skipCloudDraft(QString(), MsgId(0), date)) {
2018-06-26 13:58:29 +00:00
return;
}
history->clearCloudDraft();
2019-03-12 12:54:15 +00:00
history->applyCloudDraft();
}
2016-05-31 09:46:31 +00:00
} // namespace Data