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

60 lines
1.8 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
#include "ui/widgets/input_fields.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 "mainwidget.h"
2017-03-04 13:23:56 +03:00
#include "storage/localstorage.h"
2016-05-31 12:46:31 +03:00
namespace Data {
namespace {
} // namespace
Draft::Draft(const Ui::FlatTextarea *field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId)
: textWithTags(field->getTextWithTags())
, msgId(msgId)
, cursor(field)
, previewCancelled(previewCancelled) {
}
2016-05-31 12:46:31 +03:00
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
auto history = App::history(peerId);
auto text = TextWithEntities { qs(draft.vmessage), draft.has_entities() ? TextUtilities::EntitiesFromMTP(draft.ventities.v) : EntitiesInText() };
auto textWithTags = TextWithTags { TextUtilities::ApplyEntities(text), ConvertEntitiesToTextTags(text.entities) };
auto replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : MsgId(0);
auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage());
cloudDraft->date = ::date(draft.vdate);
history->setCloudDraft(std::move(cloudDraft));
history->createLocalDraftFromCloud();
history->updateChatListSortPosition();
if (auto main = App::main()) {
main->applyCloudDraft(history);
}
2016-05-31 12:46:31 +03:00
}
void clearPeerCloudDraft(PeerId peerId) {
auto history = App::history(peerId);
history->clearCloudDraft();
history->clearLocalDraft();
history->updateChatListSortPosition();
if (auto main = App::main()) {
main->applyCloudDraft(history);
}
}
2016-05-31 12:46:31 +03:00
} // namespace Data