diff --git a/Telegram/SourceFiles/data/data_drafts.cpp b/Telegram/SourceFiles/data/data_drafts.cpp index 99bdf5a0dc..c8374023c4 100644 --- a/Telegram/SourceFiles/data/data_drafts.cpp +++ b/Telegram/SourceFiles/data/data_drafts.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "mainwidget.h" #include "storage/localstorage.h" -#include "support/support_helper.h" namespace Data { namespace { @@ -66,17 +65,7 @@ void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { cloudDraft->date = draft.vdate.v; history->setCloudDraft(std::move(cloudDraft)); - history->createLocalDraftFromCloud(); - if (Auth().supportMode()) { - history->updateChatListEntry(); - Auth().supportHelper().cloudDraftChanged(history); - } else { - history->updateChatListSortPosition(); - } - - if (const auto main = App::main()) { - main->applyCloudDraft(history); - } + history->applyCloudDraft(); } void clearPeerCloudDraft(PeerId peerId, TimeId date) { @@ -86,18 +75,7 @@ void clearPeerCloudDraft(PeerId peerId, TimeId date) { } history->clearCloudDraft(); - history->clearLocalDraft(); - - if (Auth().supportMode()) { - history->updateChatListEntry(); - Auth().supportHelper().cloudDraftChanged(history); - } else { - history->updateChatListSortPosition(); - } - - if (auto main = App::main()) { - main->applyCloudDraft(history); - } + history->applyCloudDraft(); } } // namespace Data diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 0ae71cc5dc..cfcdebd9b4 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_components.h" #include "history/history_inner_widget.h" #include "dialogs/dialogs_indexed_list.h" -#include "styles/style_dialogs.h" #include "data/data_drafts.h" #include "data/data_session.h" #include "data/data_media_types.h" @@ -22,14 +21,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "mainwidget.h" #include "mainwindow.h" -#include "storage/localstorage.h" #include "observer_peer.h" #include "auth_session.h" #include "window/notifications_manager.h" #include "calls/calls_instance.h" +#include "storage/localstorage.h" #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" #include "storage/storage_feed_messages.h" +#include "support/support_helper.h" #include "data/data_channel_admins.h" #include "data/data_feed.h" #include "data/data_photo.h" @@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/text_options.h" #include "core/crash_reports.h" +#include "styles/style_dialogs.h" namespace { @@ -199,10 +200,11 @@ void History::takeLocalDraft(History *from) { } void History::createLocalDraftFromCloud() { - auto draft = cloudDraft(); - if (Data::draftIsNull(draft) - || !draft->date - || session().supportMode()) { + const auto draft = cloudDraft(); + if (!draft) { + clearLocalDraft(); + return; + } else if (Data::draftIsNull(draft) || !draft->date) { return; } @@ -303,6 +305,19 @@ void History::clearCloudDraft() { } } +void History::applyCloudDraft() { + if (session().supportMode()) { + updateChatListEntry(); + session().supportHelper().cloudDraftChanged(this); + } else { + createLocalDraftFromCloud(); + updateChatListSortPosition(); + if (const auto main = App::main()) { + main->applyCloudDraft(this); + } + } +} + void History::clearEditDraft() { _editDraft = nullptr; } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index e12879e1a8..50d0be452a 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -257,7 +257,6 @@ public: } void setLocalDraft(std::unique_ptr &&draft); void takeLocalDraft(History *from); - void createLocalDraftFromCloud(); void setCloudDraft(std::unique_ptr &&draft); Data::Draft *createCloudDraft(const Data::Draft *fromDraft); bool skipCloudDraft(const QString &text, MsgId replyTo, TimeId date) const; @@ -266,6 +265,7 @@ public: void setEditDraft(std::unique_ptr &&draft); void clearLocalDraft(); void clearCloudDraft(); + void applyCloudDraft(); void clearEditDraft(); void draftSavedToCloud(); Data::Draft *draft() { @@ -448,6 +448,8 @@ private: void viewReplaced(not_null was, Element *now); + void createLocalDraftFromCloud(); + not_null _owner; Flags _flags = 0; bool _mute = false; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 70f70ef10a..2acb4dff2b 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1464,6 +1464,8 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) { } void HistoryWidget::applyCloudDraft(History *history) { + Expects(!Auth().supportMode()); + if (_history == history && !_editMsgId) { applyDraft(Ui::InputField::HistoryAction::NewEntry);