2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 10:47:11 +00:00
tdesktop/Telegram/SourceFiles/data/data_drafts.cpp

97 lines
2.4 KiB
C++
Raw Normal View History

2016-05-31 12:46:31 +03:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2016-05-31 12:46:31 +03:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2016-05-31 12:46:31 +03:00
*/
#include "data/data_drafts.h"
2016-05-31 12:46:31 +03:00
2019-09-16 14:14:06 +03: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 13:27:09 +03:00
#include "history/history_widget.h"
#include "main/main_session.h"
2019-01-18 16:27:37 +04:00
#include "data/data_session.h"
#include "mainwidget.h"
2017-03-04 13:23:56 +03:00
#include "storage/localstorage.h"
2016-05-31 12:46:31 +03: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-22 00:31:46 +03: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 12:03:45 +04:00
void ApplyPeerCloudDraft(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
2020-06-08 12:03:45 +04: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 15:38:38 +02:00
qs(draft.vmessage()),
2019-09-16 14:14:06 +03:00
TextUtilities::ConvertEntitiesToTextTags(
2020-06-08 12:03:45 +04:00
Api::EntitiesFromMTP(
session,
draft.ventities().value_or_empty()))
};
2020-06-08 12:03:45 +04: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 12:46:31 +03:00
}
2020-06-08 12:03:45 +04:00
void ClearPeerCloudDraft(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
2020-06-08 12:03:45 +04:00
TimeId date) {
const auto history = session->data().history(peerId);
if (history->skipCloudDraftUpdate(topicRootId, date)) {
2018-06-26 14:58:29 +01:00
return;
}
history->clearCloudDraft(topicRootId);
history->applyCloudDraft(topicRootId);
}
2016-05-31 12:46:31 +03:00
} // namespace Data