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

105 lines
2.7 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"
2023-10-10 10:49:22 +04:00
#include "history/history_item_components.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,
2023-10-10 10:49:22 +04:00
FullReplyTo reply,
const MessageCursor &cursor,
PreviewState previewState,
mtpRequestId saveRequestId)
: textWithTags(textWithTags)
2023-10-10 10:49:22 +04:00
, reply(std::move(reply))
, cursor(cursor)
, previewState(previewState)
, saveRequestId(saveRequestId) {
}
Draft::Draft(
2018-05-22 00:31:46 +03:00
not_null<const Ui::InputField*> field,
2023-10-10 10:49:22 +04:00
FullReplyTo reply,
PreviewState previewState,
mtpRequestId saveRequestId)
: textWithTags(field->getTextWithTags())
2023-10-10 10:49:22 +04:00
, reply(std::move(reply))
, 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()))
};
2023-10-10 10:49:22 +04:00
const auto reply = draft.vreply_to()
? ReplyFieldsFromMTP(history, *draft.vreply_to())
: ReplyFields();
const auto replyPeerId = reply.externalPeerId
? reply.externalPeerId
: peerId;
auto cloudDraft = std::make_unique<Draft>(
textWithTags,
2023-10-10 10:49:22 +04:00
FullReplyTo{
.messageId = FullMsgId(replyPeerId, reply.messageId),
.quote = reply.quote,
2023-10-10 10:49:22 +04:00
.storyId = (reply.storyId
2023-10-11 08:43:32 +04:00
? FullStoryId{ replyPeerId, reply.storyId }
2023-10-10 10:49:22 +04:00
: FullStoryId()),
.topicRootId = topicRootId,
},
2023-10-13 10:04:29 +04:00
MessageCursor(Ui::kQFixedMax, Ui::kQFixedMax, Ui::kQFixedMax),
(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