diff --git a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp index a6bd98d8e..c12a997dd 100644 --- a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp @@ -504,7 +504,9 @@ void ManageFiltersPrepare::SetupBox( continue; } const auto newId = ids.take(id).value_or(id); - const auto tl = removed ? MTPDialogFilter() : row.filter.tl(); + const auto tl = removed + ? MTPDialogFilter() + : row.filter.tl(newId); const auto request = MTPmessages_UpdateDialogFilter( MTP_flags(removed ? MTPmessages_UpdateDialogFilter::Flag(0) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 18f3bf4f2..124abd256 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -502,13 +502,6 @@ void Application::switchDebugMode() { } } -void Application::switchWorkMode() { - Global::SetDialogsFiltersEnabled(!Global::DialogsFiltersEnabled()); - Global::SetDialogsFilterId(0); - Local::writeUserSettings(); - App::restart(); -} - void Application::switchTestMode() { if (cTestMode()) { QFile(cWorkingDir() + qsl("tdata/withtestmode")).remove(); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index dd0b1a805..3bec6b4ae 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -214,7 +214,6 @@ public: void handleAppDeactivated(); void switchDebugMode(); - void switchWorkMode(); void switchTestMode(); void writeInstallBetaVersionsSetting(); diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index 048543fea..27efdf7a5 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -92,7 +92,7 @@ ChatFilter ChatFilter::FromTL( }); } -MTPDialogFilter ChatFilter::tl() const { +MTPDialogFilter ChatFilter::tl(FilterId replaceId) const { using TLFlag = MTPDdialogFilter::Flag; const auto flags = TLFlag(0) | ((_flags & Flag::Contacts) ? TLFlag::f_contacts : TLFlag(0)) @@ -124,7 +124,7 @@ MTPDialogFilter ChatFilter::tl() const { } return MTP_dialogFilter( MTP_flags(flags), - MTP_int(_id), + MTP_int(replaceId ? replaceId : _id), MTP_string(_title), MTPstring(), // emoticon MTP_vector(pinned), diff --git a/Telegram/SourceFiles/data/data_chat_filters.h b/Telegram/SourceFiles/data/data_chat_filters.h index ec7f19fbb..051afa9da 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.h +++ b/Telegram/SourceFiles/data/data_chat_filters.h @@ -49,7 +49,7 @@ public: [[nodiscard]] static ChatFilter FromTL( const MTPDialogFilter &data, not_null owner); - [[nodiscard]] MTPDialogFilter tl() const; + [[nodiscard]] MTPDialogFilter tl(FilterId replaceId = 0) const; [[nodiscard]] FilterId id() const; [[nodiscard]] QString title() const; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 602793c6b..caabc4e53 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2546,11 +2546,11 @@ bool InnerWidget::chooseCollapsedRow() { void InnerWidget::switchToFilter(FilterId filterId) { clearSelection(); - if (!Global::DialogsFiltersEnabled() - || !ranges::contains( - session().data().chatsFilters().list(), - filterId, - &Data::ChatFilter::id)) { + const auto found = ranges::contains( + session().data().chatsFilters().list(), + filterId, + &Data::ChatFilter::id); + if (!found) { filterId = 0; } stopReorderPinned(); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index d4c9211fb..685766d11 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -311,7 +311,6 @@ struct Data { base::Observable AdaptiveChanged; bool DialogsFiltersEnabled = false; - FilterId DialogsFilterId = 0; bool ModerateModeEnabled = false; bool ScreenIsLocked = false; @@ -441,7 +440,6 @@ DefineVar(Global, bool, AdaptiveForWide); DefineRefVar(Global, base::Observable, AdaptiveChanged); DefineVar(Global, bool, DialogsFiltersEnabled); -DefineVar(Global, FilterId, DialogsFilterId); DefineVar(Global, bool, ModerateModeEnabled); DefineVar(Global, bool, ScreenIsLocked); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 1a76f42ca..fd598df9f 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -150,7 +150,6 @@ DeclareVar(bool, AdaptiveForWide); DeclareRefVar(base::Observable, AdaptiveChanged); DeclareVar(bool, DialogsFiltersEnabled); -DeclareVar(FilterId, DialogsFilterId); DeclareVar(bool, ModerateModeEnabled); DeclareVar(bool, ScreenIsLocked); diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index b86179618..3cc2896f1 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -69,12 +69,6 @@ auto GenerateCodes() { codes.emplace(qsl("crashplease"), [](::Main::Session *session) { Unexpected("Crashed in Settings!"); }); - codes.emplace(qsl("workmode"), [](::Main::Session *session) { - auto text = Global::DialogsFiltersEnabled() ? qsl("Disable filters?") : qsl("Enable filters?"); - Ui::show(Box(text, [] { - Core::App().switchWorkMode(); - })); - }); codes.emplace(qsl("moderate"), [](::Main::Session *session) { auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?"); Ui::show(Box(text, [] { diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 7fb7c92e1..5d4d1b71b 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -613,7 +613,7 @@ enum { dbiHiddenPinnedMessages = 0x39, dbiRecentEmoji = 0x3a, dbiEmojiVariants = 0x3b, - dbiDialogsFilters = 0x40, + dbiDialogsModeOld = 0x40, dbiModerateMode = 0x41, dbiVideoVolume = 0x42, dbiStickersRecentLimit = 0x43, @@ -644,6 +644,7 @@ enum { dbiCacheSettings = 0x5c, dbiTxtDomainString = 0x5d, dbiApplicationSettings = 0x5e, + dbiDialogsFilters = 0x5f, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, @@ -1167,10 +1168,16 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting } } break; - case dbiDialogsFilters: { + case dbiDialogsModeOld: { qint32 enabled, modeInt; stream >> enabled >> modeInt; if (!_checkStreamStatus(stream)) return false; + } break; + + case dbiDialogsFilters: { + qint32 enabled; + stream >> enabled; + if (!_checkStreamStatus(stream)) return false; Global::SetDialogsFiltersEnabled(enabled == 1); } break; @@ -2091,7 +2098,7 @@ void _writeUserSettings() { : QByteArray(); auto callSettings = serializeCallSettings(); - uint32 size = 23 * (sizeof(quint32) + sizeof(qint32)); + uint32 size = 24 * (sizeof(quint32) + sizeof(qint32)); size += sizeof(quint32) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); size += sizeof(quint32) + sizeof(qint32); @@ -2104,7 +2111,6 @@ void _writeUserSettings() { size += sizeof(quint32) + Serialize::stringSize(cDialogLastPath()); size += sizeof(quint32) + 3 * sizeof(qint32); size += sizeof(quint32) + 2 * sizeof(qint32); - size += sizeof(quint32) + 2 * sizeof(qint32); size += sizeof(quint32) + sizeof(qint64) + sizeof(qint32); if (!Global::HiddenPinnedMessages().isEmpty()) { size += sizeof(quint32) + sizeof(qint32) + Global::HiddenPinnedMessages().size() * (sizeof(PeerId) + sizeof(MsgId)); @@ -2132,7 +2138,7 @@ void _writeUserSettings() { data.stream << quint32(dbiDialogLastPath) << cDialogLastPath(); data.stream << quint32(dbiSongVolume) << qint32(qRound(Global::SongVolume() * 1e6)); data.stream << quint32(dbiVideoVolume) << qint32(qRound(Global::VideoVolume() * 1e6)); - data.stream << quint32(dbiDialogsFilters) << qint32(Global::DialogsFiltersEnabled() ? 1 : 0) << static_cast(Global::DialogsFilterId()); + data.stream << quint32(dbiDialogsFilters) << qint32(Global::DialogsFiltersEnabled() ? 1 : 0); data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); data.stream << quint32(dbiCacheSettings) << qint64(_cacheTotalSizeLimit) << qint32(_cacheTotalTimeLimit) << qint64(_cacheBigFileTotalSizeLimit) << qint32(_cacheBigFileTotalTimeLimit); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index b754c9a2f..ea4726060 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -28,7 +28,7 @@ Controller::Controller(not_null account) : _account(account) , _widget(this) { _account->sessionValue( - ) | rpl::start_with_next([=](Main::Session *session) { + ) | rpl::start_with_next([=](Main::Session *session) { _sessionController = session ? std::make_unique(session, this) : nullptr; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index ad4df58b6..8d8d8e8f1 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_folder.h" #include "data/data_channel.h" #include "data/data_chat.h" +#include "data/data_chat_filters.h" #include "passport/passport_form_controller.h" #include "chat_helpers/tabbed_selector.h" #include "core/shortcuts.h" @@ -135,6 +136,13 @@ SessionController::SessionController( folder->updateChatListSortPosition(); closeFolder(); }, lifetime()); + + session->data().chatsFilters().changed( + ) | rpl::start_with_next([=] { + crl::on_main(session, [=] { + refreshFiltersMenu(); + }); + }, session->lifetime()); } not_null<::MainWindow*> SessionController::widget() const { @@ -203,6 +211,15 @@ void SessionController::toggleFiltersMenu(bool enabled) { _window->sideBarChanged(); } +void SessionController::refreshFiltersMenu() { + const auto enabled = !session().data().chatsFilters().list().empty(); + if (enabled != Global::DialogsFiltersEnabled()) { + Global::SetDialogsFiltersEnabled(enabled); + session().saveSettingsDelayed(); + toggleFiltersMenu(enabled); + } +} + bool SessionController::uniqueChatsInSearchResults() const { return session().supportMode() && !session().settings().supportAllSearchResults() diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 8568b7b23..0a8adafa0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -299,6 +299,7 @@ public: void setActiveChatsFilter(FilterId id); void toggleFiltersMenu(bool enabled); + void refreshFiltersMenu(); rpl::lifetime &lifetime() { return _lifetime;