2016-05-31 09:46:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
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
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2016-06-03 18:24:27 +00:00
|
|
|
#include "historywidget.h"
|
|
|
|
#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 {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
Draft::Draft(const Ui::FlatTextarea *field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId)
|
|
|
|
: textWithTags(field->getTextWithTags())
|
|
|
|
, msgId(msgId)
|
|
|
|
, cursor(field)
|
|
|
|
, previewCancelled(previewCancelled) {
|
|
|
|
}
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
|
2016-06-03 18:24:27 +00:00
|
|
|
auto history = App::history(peerId);
|
|
|
|
auto text = qs(draft.vmessage);
|
2017-03-10 19:46:28 +00:00
|
|
|
auto entities = draft.has_entities() ? entitiesFromMTP(draft.ventities.v) : EntitiesInText();
|
2017-04-08 13:27:53 +00:00
|
|
|
TextWithTags textWithTags = { textApplyEntities(text, entities), ConvertEntitiesToTextTags(entities) };
|
2016-06-03 18:24:27 +00:00
|
|
|
MsgId replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : 0;
|
2017-02-21 13:45:56 +00:00
|
|
|
auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage());
|
2016-06-03 18:24:27 +00:00
|
|
|
cloudDraft->date = ::date(draft.vdate);
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
history->setCloudDraft(std::move(cloudDraft));
|
2016-06-03 18:24:27 +00:00
|
|
|
history->createLocalDraftFromCloud();
|
|
|
|
history->updateChatListSortPosition();
|
|
|
|
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->applyCloudDraft(history);
|
|
|
|
}
|
2016-05-31 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:31:10 +00: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 09:46:31 +00:00
|
|
|
} // namespace Data
|