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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
namespace Ui {
|
2018-05-21 21:31:46 +00:00
|
|
|
class InputField;
|
2016-11-15 11:56:49 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft);
|
2018-06-26 13:58:29 +00:00
|
|
|
void clearPeerCloudDraft(PeerId peerId, TimeId date);
|
2016-06-09 14:31:10 +00:00
|
|
|
|
|
|
|
struct Draft {
|
2018-02-03 19:52:35 +00:00
|
|
|
Draft() = default;
|
|
|
|
Draft(
|
|
|
|
const TextWithTags &textWithTags,
|
|
|
|
MsgId msgId,
|
|
|
|
const MessageCursor &cursor,
|
|
|
|
bool previewCancelled,
|
|
|
|
mtpRequestId saveRequestId = 0);
|
|
|
|
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,
|
|
|
|
bool previewCancelled,
|
|
|
|
mtpRequestId saveRequestId = 0);
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date = 0;
|
2016-06-09 14:31:10 +00:00
|
|
|
TextWithTags textWithTags;
|
|
|
|
MsgId msgId = 0; // replyToId for message draft, editMsgId for edit draft
|
|
|
|
MessageCursor cursor;
|
|
|
|
bool previewCancelled = false;
|
|
|
|
mtpRequestId saveRequestId = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool draftStringIsEmpty(const QString &text) {
|
|
|
|
for_const (auto ch, text) {
|
|
|
|
if (!ch.isSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool draftIsNull(Draft *draft) {
|
2016-06-14 16:26:41 +00:00
|
|
|
return !draft || (draftStringIsEmpty(draft->textWithTags.text) && !draft->msgId);
|
2016-06-09 14:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool draftsAreEqual(Draft *a, Draft *b) {
|
|
|
|
bool aIsNull = draftIsNull(a);
|
|
|
|
bool bIsNull = draftIsNull(b);
|
|
|
|
if (aIsNull) {
|
|
|
|
return bIsNull;
|
|
|
|
} else if (bIsNull) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (a->textWithTags == b->textWithTags) && (a->msgId == b->msgId) && (a->previewCancelled == b->previewCancelled);
|
|
|
|
}
|
2016-05-31 09:46:31 +00:00
|
|
|
|
|
|
|
} // namespace Data
|