diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 657e0165d..b606be053 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -40,6 +40,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Window { namespace { +[[nodiscard]] Dialogs::UnreadState MainListMapUnreadState( + not_null session, + const Dialogs::UnreadState &state) { + const auto folderId = Data::Folder::kId; + if (const auto folder = session->data().folderLoaded(folderId)) { + return state - folder->chatsList()->unreadState(); + } + return state; +} + [[nodiscard]] rpl::producer MainListUnreadState( not_null list) { return rpl::single(rpl::empty) | rpl::then( @@ -59,11 +69,7 @@ namespace { return MainListUnreadState( session->data().chatsList() ) | rpl::map([=](const Dialogs::UnreadState &state) { - const auto folderId = Data::Folder::kId; - if (const auto folder = session->data().folderLoaded(folderId)) { - return state - folder->chatsList()->unreadState(); - } - return state; + return MainListMapUnreadState(session, state); }); } @@ -331,7 +337,7 @@ base::unique_qptr FiltersMenu::prepareButton( raw->setAcceptDrops(true); raw->events( ) | rpl::filter([=](not_null e) { - return ((e->type() == QEvent::ContextMenu) && (id > 0)) + return ((e->type() == QEvent::ContextMenu) && (id >= 0)) || e->type() == QEvent::DragEnter || e->type() == QEvent::DragMove || e->type() == QEvent::DragLeave; @@ -368,7 +374,7 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) { return; } const auto i = _filters.find(id); - if (i == end(_filters)) { + if ((i == end(_filters)) && id) { return; } _popupMenu = base::make_unique_q( @@ -382,23 +388,41 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) { args.icon); }); - addAction( - tr::lng_filters_context_edit(tr::now), - [=] { showEditBox(id); }, - &st::menuIconEdit); + if (id) { + addAction( + tr::lng_filters_context_edit(tr::now), + [=] { showEditBox(id); }, + &st::menuIconEdit); - auto filteredChats = [=] { - return _session->session().data().chatsFilters().chatsList(id); - }; - Window::MenuAddMarkAsReadChatListAction( - _session, - std::move(filteredChats), - addAction); + auto filteredChats = [=] { + return _session->session().data().chatsFilters().chatsList(id); + }; + Window::MenuAddMarkAsReadChatListAction( + _session, + std::move(filteredChats), + addAction); - addAction( - tr::lng_filters_context_remove(tr::now), - [=] { showRemoveBox(id); }, - &st::menuIconDelete); + addAction( + tr::lng_filters_context_remove(tr::now), + [=] { showRemoveBox(id); }, + &st::menuIconDelete); + } else { + auto customUnreadState = [=] { + const auto session = &_session->session(); + return MainListMapUnreadState( + session, + session->data().chatsList()->unreadState()); + }; + Window::MenuAddMarkAsReadChatListAction( + _session, + [=] { return _session->session().data().chatsList(); }, + addAction, + std::move(customUnreadState)); + } + if (_popupMenu->empty()) { + _popupMenu = nullptr; + return; + } _popupMenu->popup(position); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 7b908dc47..9098b9112 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2299,9 +2299,12 @@ void MenuAddMarkAsReadAllChatsAction( void MenuAddMarkAsReadChatListAction( not_null controller, Fn()> &&list, - const PeerMenuCallback &addAction) { + const PeerMenuCallback &addAction, + Fn customUnreadState) { // There is no async to make weak from controller. - const auto unreadState = list()->unreadState(); + const auto unreadState = customUnreadState + ? customUnreadState() + : list()->unreadState(); if (!unreadState.messages && !unreadState.marks && !unreadState.chats) { return; } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index 7fde1f407..d5808fbf5 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -32,6 +32,7 @@ class Thread; namespace Dialogs { class MainList; struct EntryState; +struct UnreadState; } // namespace Dialogs namespace ChatHelpers { @@ -69,7 +70,8 @@ void MenuAddMarkAsReadAllChatsAction( void MenuAddMarkAsReadChatListAction( not_null controller, Fn()> &&list, - const PeerMenuCallback &addAction); + const PeerMenuCallback &addAction, + Fn customUnreadState = nullptr); void PeerMenuExportChat(not_null peer); void PeerMenuDeleteContact(