From 66c0d51f96929d97e39ac5998bc11049bbffa42e Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 16 Mar 2020 16:12:40 +0400 Subject: [PATCH] Show unread badges in filters. --- .../SourceFiles/data/data_chat_filters.cpp | 11 +++++++++-- .../SourceFiles/dialogs/dialogs_main_list.cpp | 3 ++- Telegram/SourceFiles/window/window.style | 6 +++++- .../SourceFiles/window/window_filters_menu.cpp | 18 +++++++++++++++++- Telegram/lib_ui | 2 +- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index 6e6fc98d4f..97beb7e81f 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -160,8 +160,15 @@ bool ChatFilter::contains(not_null history) const { } return false || ((_flags & flag) - && (!(_flags & Flag::NoMuted) || !history->mute()) - && (!(_flags & Flag::NoRead) || history->unreadCountForBadge()) + && (!(_flags & Flag::NoMuted) + || !history->mute() + || (history->hasUnreadMentions() + && history->folderKnown() + && !history->folder())) + && (!(_flags & Flag::NoRead) + || history->unreadCount() + || history->unreadMark() + || history->hasUnreadMentions()) && (!(_flags & Flag::NoArchived) || (history->folderKnown() && !history->folder()))) || _always.contains(history); diff --git a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp index f1e54e9573..d24dcf722f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp @@ -106,8 +106,9 @@ void MainList::recomputeFullListSize() { void MainList::unreadStateChanged( const UnreadState &wasState, const UnreadState &nowState) { + const auto useClouded = _cloudUnreadState.known && !loaded(); const auto updateCloudUnread = _cloudUnreadState.known && wasState.known; - const auto notify = loaded() || updateCloudUnread; + const auto notify = !useClouded || wasState.known; const auto notifier = unreadStateChangeNotifier(notify); _unreadState += nowState - wasState; if (updateCloudUnread) { diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index 79ca9003de..2800c0832a 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -255,8 +255,12 @@ windowFiltersButton: SideBarButton(defaultSideBarButton) { font: font(11px semibold); } badgeStyle: TextStyle(defaultTextStyle) { - font: font(11px semibold); + font: font(12px semibold); } + badgeSkip: 4px; + badgeHeight: 17px; + badgeStroke: 2px; + badgePosition: point(5px, 7px); iconPosition: point(-1px, 6px); } windowFiltersMainMenu: SideBarButton(windowFiltersButton) { diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 1ab31de89b..d9045a768b 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -173,7 +173,23 @@ void FiltersMenu::refresh() { _container, title, st))); - button->setBadge(badge); + if (id > 0) { + const auto list = filters->chatsList(id); + rpl::single(rpl::empty_value()) | rpl::then( + list->unreadStateChanges( + ) | rpl::map([] { return rpl::empty_value(); }) + ) | rpl::start_with_next([=, raw = button.get()] { + const auto &state = list->unreadState(); + const auto count = (state.chats + state.marks); + const auto muted = (state.chatsMuted + state.marksMuted); + const auto string = !count + ? QString() + : (count > 99) + ? "..." + : QString::number(count); + raw->setBadge(string, count == muted); + }, button->lifetime()); + } button->setActive(_session->activeChatsFilterCurrent() == id); button->setClickedCallback([=] { if (id >= 0) { diff --git a/Telegram/lib_ui b/Telegram/lib_ui index d2611d7e85..4b6b328130 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit d2611d7e8588759c9ecc129ce70ef0d7b2e24d6c +Subproject commit 4b6b328130d74e5c5b7de6d41603650f29277ad4