From 52b921262575e79b38f1c83c4d63cdbf640a7288 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 24 Apr 2019 18:12:35 +0400 Subject: [PATCH] Display top bar in archive. --- Telegram/SourceFiles/data/data_session.cpp | 42 ++--- Telegram/SourceFiles/data/data_session.h | 4 +- .../dialogs/dialogs_inner_widget.cpp | 25 ++- .../dialogs/dialogs_inner_widget.h | 3 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 46 +++-- Telegram/SourceFiles/dialogs/dialogs_widget.h | 8 +- .../view/history_view_top_bar_widget.cpp | 162 ++++++++++-------- .../view/history_view_top_bar_widget.h | 2 +- Telegram/SourceFiles/mainwidget.cpp | 29 ++-- Telegram/SourceFiles/mainwidget.h | 1 - 10 files changed, 189 insertions(+), 133 deletions(-) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 88dd8b864e..c51530aceb 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1595,37 +1595,37 @@ bool Session::unreadBadgeMuted() const { state.chatsCountMuted); } -int Session::unreadBadgeIgnoreOne(History *history) const { - const auto removeCount = (history && history->inChatList()) - ? history->unreadCount() - : 0; - if (!removeCount) { +int Session::unreadBadgeIgnoreOne(const Dialogs::Key &key) const { + const auto remove = (key && key.entry()->inChatList()) + ? key.entry()->chatListUnreadState() + : Dialogs::UnreadState(); + if (remove.empty()) { return unreadBadge(); } const auto state = _chatsList.unreadState(); - const auto removeMuted = history->mute() - || (history->folder() != nullptr); return computeUnreadBadge( - state.messagesCount.value_or(0) - removeCount, - state.messagesCountMuted - (removeMuted ? removeCount : 0), - state.chatsCount - 1, - state.chatsCountMuted - (removeMuted ? 1 : 0)); + state.messagesCount.value_or(0) - remove.messagesCount.value_or(0), + state.messagesCountMuted - remove.messagesCountMuted, + state.chatsCount - remove.chatsCount, + state.chatsCountMuted - remove.chatsCountMuted); } -bool Session::unreadBadgeMutedIgnoreOne(History *history) const { - const auto removeCount = (history && history->inChatList()) - ? history->unreadCount() - : 0; - if (!removeCount) { +bool Session::unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const { + if (!_session->settings().includeMutedCounter()) { + return false; + } + const auto remove = (key && key.entry()->inChatList()) + ? key.entry()->chatListUnreadState() + : Dialogs::UnreadState(); + if (remove.empty()) { return unreadBadgeMuted(); } const auto state = _chatsList.unreadState(); - const auto removeMuted = history->mute(); return computeUnreadBadgeMuted( - state.messagesCount.value_or(0) - removeCount, - state.messagesCountMuted - (removeMuted ? removeCount : 0), - state.chatsCount - 1, - state.chatsCountMuted - (removeMuted ? 1 : 0)); + state.messagesCount.value_or(0) - remove.messagesCount.value_or(0), + state.messagesCountMuted - remove.messagesCountMuted, + state.chatsCount - remove.chatsCount, + state.chatsCountMuted - remove.chatsCountMuted); } int Session::unreadOnlyMutedBadge() const { diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 7d54156632..7390df1a3f 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -338,8 +338,8 @@ public: int unreadBadge() const; bool unreadBadgeMuted() const; - int unreadBadgeIgnoreOne(History *history) const; - bool unreadBadgeMutedIgnoreOne(History *history) const; + int unreadBadgeIgnoreOne(const Dialogs::Key &key) const; + bool unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const; int unreadOnlyMutedBadge() const; void unreadStateChanged( diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index c842690879..cba401244d 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -275,9 +275,15 @@ void InnerWidget::changeOpenedFolder(Data::Folder *folder) { return; } stopReorderPinned(); + //const auto mouseSelection = _mouseSelection; + //const auto lastMousePosition = _lastMousePosition; clearSelection(); _openedFolder = folder; refresh(); + // This doesn't work, because we clear selection in leaveEvent on hide. + //if (mouseSelection && lastMousePosition) { + // selectByMouse(*lastMousePosition); + //} if (_loadMoreCallback) { _loadMoreCallback(); } @@ -730,8 +736,6 @@ void InnerWidget::paintSearchInSaved( // paintSearchInFilter(p, paintUserpic, top, icon, text); //} // -void InnerWidget::activate() { -} void InnerWidget::mouseMoveEvent(QMouseEvent *e) { const auto globalPosition = e->globalPos(); @@ -1533,7 +1537,11 @@ void InnerWidget::clearSelection() { updateSelectedRow(); _importantSwitchSelected = false; _selected = nullptr; - _filteredSelected = _searchedSelected = _peerSearchSelected = _hashtagSelected = -1; + _filteredSelected + = _searchedSelected + = _peerSearchSelected + = _hashtagSelected + = -1; setCursor(style::cur_default); } } @@ -2389,18 +2397,7 @@ bool InnerWidget::chooseRow() { if (IsServerMsgId(chosen.message.fullId.msg)) { Local::saveRecentSearchHashtags(_filter); } - updateSelectedRow(); - _mouseSelection = false; - _lastMousePosition = std::nullopt; - _selected = nullptr; - _hashtagSelected - = _filteredSelected - = _peerSearchSelected - = _searchedSelected - = -1; - _chosenRow.fire_copy(chosen); - return true; } return false; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index b7d48823a7..075614998c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -69,7 +69,7 @@ public: const QVector &my, const QVector &result); - void activate(); + void clearSelection(); void changeOpenedFolder(Data::Folder *folder); void selectSkip(int32 direction); @@ -265,7 +265,6 @@ private: const Text &text) const; void refreshSearchInChatLabel(); - void clearSelection(); void clearSearchResults(bool clearPeerSearchResults = true); void updateSelectedRow(Key key = Key()); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index ae863fd026..28544b7cdc 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_entry.h" #include "history/history.h" //#include "history/feed/history_feed_section.h" // #feed +#include "history/view/history_view_top_bar_widget.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/wrap/fade_wrap.h" @@ -387,7 +388,9 @@ void Widget::updateControlsVisibility(bool fast) { _updateTelegram->show(); } _searchControls->setVisible(!_openedFolder); - if (!_openedFolder) { + if (_openedFolder) { + _folderTopBar->show(); + } else { if (hasFocus()) { _filter->setFocus(); _filter->finishAnimations(); @@ -410,6 +413,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) { _cacheUnder = grabForFolderSlideAnimation(); } _openedFolder = folder; + refreshFolderTopBar(); updateControlsVisibility(true); _inner->changeOpenedFolder(folder); if (animated == anim::type::normal) { @@ -420,6 +424,18 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) { } } +void Widget::refreshFolderTopBar() { + if (_openedFolder) { + if (!_folderTopBar) { + _folderTopBar.create(this, controller()); + updateControlsGeometry(); + } + _folderTopBar->setActiveChat(_openedFolder); + } else { + _folderTopBar.destroy(); + } +} + QPixmap Widget::grabForFolderSlideAnimation() { const auto hidden = _scrollToTop->isHidden(); if (!hidden) { @@ -464,13 +480,12 @@ void Widget::checkUpdateStatus() { updateControlsGeometry(); } -void Widget::activate() { +void Widget::setInnerFocus() { if (_openedFolder) { setFocus(); } else { _filter->setFocus(); } - _inner->activate(); } void Widget::refreshDialog(Key key) { @@ -563,6 +578,9 @@ void Widget::stopWidthAnimation() { } void Widget::showFast() { + if (isHidden()) { + _inner->clearSelection(); + } show(); updateForwardBar(); } @@ -574,8 +592,7 @@ void Widget::showAnimated(Window::SlideDirection direction, const Window::Sectio _a_show.stop(); _cacheUnder = params.oldContentCache; - show(); - updateForwardBar(); + showFast(); _cacheOver = App::main()->grabForShowAnimation(params); if (_updateTelegram) { @@ -591,6 +608,9 @@ void Widget::startSlideAnimation() { _forwardCancel->hide(); } _searchControls->hide(); + if (_folderTopBar) { + _folderTopBar->hide(); + } int delta = st::slideShift; if (_showDirection == Window::SlideDirection::FromLeft) { @@ -1372,6 +1392,9 @@ void Widget::updateControlsGeometry() { auto filterWidth = qMax(width(), st::columnMinimalWidthLeft) - filterLeft - filterRight; auto filterAreaHeight = st::dialogsFilterPadding.y() + _mainMenuToggle->height() + st::dialogsFilterPadding.y(); _searchControls->setGeometry(0, filterAreaTop, width(), filterAreaHeight); + if (_folderTopBar) { + _folderTopBar->setGeometry(_searchControls->geometry()); + } auto filterTop = (filterAreaHeight - _filter->height()) / 2; filterLeft = anim::interpolate(filterLeft, smallLayoutWidth, smallLayoutRatio); @@ -1474,16 +1497,17 @@ void Widget::paintEvent(QPaintEvent *e) { if (r != rect()) { p.setClipRect(r); } - auto progress = _a_show.value(1.); if (_a_show.animating()) { + const auto progress = _a_show.value(1.); const auto top = (_showAnimationType == ShowAnimation::Internal) ? (_forwardCancel ? _forwardCancel->height() : 0) : 0; - auto retina = cIntRetinaFactor(); - auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft); - auto coordUnder = fromLeft ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress); - auto coordOver = fromLeft ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); - auto shadow = fromLeft ? (1. - progress) : progress; + const auto shift = std::min(st::slideShift, width() / 2); + const auto retina = cIntRetinaFactor(); + const auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft); + const auto coordUnder = fromLeft ? anim::interpolate(-shift, 0, progress) : anim::interpolate(0, -shift, progress); + const auto coordOver = fromLeft ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); + const auto shadow = fromLeft ? (1. - progress) : progress; if (coordOver > 0) { p.drawPixmap(QRect(0, top, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height())); p.setOpacity(shadow); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index cd20691bb0..63bb4d47a0 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class AuthSession; +namespace HistoryView { +class TopBarWidget; +} // namespace HistoryView + namespace Ui { class IconButton; class PopupMenu; @@ -50,6 +54,7 @@ public: void updateDragInScroll(bool inScroll); void searchInChat(Key chat); + void setInnerFocus(); void refreshDialog(Key key); void removeDialog(Key key); @@ -88,7 +93,6 @@ public slots: void onCancel(); void onListScroll(); - void activate(); bool onCancelSearch(); void onCancelSearchInChat(); @@ -142,6 +146,7 @@ private: void updateJumpToDateVisibility(bool fast = false); void updateSearchFromVisibility(bool fast = false); void updateControlsGeometry(); + void refreshFolderTopBar(); void updateForwardBar(); void checkUpdateStatus(); void changeOpenedFolder(Data::Folder *folder, anim::type animated); @@ -167,6 +172,7 @@ private: object_ptr _forwardCancel = { nullptr }; object_ptr _searchControls; + object_ptr _folderTopBar = { nullptr } ; object_ptr _mainMenuToggle; object_ptr _filter; object_ptr> _chooseFromUser; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 8f762e0289..3835264a4c 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -81,13 +81,12 @@ TopBarWidget::TopBarWidget( ) | rpl::map([]( const std::tuple &previous, const std::tuple ¤t) { - auto active = std::get<0>(current); - auto search = std::get<1>(current); - auto activeChanged = (active != std::get<0>(previous)); - auto searchInChat - = search && (active == search); + const auto &active = std::get<0>(current); + const auto &search = std::get<1>(current); + const auto activeChanged = (active != std::get<0>(previous)); + const auto searchInChat = search && (active == search); return std::make_tuple(searchInChat, activeChanged); - }) | rpl::start_with_next([this]( + }) | rpl::start_with_next([=]( bool searchInActiveChat, bool activeChanged) { auto animated = activeChanged @@ -96,10 +95,8 @@ TopBarWidget::TopBarWidget( _search->setForceRippled(searchInActiveChat, animated); }, lifetime()); - subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); }); - if (Adaptive::OneColumn()) { - createUnreadBadge(); - } + subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); }); + refreshUnreadBadge(); { using AnimationUpdate = Data::Session::SendActionAnimationUpdate; Auth().data().sendActionAnimationUpdated( @@ -172,7 +169,9 @@ void TopBarWidget::refreshLang() { } void TopBarWidget::onSearch() { - if (_activeChat) { + if (_activeChat.folder()) { + _controller->closeFolder(); + } else if (_activeChat) { App::main()->searchInChat(_activeChat); } } @@ -190,27 +189,27 @@ void TopBarWidget::showMenu() { return; } _menu.create(parentWidget()); - _menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()] { + _menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()]{ menu->deleteLater(); if (weak && weak->_menu == menu) { weak->_menu = nullptr; weak->_menuToggle->setForceRippled(false); } - }); - _menu->setShowStartCallback(crl::guard(this, [this, menu = _menu.data()] { + }); + _menu->setShowStartCallback(crl::guard(this, [this, menu = _menu.data()]{ if (_menu == menu) { _menuToggle->setForceRippled(true); } - })); - _menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()] { + })); + _menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()]{ if (_menu == menu) { _menuToggle->setForceRippled(false); } - })); + })); _menuToggle->installEventFilter(_menu); const auto addAction = [&]( - const QString &text, - Fn callback) { + const QString & text, + Fn callback) { return _menu->addAction(text, std::move(callback)); }; if (const auto peer = _activeChat.peer()) { @@ -228,8 +227,12 @@ void TopBarWidget::showMenu() { } else { Unexpected("Empty active chat in TopBarWidget::showMenu."); } - _menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y()); - _menu->showAnimated(Ui::PanelAnimation::Origin::TopRight); + if (_menu->actions().empty()) { + _menu.destroy(); + } else { + _menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y()); + _menu->showAnimated(Ui::PanelAnimation::Origin::TopRight); + } } void TopBarWidget::toggleInfoSection() { @@ -297,7 +300,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { } void TopBarWidget::paintTopBar(Painter &p) { - if (!_activeChat.peer()) { // #feed + if (!_activeChat) { return; } auto nameleft = _leftTaken; @@ -308,8 +311,8 @@ void TopBarWidget::paintTopBar(Painter &p) { auto history = _activeChat.history(); p.setPen(st::dialogsNameFg); - /*if (const auto feed = _activeChat.feed()) { // #feed - auto text = feed->chatListName(); // TODO feed name emoji + if (const auto folder = _activeChat.folder()) { + auto text = folder->chatListName(); // TODO feed name emoji auto textWidth = st::historySavedFont->width(text); if (namewidth < textWidth) { text = st::historySavedFont->elided(text, namewidth); @@ -320,7 +323,7 @@ void TopBarWidget::paintTopBar(Painter &p) { (height() - st::historySavedFont->height) / 2, width(), text); - } else */if (_activeChat.peer()->isSelf()) { + } else if (_activeChat.peer()->isSelf()) { auto text = lang(lng_saved_messages); auto textWidth = st::historySavedFont->width(text); if (namewidth < textWidth) { @@ -411,8 +414,10 @@ void TopBarWidget::mousePressEvent(QMouseEvent *e) { } void TopBarWidget::infoClicked() { - if (!_activeChat.peer()) { + if (!_activeChat) { return; + } else if (_activeChat.folder()) { + _controller->closeFolder(); //} else if (const auto feed = _activeChat.feed()) { // #feed // _controller->showSection(Info::Memento( // feed, @@ -427,24 +432,30 @@ void TopBarWidget::infoClicked() { } void TopBarWidget::backClicked() { - _controller->showBackFromStack(); + if (_activeChat.folder()) { + _controller->closeFolder(); + } else { + _controller->showBackFromStack(); + } } void TopBarWidget::setActiveChat(Dialogs::Key chat) { - if (_activeChat != chat) { - _activeChat = chat; - _back->clearState(); - update(); - - updateUnreadBadge(); - refreshInfoButton(); - if (_menu) { - _menuToggle->removeEventFilter(_menu); - _menu->hideFast(); - } - updateOnlineDisplay(); - updateControlsVisibility(); + if (_activeChat == chat) { + return; } + _activeChat = chat; + _back->clearState(); + update(); + + updateUnreadBadge(); + refreshInfoButton(); + if (_menu) { + _menuToggle->removeEventFilter(_menu); + _menu->hideFast(); + } + updateOnlineDisplay(); + updateControlsVisibility(); + refreshUnreadBadge(); } void TopBarWidget::refreshInfoButton() { @@ -473,6 +484,9 @@ void TopBarWidget::refreshInfoButton() { void TopBarWidget::resizeEvent(QResizeEvent *e) { updateControlsGeometry(); + const auto smallDialogsColumn = _activeChat.folder() + && (width() < _back->width() + _search->width()); + _search->setVisible(!smallDialogsColumn); } int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) { @@ -502,18 +516,20 @@ void TopBarWidget::updateControlsGeometry() { _delete->moveToLeft(buttonsLeft, selectedButtonsTop); _clear->moveToRight(st::topBarActionSkip, selectedButtonsTop); - if (_unreadBadge) { - _unreadBadge->setGeometryToLeft( - 0, - otherButtonsTop + st::titleUnreadCounterTop, - _back->width(), - st::dialogsUnreadHeight); - } if (_back->isHidden()) { _leftTaken = st::topBarArrowPadding.right(); } else { - _leftTaken = 0; + const auto smallDialogsColumn = _activeChat.folder() + && (width() < _back->width() + _search->width()); + _leftTaken = smallDialogsColumn ? (width() - _back->width()) / 2 : 0; _back->moveToLeft(_leftTaken, otherButtonsTop); + if (_unreadBadge) { + _unreadBadge->setGeometryToLeft( + _leftTaken, + otherButtonsTop + st::titleUnreadCounterTop, + _back->width(), + st::dialogsUnreadHeight); + } _leftTaken += _back->width(); if (_info && !_info->isHidden()) { _info->moveToLeft(_leftTaken, otherButtonsTop); @@ -523,7 +539,11 @@ void TopBarWidget::updateControlsGeometry() { _rightTaken = 0; _menuToggle->moveToRight(_rightTaken, otherButtonsTop); - _rightTaken += _menuToggle->width() + st::topBarSkip; + if (_menuToggle->isHidden()) { + _rightTaken += (_menuToggle->width() - _search->width()); + } else { + _rightTaken += _menuToggle->width() + st::topBarSkip; + } _infoToggle->moveToRight(_rightTaken, otherButtonsTop); if (!_infoToggle->isHidden()) { _rightTaken += _infoToggle->width() + st::topBarSkip; @@ -560,7 +580,8 @@ void TopBarWidget::updateControlsVisibility() { _forward->setVisible(_canForward); auto backVisible = Adaptive::OneColumn() - || (App::main() && !App::main()->stackIsEmpty()); + || (App::main() && !App::main()->stackIsEmpty()) + || _activeChat.folder(); _back->setVisible(backVisible); if (_info) { _info->setVisible(Adaptive::OneColumn()); @@ -568,9 +589,12 @@ void TopBarWidget::updateControlsVisibility() { if (_unreadBadge) { _unreadBadge->show(); } - _search->show(); - _menuToggle->show(); - _infoToggle->setVisible(!Adaptive::OneColumn() + const auto smallDialogsColumn = _activeChat.folder() + && (width() < _back->width() + _search->width()); + _search->setVisible(!smallDialogsColumn); + _menuToggle->setVisible(!_activeChat.folder()); + _infoToggle->setVisible(!_activeChat.folder() + && !Adaptive::OneColumn() && _controller->canShowThirdSection()); const auto callsEnabled = [&] { if (const auto peer = _activeChat.peer()) { @@ -669,35 +693,39 @@ void TopBarWidget::selectedShowCallback() { void TopBarWidget::updateAdaptiveLayout() { updateControlsVisibility(); - if (Adaptive::OneColumn()) { - createUnreadBadge(); - } else if (_unreadBadge) { - unsubscribe(base::take(_unreadCounterSubscription)); - _unreadBadge.destroy(); - } updateInfoToggleActive(); + refreshUnreadBadge(); } -void TopBarWidget::createUnreadBadge() { - if (_unreadBadge) { +void TopBarWidget::refreshUnreadBadge() { + if (!Adaptive::OneColumn() && !_activeChat.folder()) { + if (_unreadBadge) { + unsubscribe(base::take(_unreadCounterSubscription)); + _unreadBadge.destroy(); + } + return; + } else if (_unreadBadge) { return; } _unreadBadge.create(this); - _unreadBadge->setGeometryToLeft(0, st::titleUnreadCounterTop, _back->width(), st::dialogsUnreadHeight); + _unreadBadge->setGeometryToLeft( + 0, + st::titleUnreadCounterTop, + _back->width(), + st::dialogsUnreadHeight); _unreadBadge->show(); _unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents); _unreadCounterSubscription = subscribe( Global::RefUnreadCounterUpdate(), - [this] { updateUnreadBadge(); }); + [=] { updateUnreadBadge(); }); updateUnreadBadge(); } void TopBarWidget::updateUnreadBadge() { if (!_unreadBadge) return; - const auto history = _activeChat.history(); - const auto active = !Auth().data().unreadBadgeMutedIgnoreOne(history); - const auto counter = Auth().data().unreadBadgeIgnoreOne(history); + const auto muted = Auth().data().unreadBadgeMutedIgnoreOne(_activeChat); + const auto counter = Auth().data().unreadBadgeIgnoreOne(_activeChat); const auto text = [&] { if (!counter) { return QString(); @@ -706,7 +734,7 @@ void TopBarWidget::updateUnreadBadge() { ? qsl("..%1").arg(counter % 100, 2, 10, QChar('0')) : QString::number(counter); }(); - _unreadBadge->setText(text, active); + _unreadBadge->setText(text, !muted); } void TopBarWidget::updateInfoToggleActive() { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index ffc662ab59..72647c1d7d 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -104,7 +104,7 @@ private: void infoClicked(); void backClicked(); - void createUnreadBadge(); + void refreshUnreadBadge(); void updateUnreadBadge(); not_null _controller; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 3a37e72db2..b782bf85a4 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -385,7 +385,9 @@ MainWidget::MainWidget( connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll())); - connect(_history, SIGNAL(cancelled()), _dialogs, SLOT(activate())); + connect(_history, &HistoryWidget::cancelled, [=] { + _dialogs->setInnerFocus(); + }); subscribe( Media::Player::instance()->updatedNotifier(), [=](const Media::Player::TrackState &state) { handleAudioUpdate(state); }); @@ -808,7 +810,7 @@ void MainWidget::hiderLayer(base::unique_qptr hider) { } else { _hider->show(); updateControlsGeometry(); - _dialogs->activate(); + _dialogs->setInnerFocus(); } floatPlayerCheckVisibility(); } @@ -900,10 +902,6 @@ bool MainWidget::selectingPeer() const { return _hider ? true : false; } -void MainWidget::dialogsActivate() { - _dialogs->activate(); -} - void MainWidget::removeDialog(Dialogs::Key key) { _dialogs->removeDialog(key); } @@ -1009,7 +1007,7 @@ void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) { if (Adaptive::OneColumn()) { Ui::showChatsList(); } else { - _dialogs->activate(); + _dialogs->setInnerFocus(); } } @@ -1462,7 +1460,7 @@ void MainWidget::setInnerFocus() { } else if (!_hider && _thirdSection) { _thirdSection->setInnerFocus(); } else { - dialogsActivate(); + _dialogs->setInnerFocus(); } } else if (_mainSection) { _mainSection->setInnerFocus(); @@ -1594,7 +1592,7 @@ void MainWidget::ui_showPeerHistory( bool back = (way == Way::Backward || !peerId); bool foundInStack = !peerId; if (foundInStack || (way == Way::ClearStack)) { - for_const (auto &item, _stack) { + for (const auto &item : _stack) { clearBotStartToken(item->peer()); } _stack.clear(); @@ -2047,7 +2045,9 @@ bool MainWidget::stackIsEmpty() const { void MainWidget::showBackFromStack( const SectionShow ¶ms) { - if (selectingPeer()) return; + if (selectingPeer()) { + return; + } if (_stack.empty()) { _controller->clearSectionStack(params); crl::on_main(App::wnd(), [] { @@ -2790,11 +2790,14 @@ int MainWidget::backgroundFromY() const { } void MainWidget::searchInChat(Dialogs::Key chat) { + if (_controller->openedFolder().current()) { + _controller->closeFolder(); + } _dialogs->searchInChat(chat); if (Adaptive::OneColumn()) { Ui::showChatsList(); } else { - _dialogs->activate(); + _dialogs->setInnerFocus(); } } @@ -3453,7 +3456,7 @@ void MainWidget::activate() { if (_a_show.animating()) return; if (!_mainSection) { if (_hider) { - _dialogs->activate(); + _dialogs->setInnerFocus(); } else if (App::wnd() && !Ui::isLayerShown()) { if (!cSendPaths().isEmpty()) { const auto interpret = qstr("interpret://"); @@ -3470,7 +3473,7 @@ void MainWidget::activate() { } else if (_history->peer()) { _history->activate(); } else { - _dialogs->activate(); + _dialogs->setInnerFocus(); } } } diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index b4e571f6a7..81c5145a8b 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -192,7 +192,6 @@ public: bool sendPaths(PeerId peerId); void onFilesOrForwardDrop(const PeerId &peer, const QMimeData *data); bool selectingPeer() const; - void dialogsActivate(); void deletePhotoLayer(PhotoData *photo);