tdesktop/Telegram/SourceFiles/data/data_drafts.cpp

97 lines
2.4 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/fields/input_field.h"
#include "chat_helpers/message_field.h"
#include "history/history.h"
2017-06-29 10:27:09 +00:00
#include "history/history_widget.h"
#include "main/main_session.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 {
Draft::Draft(
const TextWithTags &textWithTags,
MsgId msgId,
MsgId topicRootId,
const MessageCursor &cursor,
PreviewState previewState,
mtpRequestId saveRequestId)
: textWithTags(textWithTags)
, msgId(msgId)
, topicRootId(topicRootId)
, cursor(cursor)
, previewState(previewState)
, saveRequestId(saveRequestId) {
}
Draft::Draft(
2018-05-21 21:31:46 +00:00
not_null<const Ui::InputField*> field,
MsgId msgId,
MsgId topicRootId,
PreviewState previewState,
mtpRequestId saveRequestId)
: textWithTags(field->getTextWithTags())
, msgId(msgId)
, topicRootId(topicRootId)
, cursor(field)
, previewState(previewState) {
}
2020-06-08 08:03:45 +00:00
void ApplyPeerCloudDraft(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
2020-06-08 08:03:45 +00:00
const MTPDdraftMessage &draft) {
const auto history = session->data().history(peerId);
const auto date = draft.vdate().v;
if (history->skipCloudDraftUpdate(topicRootId, date)) {
return;
}
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(
2020-06-08 08:03:45 +00:00
Api::EntitiesFromMTP(
session,
draft.ventities().value_or_empty()))
};
2020-06-08 08:03:45 +00:00
const auto replyTo = draft.vreply_to_msg_id().value_or_empty();
auto cloudDraft = std::make_unique<Draft>(
textWithTags,
replyTo,
topicRootId,
MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX),
(draft.is_no_webpage()
? Data::PreviewState::Cancelled
: Data::PreviewState::Allowed));
cloudDraft->date = date;
history->setCloudDraft(std::move(cloudDraft));
history->applyCloudDraft(topicRootId);
2016-05-31 09:46:31 +00:00
}
2020-06-08 08:03:45 +00:00
void ClearPeerCloudDraft(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
2020-06-08 08:03:45 +00:00
TimeId date) {
const auto history = session->data().history(peerId);
if (history->skipCloudDraftUpdate(topicRootId, date)) {
2018-06-26 13:58:29 +00:00
return;
}
history->clearCloudDraft(topicRootId);
history->applyCloudDraft(topicRootId);
}
2016-05-31 09:46:31 +00:00
} // namespace Data