diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index c459ffcf5..6222b28bb 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2449,7 +2449,7 @@ void ApiWrap::saveDraftsToCloud() { auto flags = MTPmessages_SaveDraft::Flags(0); auto &textWithTags = cloudDraft->textWithTags; - if (cloudDraft->previewCancelled) { + if (cloudDraft->previewState != Data::PreviewState::Allowed) { flags |= MTPmessages_SaveDraft::Flag::f_no_webpage; } if (cloudDraft->msgId) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 2513d507e..12037e961 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -501,6 +501,11 @@ MessageLinksParser::MessageLinksParser(not_null field) _field->installEventFilter(this); } +void MessageLinksParser::parseNow() { + _timer.cancel(); + parse(); +} + bool MessageLinksParser::eventFilter(QObject *object, QEvent *event) { if (object == _field) { if (event->type() == QEvent::KeyPress) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index fd7e53aad..72c737dd4 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -71,7 +71,9 @@ class MessageLinksParser : private QObject { public: MessageLinksParser(not_null field); - const rpl::variable &list() const; + void parseNow(); + + [[nodiscard]] const rpl::variable &list() const; protected: bool eventFilter(QObject *object, QEvent *event) override; diff --git a/Telegram/SourceFiles/data/data_drafts.cpp b/Telegram/SourceFiles/data/data_drafts.cpp index f24fda93f..ef649ad83 100644 --- a/Telegram/SourceFiles/data/data_drafts.cpp +++ b/Telegram/SourceFiles/data/data_drafts.cpp @@ -18,32 +18,29 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" namespace Data { -namespace { - -} // namespace Draft::Draft( const TextWithTags &textWithTags, MsgId msgId, const MessageCursor &cursor, - bool previewCancelled, + PreviewState previewState, mtpRequestId saveRequestId) : textWithTags(textWithTags) , msgId(msgId) , cursor(cursor) -, previewCancelled(previewCancelled) +, previewState(previewState) , saveRequestId(saveRequestId) { } Draft::Draft( not_null field, MsgId msgId, - bool previewCancelled, + PreviewState previewState, mtpRequestId saveRequestId) : textWithTags(field->getTextWithTags()) , msgId(msgId) , cursor(field) -, previewCancelled(previewCancelled) { +, previewState(previewState) { } void ApplyPeerCloudDraft( @@ -66,7 +63,9 @@ void ApplyPeerCloudDraft( textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), - draft.is_no_webpage()); + (draft.is_no_webpage() + ? Data::PreviewState::Cancelled + : Data::PreviewState::Allowed)); cloudDraft->date = draft.vdate().v; history->setCloudDraft(std::move(cloudDraft)); diff --git a/Telegram/SourceFiles/data/data_drafts.h b/Telegram/SourceFiles/data/data_drafts.h index b797cb3d3..a8c391d5b 100644 --- a/Telegram/SourceFiles/data/data_drafts.h +++ b/Telegram/SourceFiles/data/data_drafts.h @@ -26,25 +26,31 @@ void ClearPeerCloudDraft( PeerId peerId, TimeId date); +enum class PreviewState : char { + Allowed, + Cancelled, + EmptyOnEdit, +}; + struct Draft { Draft() = default; Draft( const TextWithTags &textWithTags, MsgId msgId, const MessageCursor &cursor, - bool previewCancelled, + PreviewState previewState, mtpRequestId saveRequestId = 0); Draft( not_null field, MsgId msgId, - bool previewCancelled, + PreviewState previewState, mtpRequestId saveRequestId = 0); TimeId date = 0; TextWithTags textWithTags; MsgId msgId = 0; // replyToId for message draft, editMsgId for edit draft MessageCursor cursor; - bool previewCancelled = false; + PreviewState previewState = PreviewState::Allowed; mtpRequestId saveRequestId = 0; }; @@ -144,7 +150,7 @@ inline bool draftsAreEqual(const Draft *a, const Draft *b) { return (a->textWithTags == b->textWithTags) && (a->msgId == b->msgId) - && (a->previewCancelled == b->previewCancelled); + && (a->previewState == b->previewState); } } // namespace Data diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 8e51f250a..8728fe610 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -215,13 +215,13 @@ void History::createLocalDraftFromCloud() { draft->textWithTags, draft->msgId, draft->cursor, - draft->previewCancelled)); + draft->previewState)); existing = localDraft(); } else if (existing != draft) { existing->textWithTags = draft->textWithTags; existing->msgId = draft->msgId; existing->cursor = draft->cursor; - existing->previewCancelled = draft->previewCancelled; + existing->previewState = draft->previewState; } existing->date = draft->date; } @@ -280,7 +280,7 @@ Data::Draft *History::createCloudDraft(const Data::Draft *fromDraft) { TextWithTags(), 0, MessageCursor(), - false)); + Data::PreviewState::Allowed)); cloudDraft()->date = TimeId(0); } else { auto existing = cloudDraft(); @@ -289,13 +289,13 @@ Data::Draft *History::createCloudDraft(const Data::Draft *fromDraft) { fromDraft->textWithTags, fromDraft->msgId, fromDraft->cursor, - fromDraft->previewCancelled)); + fromDraft->previewState)); existing = cloudDraft(); } else if (existing != fromDraft) { existing->textWithTags = fromDraft->textWithTags; existing->msgId = fromDraft->msgId; existing->cursor = fromDraft->cursor; - existing->previewCancelled = fromDraft->previewCancelled; + existing->previewState = fromDraft->previewState; } existing->date = base::unixtime::now(); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e46bc467e..8cad61a24 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -174,6 +174,7 @@ HistoryWidget::HistoryWidget( , _updateEditTimeLeftDisplay([=] { updateField(); }) , _fieldBarCancel(this, st::historyReplyCancel) , _previewTimer([=] { requestPreview(); }) +, _previewState(Data::PreviewState::Allowed) , _topBar(this, controller) , _scroll(this, st::historyScroll, false) , _updateHistoryItems([=] { updateHistoryItemsByTimer(); }) @@ -335,6 +336,10 @@ HistoryWidget::HistoryWidget( _fieldLinksParser = std::make_unique(_field); _fieldLinksParser->list().changes( ) | rpl::start_with_next([=](QStringList &&parsed) { + if (_previewState == Data::PreviewState::EmptyOnEdit + && _parsedLinks != parsed) { + _previewState = Data::PreviewState::Allowed; + } _parsedLinks = std::move(parsed); checkPreview(); }, lifetime()); @@ -1328,7 +1333,7 @@ void HistoryWidget::fieldChanged() { updateSendButtonType(); if (!HasSendText(_field)) { - _previewCancelled = false; + _previewState = Data::PreviewState::Allowed; } if (updateCmdStartShown()) { updateControlsVisibility(); @@ -1377,10 +1382,17 @@ void HistoryWidget::saveFieldToHistoryLocalDraft() { if (!_history) return; if (_editMsgId) { - _history->setLocalEditDraft(std::make_unique(_field, _editMsgId, _previewCancelled, _saveEditMsgRequestId)); + _history->setLocalEditDraft(std::make_unique( + _field, + _editMsgId, + _previewState, + _saveEditMsgRequestId)); } else { if (_replyToId || !_field->empty()) { - _history->setLocalDraft(std::make_unique(_field, _replyToId, _previewCancelled)); + _history->setLocalDraft(std::make_unique( + _field, + _replyToId, + _previewState)); } else { _history->clearLocalDraft(); } @@ -1401,7 +1413,7 @@ void HistoryWidget::writeDraftTexts() { Storage::MessageDraft{ _editMsgId ? _editMsgId : _replyToId, _field->getTextWithTags(), - _previewCancelled, + _previewState, }); if (_migrated) { _migrated->clearDrafts(); @@ -1476,7 +1488,11 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U if (_history) { TextWithTags textWithTags = { '@' + samePeerBot->username + ' ' + query, TextWithTags::Tags() }; MessageCursor cursor = { textWithTags.text.size(), textWithTags.text.size(), QFIXED_MAX }; - _history->setLocalDraft(std::make_unique(textWithTags, 0, cursor, false)); + _history->setLocalDraft(std::make_unique( + textWithTags, + 0, + cursor, + Data::PreviewState::Allowed)); applyDraft(); return true; } @@ -1497,7 +1513,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U textWithTags, to.currentReplyToId, cursor, - false); + Data::PreviewState::Allowed); if (to.section == Section::Replies) { history->setDraft( @@ -1653,8 +1669,15 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) { setFieldText(draft->textWithTags, 0, fieldHistoryAction); _field->setFocus(); draft->cursor.applyTo(_field); - _textUpdateEvents = TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping; - _previewCancelled = draft->previewCancelled; + _textUpdateEvents = TextUpdateEvent::SaveDraft + | TextUpdateEvent::SendTyping; + + // Save links from _field to _parsedLinks without generating preview. + _previewState = Data::PreviewState::Cancelled; + _fieldLinksParser->parseNow(); + _parsedLinks = _fieldLinksParser->list().current(); + _previewState = draft->previewState; + _replyEditMsg = nullptr; if (const auto editDraft = _history->localEditDraft()) { _editMsgId = editDraft->msgId; @@ -2986,7 +3009,7 @@ void HistoryWidget::saveEditMsg() { cancelEdit(); return; } - const auto webPageId = _previewCancelled + const auto webPageId = (_previewState != Data::PreviewState::Allowed) ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id @@ -3106,7 +3129,7 @@ void HistoryWidget::send(Api::SendOptions options) { return; } - const auto webPageId = _previewCancelled + const auto webPageId = (_previewState != Data::PreviewState::Allowed) ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id @@ -5580,7 +5603,7 @@ void HistoryWidget::setFieldText( | TextUpdateEvent::SendTyping; previewCancel(); - _previewCancelled = false; + _previewState = Data::PreviewState::Allowed; } void HistoryWidget::clearFieldText( @@ -5623,7 +5646,7 @@ void HistoryWidget::replyToMessage(not_null item) { TextWithTags(), item->id, MessageCursor(), - false)); + Data::PreviewState::Allowed)); } } else { _replyEditMsg = item; @@ -5670,7 +5693,7 @@ void HistoryWidget::editMessage(not_null item) { _history->setLocalDraft(std::make_unique( _field, _replyToId, - _previewCancelled)); + _previewState)); } else { _history->clearLocalDraft(); } @@ -5688,12 +5711,14 @@ void HistoryWidget::editMessage(not_null item) { } return nullptr; }(); - const auto previewCancelled = !previewPage; + const auto previewState = previewPage + ? Data::PreviewState::Allowed + : Data::PreviewState::EmptyOnEdit; _history->setLocalEditDraft(std::make_unique( editData, item->id, cursor, - previewCancelled)); + previewState)); applyDraft(); _previewData = previewPage; @@ -5853,7 +5878,7 @@ void HistoryWidget::cancelFieldAreaState() { Ui::hideLayer(); _replyForwardPressed = false; if (_previewData && _previewData->pendingTill >= 0) { - _previewCancelled = true; + _previewState = Data::PreviewState::Cancelled; previewCancel(); _saveDraftText = true; @@ -5881,7 +5906,7 @@ void HistoryWidget::checkPreview() { const auto previewRestricted = [&] { return _peer && _peer->amRestricted(ChatRestriction::f_embed_links); }(); - if (_previewCancelled || previewRestricted) { + if (_previewState != Data::PreviewState::Allowed || previewRestricted) { previewCancel(); return; } @@ -5929,7 +5954,10 @@ void HistoryWidget::requestPreview() { }).send(); } -void HistoryWidget::gotPreview(QString links, const MTPMessageMedia &result, mtpRequestId req) { +void HistoryWidget::gotPreview( + QString links, + const MTPMessageMedia &result, + mtpRequestId req) { if (req == _previewRequest) { _previewRequest = 0; } @@ -5937,10 +5965,12 @@ void HistoryWidget::gotPreview(QString links, const MTPMessageMedia &result, mtp const auto &data = result.c_messageMediaWebPage().vwebpage(); const auto page = session().data().processWebpage(data); _previewCache.insert(links, page->id); - if (page->pendingTill > 0 && page->pendingTill <= base::unixtime::now()) { + if (page->pendingTill > 0 + && page->pendingTill <= base::unixtime::now()) { page->pendingTill = -1; } - if (links == _previewLinks && !_previewCancelled) { + if (links == _previewLinks + && _previewState == Data::PreviewState::Allowed) { _previewData = (page->id && page->pendingTill >= 0) ? page.get() : nullptr; @@ -5949,7 +5979,8 @@ void HistoryWidget::gotPreview(QString links, const MTPMessageMedia &result, mtp session().data().sendWebPageGamePollNotifications(); } else if (result.type() == mtpc_messageMediaEmpty) { _previewCache.insert(links, 0); - if (links == _previewLinks && !_previewCancelled) { + if (links == _previewLinks + && _previewState == Data::PreviewState::Allowed) { _previewData = nullptr; updatePreview(); } diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 163b9ac01..3c52c09ac 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -25,6 +25,10 @@ struct SendingAlbum; enum class SendMediaType; class MessageLinksParser; +namespace Data { +enum class PreviewState : char; +} // namespace Data + namespace SendMenu { enum class Type; } // namespace SendMenu @@ -617,7 +621,7 @@ private: Ui::Text::String _previewTitle; Ui::Text::String _previewDescription; base::Timer _previewTimer; - bool _previewCancelled = false; + Data::PreviewState _previewState = Data::PreviewState(); bool _replyForwardPressed = false; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index c3d962906..c34332fbe 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -612,7 +612,8 @@ ComposeControls::ComposeControls( _send, st::historySendSize.height())) , _sendMenuType(sendMenuType) -, _saveDraftTimer([=] { saveDraft(); }) { +, _saveDraftTimer([=] { saveDraft(); }) +, _previewState(Data::PreviewState::Allowed) { init(); } @@ -865,7 +866,7 @@ void ComposeControls::setFieldText( | TextUpdateEvent::SendTyping; _previewCancel(); - _previewCancelled = false; + _previewState = Data::PreviewState::Allowed; } void ComposeControls::saveFieldToHistoryLocalDraft() { @@ -880,7 +881,7 @@ void ComposeControls::saveFieldToHistoryLocalDraft() { std::make_unique( _field, _header->getDraftMessageId(), - _previewCancelled)); + _previewState)); } else { _history->clearDraft(draftKeyCurrent()); } @@ -964,7 +965,7 @@ void ComposeControls::init() { _header->previewCancelled( ) | rpl::start_with_next([=] { - _previewCancelled = true; + _previewState = Data::PreviewState::Cancelled; _saveDraftText = true; _saveDraftStart = crl::now(); saveDraft(); @@ -1224,7 +1225,7 @@ void ComposeControls::fieldChanged() { } updateSendButtonType(); if (!HasSendText(_field)) { - _previewCancelled = false; + _previewState = Data::PreviewState::Allowed; } if (updateBotCommandShown()) { updateControlsVisibility(); @@ -1294,7 +1295,7 @@ void ComposeControls::writeDraftTexts() { Storage::MessageDraft{ _header->getDraftMessageId(), _field->getTextWithTags(), - _previewCancelled, + _previewState, }); } @@ -1353,7 +1354,8 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) { _field->setFocus(); draft->cursor.applyTo(_field); _textUpdateEvents = TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping; - _previewCancelled = draft->previewCancelled; + _previewSetState(draft->previewState); + if (draft == editDraft) { _header->editMessage({ _history->channelId(), draft->msgId }); _header->replyToMessage({}); @@ -1837,14 +1839,16 @@ void ComposeControls::editMessage(not_null item) { } return nullptr; }(); - const auto previewCancelled = !previewPage; + const auto previewState = previewPage + ? Data::PreviewState::Allowed + : Data::PreviewState::EmptyOnEdit; _history->setDraft( draftKey(DraftType::Edit), std::make_unique( editData, item->id, cursor, - previewCancelled)); + previewState)); applyDraft(); if (_autocomplete) { @@ -1883,7 +1887,7 @@ void ComposeControls::replyToMessage(FullMsgId id) { TextWithTags(), id.msg, MessageCursor(), - false)); + Data::PreviewState::Allowed)); } } else { _header->replyToMessage(id); @@ -1995,7 +1999,8 @@ void ComposeControls::initWebpageProcess() { if (till > 0 && till <= base::unixtime::now()) { till = -1; } - if (links == *previewLinks && !_previewCancelled) { + if (links == *previewLinks + && _previewState == Data::PreviewState::Allowed) { *previewData = (page->id && page->pendingTill >= 0) ? page.get() : nullptr; @@ -2003,7 +2008,8 @@ void ComposeControls::initWebpageProcess() { } }, [=](const MTPDmessageMediaEmpty &d) { previewCache->insert({ links, 0 }); - if (links == *previewLinks && !_previewCancelled) { + if (links == *previewLinks + && _previewState == Data::PreviewState::Allowed) { *previewData = nullptr; updatePreview(); } @@ -2032,7 +2038,8 @@ void ComposeControls::initWebpageProcess() { const auto checkPreview = crl::guard(_wrap.get(), [=] { const auto previewRestricted = peer && peer->amRestricted(ChatRestriction::f_embed_links); - if (_previewCancelled || previewRestricted) { + if (_previewState != Data::PreviewState::Allowed + || previewRestricted) { _previewCancel(); return; } @@ -2105,8 +2112,20 @@ void ComposeControls::initWebpageProcess() { const auto fieldLinksParser = lifetime.make_state(_field); + _previewSetState = [=](Data::PreviewState state) { + // Save links from _field to _parsedLinks without generating preview. + _previewState = Data::PreviewState::Cancelled; + fieldLinksParser->parseNow(); + *parsedLinks = fieldLinksParser->list().current(); + _previewState = state; + }; + fieldLinksParser->list().changes( ) | rpl::start_with_next([=](QStringList &&parsed) { + if (_previewState == Data::PreviewState::EmptyOnEdit + && *parsedLinks != parsed) { + _previewState = Data::PreviewState::Allowed; + } *parsedLinks = std::move(parsed); checkPreview(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 30201f1ac..d6328a055 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -34,6 +34,7 @@ namespace Data { struct MessagePosition; struct Draft; class DraftKey; +enum class PreviewState : char; } // namespace Data namespace InlineBots { @@ -307,7 +308,8 @@ private: bool _botCommandShown = false; Fn _previewCancel; - bool _previewCancelled = false; + Fn _previewSetState; + Data::PreviewState _previewState = Data::PreviewState(); rpl::lifetime _uploaderSubscriptions; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 1ec922262..5b8ee8c4a 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -902,11 +902,7 @@ void RepliesWidget::send(Api::SendOptions options) { return; } - const auto webPageId = _composeControls->webPageId();/* _previewCancelled - ? CancelledWebPageId - : ((_previewData && _previewData->pendingTill >= 0) - ? _previewData->id - : WebPageId(0));*/ + const auto webPageId = _composeControls->webPageId(); auto message = ApiWrap::MessageToSend(_history); message.textWithTags = _composeControls->getTextWithAppliedMarkdown(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 1755b6ed6..9faee54c7 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -523,11 +523,7 @@ void ScheduledWidget::send() { } void ScheduledWidget::send(Api::SendOptions options) { - const auto webPageId = _composeControls->webPageId();/* _previewCancelled - ? CancelledWebPageId - : ((_previewData && _previewData->pendingTill >= 0) - ? _previewData->id - : WebPageId(0));*/ + const auto webPageId = _composeControls->webPageId(); auto message = ApiWrap::MessageToSend(_history); message.textWithTags = _composeControls->getTextWithAppliedMarkdown(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index bbf183590..50c8614bf 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -548,8 +548,11 @@ bool MainWidget::shareUrl( QFIXED_MAX }; auto history = peer->owner().history(peer); - history->setLocalDraft( - std::make_unique(textWithTags, 0, cursor, false)); + history->setLocalDraft(std::make_unique( + textWithTags, + 0, + cursor, + Data::PreviewState::Allowed)); history->clearLocalEditDraft(); history->session().changes().historyUpdated( history, @@ -576,7 +579,11 @@ bool MainWidget::inlineSwitchChosen(PeerId peerId, const QString &botAndQuery) { const auto h = peer->owner().history(peer); TextWithTags textWithTags = { botAndQuery, TextWithTags::Tags() }; MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX }; - h->setLocalDraft(std::make_unique(textWithTags, 0, cursor, false)); + h->setLocalDraft(std::make_unique( + textWithTags, + 0, + cursor, + Data::PreviewState::Allowed)); h->clearLocalEditDraft(); h->session().changes().historyUpdated( h, diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index ee882fc6a..d274b60ff 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -958,7 +958,7 @@ void EnumerateDrafts( key, draft->msgId, draft->textWithTags, - draft->previewCancelled, + draft->previewState, draft->cursor); } if (replaceKey @@ -969,7 +969,7 @@ void EnumerateDrafts( replaceKey, replaceDraft.msgId, replaceDraft.textWithTags, - replaceDraft.previewCancelled, + replaceDraft.previewState, replaceCursor); } } @@ -1017,12 +1017,12 @@ void Account::writeDrafts( auto&&, // key MsgId, // msgId const TextWithTags &text, - bool, // previewCancelled + Data::PreviewState, auto&&) { // cursor size += sizeof(qint32) // key + Serialize::stringSize(text.text) + sizeof(quint32) + TextUtilities::SerializeTagsSize(text.tags) - + 2 * sizeof(qint32); // msgId, previewCancelled + + 2 * sizeof(qint32); // msgId, previewState }; EnumerateDrafts( map, @@ -1043,14 +1043,14 @@ void Account::writeDrafts( const Data::DraftKey &key, MsgId msgId, const TextWithTags &text, - bool previewCancelled, + Data::PreviewState previewState, auto&&) { // cursor data.stream << key.serialize() << text.text << TextUtilities::SerializeTags(text.tags) << qint32(msgId) - << qint32(previewCancelled ? 1 : 0); + << qint32(previewState); }; EnumerateDrafts( map, @@ -1109,7 +1109,7 @@ void Account::writeDraftCursors( auto&&, // key MsgId, // msgId auto&&, // text - bool, // previewCancelled + Data::PreviewState, const MessageCursor &cursor) { // cursor data.stream << qint32(cursor.position) @@ -1249,23 +1249,29 @@ void Account::readDraftsWithCursors(not_null history) { for (auto i = 0; i != count; ++i) { TextWithTags data; QByteArray tagsSerialized; - qint32 keyValue = 0, messageId = 0, previewCancelled = 0; + qint32 keyValue = 0, messageId = 0, uncheckedPreviewState = 0; draft.stream >> keyValue >> data.text >> tagsSerialized >> messageId - >> previewCancelled; + >> uncheckedPreviewState; data.tags = TextUtilities::DeserializeTags( tagsSerialized, data.text.size()); + auto previewState = Data::PreviewState::Allowed; + switch (static_cast(uncheckedPreviewState)) { + case Data::PreviewState::Cancelled: + case Data::PreviewState::EmptyOnEdit: + previewState = Data::PreviewState(uncheckedPreviewState); + } const auto key = Data::DraftKey::FromSerialized(keyValue); if (key && key != Data::DraftKey::Cloud()) { map.emplace(key, std::make_unique( data, messageId, MessageCursor(), - previewCancelled)); + previewState)); } } if (draft.stream.status() != QDataStream::Ok) { @@ -1326,14 +1332,18 @@ void Account::readDraftsWithCursorsLegacy( msgData, msgReplyTo, MessageCursor(), - msgPreviewCancelled)); + (msgPreviewCancelled + ? Data::PreviewState::Cancelled + : Data::PreviewState::Allowed))); } if (editMsgId) { map.emplace(Data::DraftKey::LocalEdit(), std::make_unique( editData, editMsgId, MessageCursor(), - editPreviewCancelled)); + (editPreviewCancelled + ? Data::PreviewState::Cancelled + : Data::PreviewState::Allowed))); } readDraftCursors(peerId, map); history->setDraftsMap(std::move(map)); diff --git a/Telegram/SourceFiles/storage/storage_account.h b/Telegram/SourceFiles/storage/storage_account.h index 1aeb64d0b..4cb6fbc5a 100644 --- a/Telegram/SourceFiles/storage/storage_account.h +++ b/Telegram/SourceFiles/storage/storage_account.h @@ -52,7 +52,7 @@ enum class StartResult : uchar; struct MessageDraft { MsgId msgId = 0; TextWithTags textWithTags; - bool previewCancelled = false; + Data::PreviewState previewState = Data::PreviewState::Allowed; }; class Account final { diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index ffbd3c1cb..940b25388 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -155,7 +155,7 @@ Data::Draft OccupiedDraft(const QString &normalizedName) { + normalizedName }, MsgId(0), MessageCursor(), - false + Data::PreviewState::Allowed }; }