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
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
void ApplyPeerCloudDraft(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
PeerId peerId,
|
|
|
|
const MTPDdraftMessage &draft);
|
|
|
|
void ClearPeerCloudDraft(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
inline bool draftIsNull(const Draft *draft) {
|
|
|
|
return !draft
|
|
|
|
|| (draftStringIsEmpty(draft->textWithTags.text) && !draft->msgId);
|
2016-06-09 14:31:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
inline bool draftsAreEqual(const Draft *a, const Draft *b) {
|
2016-06-09 14:31:10 +00:00
|
|
|
bool aIsNull = draftIsNull(a);
|
|
|
|
bool bIsNull = draftIsNull(b);
|
|
|
|
if (aIsNull) {
|
|
|
|
return bIsNull;
|
|
|
|
} else if (bIsNull) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
return (a->textWithTags == b->textWithTags)
|
|
|
|
&& (a->msgId == b->msgId)
|
|
|
|
&& (a->previewCancelled == b->previewCancelled);
|
2016-06-09 14:31:10 +00:00
|
|
|
}
|
2016-05-31 09:46:31 +00:00
|
|
|
|
|
|
|
} // namespace Data
|