tdesktop/Telegram/SourceFiles/data/data_drafts.h

67 lines
1.5 KiB
C
Raw Normal View History

2016-05-31 09:46:31 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2016-05-31 09:46:31 +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
namespace Ui {
2018-05-21 21:31:46 +00:00
class InputField;
} // 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);
struct Draft {
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,
MsgId msgId,
bool previewCancelled,
mtpRequestId saveRequestId = 0);
TimeId date = 0;
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) {
return !draft || (draftStringIsEmpty(draft->textWithTags.text) && !draft->msgId);
}
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