tdesktop/Telegram/SourceFiles/data/data_drafts.h

80 lines
1.7 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
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);
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(const Draft *draft) {
return !draft
|| (draftStringIsEmpty(draft->textWithTags.text) && !draft->msgId);
}
inline bool draftsAreEqual(const Draft *a, const 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