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
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "api/api_text_entities.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.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"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session.h"
|
2019-01-18 12:27:37 +00:00
|
|
|
#include "data/data_session.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 {
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
Draft::Draft(
|
|
|
|
const TextWithTags &textWithTags,
|
|
|
|
MsgId msgId,
|
2022-10-17 16:29:48 +00:00
|
|
|
MsgId topicRootId,
|
2018-02-03 19:52:35 +00:00
|
|
|
const MessageCursor &cursor,
|
2021-01-29 11:27:17 +00:00
|
|
|
PreviewState previewState,
|
2018-02-03 19:52:35 +00:00
|
|
|
mtpRequestId saveRequestId)
|
|
|
|
: textWithTags(textWithTags)
|
|
|
|
, msgId(msgId)
|
2022-10-17 16:29:48 +00:00
|
|
|
, topicRootId(topicRootId)
|
2018-02-03 19:52:35 +00:00
|
|
|
, cursor(cursor)
|
2021-01-29 11:27:17 +00:00
|
|
|
, previewState(previewState)
|
2018-02-03 19:52:35 +00:00
|
|
|
, saveRequestId(saveRequestId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Draft::Draft(
|
2018-05-21 21:31:46 +00:00
|
|
|
not_null<const Ui::InputField*> field,
|
2018-02-03 19:52:35 +00:00
|
|
|
MsgId msgId,
|
2022-10-17 16:29:48 +00:00
|
|
|
MsgId topicRootId,
|
2021-01-29 11:27:17 +00:00
|
|
|
PreviewState previewState,
|
2018-02-03 19:52:35 +00:00
|
|
|
mtpRequestId saveRequestId)
|
|
|
|
: textWithTags(field->getTextWithTags())
|
|
|
|
, msgId(msgId)
|
2022-10-17 16:29:48 +00:00
|
|
|
, topicRootId(topicRootId)
|
2018-02-03 19:52:35 +00:00
|
|
|
, cursor(field)
|
2021-01-29 11:27:17 +00:00
|
|
|
, previewState(previewState) {
|
2016-11-15 11:56:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
void ApplyPeerCloudDraft(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
PeerId peerId,
|
2022-10-17 16:29:48 +00:00
|
|
|
MsgId topicRootId,
|
2020-06-08 08:03:45 +00:00
|
|
|
const MTPDdraftMessage &draft) {
|
|
|
|
const auto history = session->data().history(peerId);
|
2021-03-12 11:18:33 +00:00
|
|
|
const auto date = draft.vdate().v;
|
2022-10-17 16:29:48 +00:00
|
|
|
if (history->skipCloudDraftUpdate(topicRootId, date)) {
|
2021-03-12 11:18:33 +00:00
|
|
|
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()))
|
2018-05-22 19:09:13 +00:00
|
|
|
};
|
2020-06-08 08:03:45 +00:00
|
|
|
const auto replyTo = draft.vreply_to_msg_id().value_or_empty();
|
2018-11-15 15:36:04 +00:00
|
|
|
auto cloudDraft = std::make_unique<Draft>(
|
|
|
|
textWithTags,
|
|
|
|
replyTo,
|
2022-10-17 16:29:48 +00:00
|
|
|
topicRootId,
|
2018-11-15 15:36:04 +00:00
|
|
|
MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX),
|
2021-01-29 11:27:17 +00:00
|
|
|
(draft.is_no_webpage()
|
|
|
|
? Data::PreviewState::Cancelled
|
|
|
|
: Data::PreviewState::Allowed));
|
2021-03-12 11:18:33 +00:00
|
|
|
cloudDraft->date = date;
|
2016-06-03 18:24:27 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
history->setCloudDraft(std::move(cloudDraft));
|
2022-10-17 16:29:48 +00:00
|
|
|
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,
|
2022-10-17 16:29:48 +00:00
|
|
|
MsgId topicRootId,
|
2020-06-08 08:03:45 +00:00
|
|
|
TimeId date) {
|
|
|
|
const auto history = session->data().history(peerId);
|
2022-10-17 16:29:48 +00:00
|
|
|
if (history->skipCloudDraftUpdate(topicRootId, date)) {
|
2018-06-26 13:58:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-09 14:31:10 +00:00
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
history->clearCloudDraft(topicRootId);
|
|
|
|
history->applyCloudDraft(topicRootId);
|
2016-06-09 14:31:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
} // namespace Data
|