From ee3e9af63a8ba995fe433a75557e331db8724382 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Feb 2020 18:16:42 +0400 Subject: [PATCH] Remove counter from unread bar. --- Telegram/Resources/langs/lang.strings | 2 +- Telegram/SourceFiles/history/history.cpp | 25 ++--------- Telegram/SourceFiles/history/history.h | 1 - .../SourceFiles/history/history_widget.cpp | 7 ++- .../history/view/history_view_element.cpp | 45 ++++++------------- .../history/view/history_view_element.h | 20 +-------- .../history/view/history_view_list_widget.cpp | 11 ++--- 7 files changed, 26 insertions(+), 85 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5578b330e..b15250cf7 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1369,7 +1369,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_user_action_upload_file" = "{user} is sending a file"; "lng_unread_bar#one" = "{count} unread message"; "lng_unread_bar#other" = "{count} unread messages"; -//"lng_unread_bar_some" = "Unread messages"; +"lng_unread_bar_some" = "Unread messages"; "lng_maps_point" = "Location"; "lng_save_photo" = "Save image"; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index d0c953fe3..69a7d57fe 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1367,8 +1367,8 @@ HistoryBlock *History::prepareBlockForAddingItem() { } void History::viewReplaced(not_null was, Element *now) { - if (scrollTopItem == was) scrollTopItem= now; - if (_firstUnreadView == was) _firstUnreadView= now; + if (scrollTopItem == was) scrollTopItem = now; + if (_firstUnreadView == was) _firstUnreadView = now; if (_unreadBarView == was) _unreadBarView = now; } @@ -1803,14 +1803,6 @@ void History::setUnreadCount(int newUnreadCount) { calculateFirstUnreadMessage(); } } - if (_unreadBarView) { - const auto count = chatListUnreadCount(); - if (count > 0) { - _unreadBarView->setUnreadBarCount(count); - } else { - _unreadBarView->setUnreadBarFreezed(); - } - } Notify::peerUpdatedDelayed( peer, Notify::PeerUpdate::Flag::UnreadViewChanged); @@ -2064,7 +2056,7 @@ void History::addUnreadBar() { } if (const auto count = chatListUnreadCount()) { _unreadBarView = _firstUnreadView; - _unreadBarView->setUnreadBarCount(count); + _unreadBarView->createUnreadBar(); } } @@ -2074,17 +2066,6 @@ void History::destroyUnreadBar() { } } -bool History::hasNotFreezedUnreadBar() const { - if (_firstUnreadView) { - if (const auto view = _unreadBarView) { - if (const auto bar = view->Get()) { - return !bar->freezed; - } - } - } - return false; -} - void History::unsetFirstUnreadMessage() { _firstUnreadView = nullptr; } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 5ea915201..2abe674ed 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -205,7 +205,6 @@ public: bool changeMute(bool newMute); void addUnreadBar(); void destroyUnreadBar(); - [[nodiscard]] bool hasNotFreezedUnreadBar() const; [[nodiscard]] Element *unreadBar() const; void calculateFirstUnreadMessage(); void unsetFirstUnreadMessage(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8f6a1c2d7..cbaae0148 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2389,7 +2389,7 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages _preloadDownRequest = 0; preloadHistoryIfNeeded(); if (_history->loadedAtBottom()) { - App::wnd()->checkHistoryActivation(); + checkHistoryActivation(); } } else if (_firstLoadRequest == requestId) { if (toMigrated) { @@ -3138,7 +3138,7 @@ void HistoryWidget::doneShow() { handlePendingHistoryUpdate(); } preloadHistoryIfNeeded(); - App::wnd()->checkHistoryActivation(); + checkHistoryActivation(); App::wnd()->setInnerFocus(); } @@ -4986,7 +4986,6 @@ int HistoryWidget::countAutomaticScrollTop() { if (history->unreadBar() != nullptr) { setMsgId(ShowAtUnreadMsgId); result = countInitialScrollTop(); - App::wnd()->checkHistoryActivation(); if (session().supportMode()) { history->unsetFirstUnreadMessage(); } @@ -5109,7 +5108,7 @@ void HistoryWidget::updateHistoryGeometry( _historyInited = true; _scrollToAnimation.stop(); } - auto newScrollTop = initial + const auto newScrollTop = initial ? countInitialScrollTop() : countAutomaticScrollTop(); if (_scroll->scrollTop() == newScrollTop) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 96a84ecaa..4a287222d 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -127,14 +127,8 @@ TextSelection ShiftItemSelection( return ShiftItemSelection(selection, byText.length()); } -void UnreadBar::init(int newCount) { - if (freezed) { - return; - } - count = newCount; - text = /*(count == kCountUnknown) // #feed - ? tr::lng_unread_bar_some(tr::now) - : */tr::lng_unread_bar(tr::now, lt_count, count); +void UnreadBar::init() { + text = tr::lng_unread_bar_some(tr::now); width = st::semiboldFont->width(text); } @@ -416,6 +410,18 @@ bool Element::computeIsAttachToPrevious(not_null previous) { return false; } +void Element::createUnreadBar() { + if (!AddComponents(UnreadBar::Bit())) { + return; + } + const auto bar = Get(); + bar->init(); + if (data()->mainView() == this) { + recountAttachToPreviousInBlocks(); + } + history()->owner().requestViewResize(this); +} + void Element::destroyUnreadBar() { if (!Has()) { return; @@ -427,29 +433,6 @@ void Element::destroyUnreadBar() { } } -void Element::setUnreadBarCount(int count) { - const auto changed = AddComponents(UnreadBar::Bit()); - const auto bar = Get(); - if (bar->freezed) { - return; - } - bar->init(count); - if (changed) { - if (data()->mainView() == this) { - recountAttachToPreviousInBlocks(); - } - history()->owner().requestViewResize(this); - } else { - history()->owner().requestViewRepaint(this); - } -} - -void Element::setUnreadBarFreezed() { - if (const auto bar = Get()) { - bar->freezed = true; - } -} - int Element::displayedDateHeight() const { if (auto date = Get()) { return date->height(); diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 41bbd4feb..734ba8a79 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -96,26 +96,15 @@ TextSelection ShiftItemSelection( // Any HistoryView::Element can have this Component for // displaying the unread messages bar above the message. struct UnreadBar : public RuntimeComponent { - void init(int newCount); + void init(); static int height(); static int marginTop(); void paint(Painter &p, int y, int w) const; - static constexpr auto kCountUnknown = std::numeric_limits::max(); - QString text; int width = 0; - int count = 0; - - // If unread bar is freezed the new messages do not - // increment the counter displayed by this bar. - // - // It happens when we've opened the conversation and - // we've seen the bar and new messages are marked as read - // as soon as they are added to the chat history. - bool freezed = false; }; @@ -192,14 +181,9 @@ public: bool computeIsAttachToPrevious(not_null previous); - void setUnreadBarCount(int count); + void createUnreadBar(); void destroyUnreadBar(); - // marks the unread bar as freezed so that unread - // messages count will not change for this bar - // when the new messages arrive in this chat history - void setUnreadBarFreezed(); - int displayedDateHeight() const; bool displayDate() const; bool isInOneDayWithPrevious() const; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index c5f449cf7..cf0bb871a 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -462,7 +462,7 @@ void ListWidget::checkUnreadBarCreation() { if (!_unreadBarElement) { if (const auto index = _delegate->listUnreadBarView(_items)) { _unreadBarElement = _items[*index].get(); - _unreadBarElement->setUnreadBarCount(UnreadBar::kCountUnknown); + _unreadBarElement->createUnreadBar(); refreshAttachmentsAtIndex(*index); } } @@ -2497,14 +2497,9 @@ void ListWidget::viewReplaced(not_null was, Element *now) { if (_overElement == was) _overElement = now; if (_unreadBarElement == was) { const auto bar = _unreadBarElement->Get(); - const auto count = bar ? bar->count : 0; - const auto freezed = bar ? bar->freezed : false; _unreadBarElement = now; - if (now && count) { - _unreadBarElement->setUnreadBarCount(count); - if (freezed) { - _unreadBarElement->setUnreadBarFreezed(); - } + if (now && bar) { + _unreadBarElement->createUnreadBar(); } } }