Display top bar in archive.

This commit is contained in:
John Preston 2019-04-24 18:12:35 +04:00
parent f56df0e1d9
commit 52b9212625
10 changed files with 189 additions and 133 deletions

View File

@ -1595,37 +1595,37 @@ bool Session::unreadBadgeMuted() const {
state.chatsCountMuted); state.chatsCountMuted);
} }
int Session::unreadBadgeIgnoreOne(History *history) const { int Session::unreadBadgeIgnoreOne(const Dialogs::Key &key) const {
const auto removeCount = (history && history->inChatList()) const auto remove = (key && key.entry()->inChatList())
? history->unreadCount() ? key.entry()->chatListUnreadState()
: 0; : Dialogs::UnreadState();
if (!removeCount) { if (remove.empty()) {
return unreadBadge(); return unreadBadge();
} }
const auto state = _chatsList.unreadState(); const auto state = _chatsList.unreadState();
const auto removeMuted = history->mute()
|| (history->folder() != nullptr);
return computeUnreadBadge( return computeUnreadBadge(
state.messagesCount.value_or(0) - removeCount, state.messagesCount.value_or(0) - remove.messagesCount.value_or(0),
state.messagesCountMuted - (removeMuted ? removeCount : 0), state.messagesCountMuted - remove.messagesCountMuted,
state.chatsCount - 1, state.chatsCount - remove.chatsCount,
state.chatsCountMuted - (removeMuted ? 1 : 0)); state.chatsCountMuted - remove.chatsCountMuted);
} }
bool Session::unreadBadgeMutedIgnoreOne(History *history) const { bool Session::unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const {
const auto removeCount = (history && history->inChatList()) if (!_session->settings().includeMutedCounter()) {
? history->unreadCount() return false;
: 0; }
if (!removeCount) { const auto remove = (key && key.entry()->inChatList())
? key.entry()->chatListUnreadState()
: Dialogs::UnreadState();
if (remove.empty()) {
return unreadBadgeMuted(); return unreadBadgeMuted();
} }
const auto state = _chatsList.unreadState(); const auto state = _chatsList.unreadState();
const auto removeMuted = history->mute();
return computeUnreadBadgeMuted( return computeUnreadBadgeMuted(
state.messagesCount.value_or(0) - removeCount, state.messagesCount.value_or(0) - remove.messagesCount.value_or(0),
state.messagesCountMuted - (removeMuted ? removeCount : 0), state.messagesCountMuted - remove.messagesCountMuted,
state.chatsCount - 1, state.chatsCount - remove.chatsCount,
state.chatsCountMuted - (removeMuted ? 1 : 0)); state.chatsCountMuted - remove.chatsCountMuted);
} }
int Session::unreadOnlyMutedBadge() const { int Session::unreadOnlyMutedBadge() const {

View File

@ -338,8 +338,8 @@ public:
int unreadBadge() const; int unreadBadge() const;
bool unreadBadgeMuted() const; bool unreadBadgeMuted() const;
int unreadBadgeIgnoreOne(History *history) const; int unreadBadgeIgnoreOne(const Dialogs::Key &key) const;
bool unreadBadgeMutedIgnoreOne(History *history) const; bool unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const;
int unreadOnlyMutedBadge() const; int unreadOnlyMutedBadge() const;
void unreadStateChanged( void unreadStateChanged(

View File

@ -275,9 +275,15 @@ void InnerWidget::changeOpenedFolder(Data::Folder *folder) {
return; return;
} }
stopReorderPinned(); stopReorderPinned();
//const auto mouseSelection = _mouseSelection;
//const auto lastMousePosition = _lastMousePosition;
clearSelection(); clearSelection();
_openedFolder = folder; _openedFolder = folder;
refresh(); refresh();
// This doesn't work, because we clear selection in leaveEvent on hide.
//if (mouseSelection && lastMousePosition) {
// selectByMouse(*lastMousePosition);
//}
if (_loadMoreCallback) { if (_loadMoreCallback) {
_loadMoreCallback(); _loadMoreCallback();
} }
@ -730,8 +736,6 @@ void InnerWidget::paintSearchInSaved(
// paintSearchInFilter(p, paintUserpic, top, icon, text); // paintSearchInFilter(p, paintUserpic, top, icon, text);
//} //}
// //
void InnerWidget::activate() {
}
void InnerWidget::mouseMoveEvent(QMouseEvent *e) { void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
const auto globalPosition = e->globalPos(); const auto globalPosition = e->globalPos();
@ -1533,7 +1537,11 @@ void InnerWidget::clearSelection() {
updateSelectedRow(); updateSelectedRow();
_importantSwitchSelected = false; _importantSwitchSelected = false;
_selected = nullptr; _selected = nullptr;
_filteredSelected = _searchedSelected = _peerSearchSelected = _hashtagSelected = -1; _filteredSelected
= _searchedSelected
= _peerSearchSelected
= _hashtagSelected
= -1;
setCursor(style::cur_default); setCursor(style::cur_default);
} }
} }
@ -2389,18 +2397,7 @@ bool InnerWidget::chooseRow() {
if (IsServerMsgId(chosen.message.fullId.msg)) { if (IsServerMsgId(chosen.message.fullId.msg)) {
Local::saveRecentSearchHashtags(_filter); Local::saveRecentSearchHashtags(_filter);
} }
updateSelectedRow();
_mouseSelection = false;
_lastMousePosition = std::nullopt;
_selected = nullptr;
_hashtagSelected
= _filteredSelected
= _peerSearchSelected
= _searchedSelected
= -1;
_chosenRow.fire_copy(chosen); _chosenRow.fire_copy(chosen);
return true; return true;
} }
return false; return false;

View File

@ -69,7 +69,7 @@ public:
const QVector<MTPPeer> &my, const QVector<MTPPeer> &my,
const QVector<MTPPeer> &result); const QVector<MTPPeer> &result);
void activate(); void clearSelection();
void changeOpenedFolder(Data::Folder *folder); void changeOpenedFolder(Data::Folder *folder);
void selectSkip(int32 direction); void selectSkip(int32 direction);
@ -265,7 +265,6 @@ private:
const Text &text) const; const Text &text) const;
void refreshSearchInChatLabel(); void refreshSearchInChatLabel();
void clearSelection();
void clearSearchResults(bool clearPeerSearchResults = true); void clearSearchResults(bool clearPeerSearchResults = true);
void updateSelectedRow(Key key = Key()); void updateSelectedRow(Key key = Key());

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_entry.h" #include "dialogs/dialogs_entry.h"
#include "history/history.h" #include "history/history.h"
//#include "history/feed/history_feed_section.h" // #feed //#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/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"
@ -387,7 +388,9 @@ void Widget::updateControlsVisibility(bool fast) {
_updateTelegram->show(); _updateTelegram->show();
} }
_searchControls->setVisible(!_openedFolder); _searchControls->setVisible(!_openedFolder);
if (!_openedFolder) { if (_openedFolder) {
_folderTopBar->show();
} else {
if (hasFocus()) { if (hasFocus()) {
_filter->setFocus(); _filter->setFocus();
_filter->finishAnimations(); _filter->finishAnimations();
@ -410,6 +413,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) {
_cacheUnder = grabForFolderSlideAnimation(); _cacheUnder = grabForFolderSlideAnimation();
} }
_openedFolder = folder; _openedFolder = folder;
refreshFolderTopBar();
updateControlsVisibility(true); updateControlsVisibility(true);
_inner->changeOpenedFolder(folder); _inner->changeOpenedFolder(folder);
if (animated == anim::type::normal) { 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() { QPixmap Widget::grabForFolderSlideAnimation() {
const auto hidden = _scrollToTop->isHidden(); const auto hidden = _scrollToTop->isHidden();
if (!hidden) { if (!hidden) {
@ -464,13 +480,12 @@ void Widget::checkUpdateStatus() {
updateControlsGeometry(); updateControlsGeometry();
} }
void Widget::activate() { void Widget::setInnerFocus() {
if (_openedFolder) { if (_openedFolder) {
setFocus(); setFocus();
} else { } else {
_filter->setFocus(); _filter->setFocus();
} }
_inner->activate();
} }
void Widget::refreshDialog(Key key) { void Widget::refreshDialog(Key key) {
@ -563,6 +578,9 @@ void Widget::stopWidthAnimation() {
} }
void Widget::showFast() { void Widget::showFast() {
if (isHidden()) {
_inner->clearSelection();
}
show(); show();
updateForwardBar(); updateForwardBar();
} }
@ -574,8 +592,7 @@ void Widget::showAnimated(Window::SlideDirection direction, const Window::Sectio
_a_show.stop(); _a_show.stop();
_cacheUnder = params.oldContentCache; _cacheUnder = params.oldContentCache;
show(); showFast();
updateForwardBar();
_cacheOver = App::main()->grabForShowAnimation(params); _cacheOver = App::main()->grabForShowAnimation(params);
if (_updateTelegram) { if (_updateTelegram) {
@ -591,6 +608,9 @@ void Widget::startSlideAnimation() {
_forwardCancel->hide(); _forwardCancel->hide();
} }
_searchControls->hide(); _searchControls->hide();
if (_folderTopBar) {
_folderTopBar->hide();
}
int delta = st::slideShift; int delta = st::slideShift;
if (_showDirection == Window::SlideDirection::FromLeft) { if (_showDirection == Window::SlideDirection::FromLeft) {
@ -1372,6 +1392,9 @@ void Widget::updateControlsGeometry() {
auto filterWidth = qMax(width(), st::columnMinimalWidthLeft) - filterLeft - filterRight; auto filterWidth = qMax(width(), st::columnMinimalWidthLeft) - filterLeft - filterRight;
auto filterAreaHeight = st::dialogsFilterPadding.y() + _mainMenuToggle->height() + st::dialogsFilterPadding.y(); auto filterAreaHeight = st::dialogsFilterPadding.y() + _mainMenuToggle->height() + st::dialogsFilterPadding.y();
_searchControls->setGeometry(0, filterAreaTop, width(), filterAreaHeight); _searchControls->setGeometry(0, filterAreaTop, width(), filterAreaHeight);
if (_folderTopBar) {
_folderTopBar->setGeometry(_searchControls->geometry());
}
auto filterTop = (filterAreaHeight - _filter->height()) / 2; auto filterTop = (filterAreaHeight - _filter->height()) / 2;
filterLeft = anim::interpolate(filterLeft, smallLayoutWidth, smallLayoutRatio); filterLeft = anim::interpolate(filterLeft, smallLayoutWidth, smallLayoutRatio);
@ -1474,16 +1497,17 @@ void Widget::paintEvent(QPaintEvent *e) {
if (r != rect()) { if (r != rect()) {
p.setClipRect(r); p.setClipRect(r);
} }
auto progress = _a_show.value(1.);
if (_a_show.animating()) { if (_a_show.animating()) {
const auto progress = _a_show.value(1.);
const auto top = (_showAnimationType == ShowAnimation::Internal) const auto top = (_showAnimationType == ShowAnimation::Internal)
? (_forwardCancel ? _forwardCancel->height() : 0) ? (_forwardCancel ? _forwardCancel->height() : 0)
: 0; : 0;
auto retina = cIntRetinaFactor(); const auto shift = std::min(st::slideShift, width() / 2);
auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft); const auto retina = cIntRetinaFactor();
auto coordUnder = fromLeft ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress); const auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft);
auto coordOver = fromLeft ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); const auto coordUnder = fromLeft ? anim::interpolate(-shift, 0, progress) : anim::interpolate(0, -shift, progress);
auto shadow = fromLeft ? (1. - progress) : 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) { if (coordOver > 0) {
p.drawPixmap(QRect(0, top, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height())); p.drawPixmap(QRect(0, top, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
p.setOpacity(shadow); p.setOpacity(shadow);

View File

@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class AuthSession; class AuthSession;
namespace HistoryView {
class TopBarWidget;
} // namespace HistoryView
namespace Ui { namespace Ui {
class IconButton; class IconButton;
class PopupMenu; class PopupMenu;
@ -50,6 +54,7 @@ public:
void updateDragInScroll(bool inScroll); void updateDragInScroll(bool inScroll);
void searchInChat(Key chat); void searchInChat(Key chat);
void setInnerFocus();
void refreshDialog(Key key); void refreshDialog(Key key);
void removeDialog(Key key); void removeDialog(Key key);
@ -88,7 +93,6 @@ public slots:
void onCancel(); void onCancel();
void onListScroll(); void onListScroll();
void activate();
bool onCancelSearch(); bool onCancelSearch();
void onCancelSearchInChat(); void onCancelSearchInChat();
@ -142,6 +146,7 @@ private:
void updateJumpToDateVisibility(bool fast = false); void updateJumpToDateVisibility(bool fast = false);
void updateSearchFromVisibility(bool fast = false); void updateSearchFromVisibility(bool fast = false);
void updateControlsGeometry(); void updateControlsGeometry();
void refreshFolderTopBar();
void updateForwardBar(); void updateForwardBar();
void checkUpdateStatus(); void checkUpdateStatus();
void changeOpenedFolder(Data::Folder *folder, anim::type animated); void changeOpenedFolder(Data::Folder *folder, anim::type animated);
@ -167,6 +172,7 @@ private:
object_ptr<Ui::IconButton> _forwardCancel = { nullptr }; object_ptr<Ui::IconButton> _forwardCancel = { nullptr };
object_ptr<Ui::RpWidget> _searchControls; object_ptr<Ui::RpWidget> _searchControls;
object_ptr<HistoryView::TopBarWidget> _folderTopBar = { nullptr } ;
object_ptr<Ui::IconButton> _mainMenuToggle; object_ptr<Ui::IconButton> _mainMenuToggle;
object_ptr<Ui::FlatInput> _filter; object_ptr<Ui::FlatInput> _filter;
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser; object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser;

View File

@ -81,13 +81,12 @@ TopBarWidget::TopBarWidget(
) | rpl::map([]( ) | rpl::map([](
const std::tuple<Dialogs::Key, Dialogs::Key> &previous, const std::tuple<Dialogs::Key, Dialogs::Key> &previous,
const std::tuple<Dialogs::Key, Dialogs::Key> &current) { const std::tuple<Dialogs::Key, Dialogs::Key> &current) {
auto active = std::get<0>(current); const auto &active = std::get<0>(current);
auto search = std::get<1>(current); const auto &search = std::get<1>(current);
auto activeChanged = (active != std::get<0>(previous)); const auto activeChanged = (active != std::get<0>(previous));
auto searchInChat const auto searchInChat = search && (active == search);
= search && (active == search);
return std::make_tuple(searchInChat, activeChanged); return std::make_tuple(searchInChat, activeChanged);
}) | rpl::start_with_next([this]( }) | rpl::start_with_next([=](
bool searchInActiveChat, bool searchInActiveChat,
bool activeChanged) { bool activeChanged) {
auto animated = activeChanged auto animated = activeChanged
@ -96,10 +95,8 @@ TopBarWidget::TopBarWidget(
_search->setForceRippled(searchInActiveChat, animated); _search->setForceRippled(searchInActiveChat, animated);
}, lifetime()); }, lifetime());
subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); }); subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); });
if (Adaptive::OneColumn()) { refreshUnreadBadge();
createUnreadBadge();
}
{ {
using AnimationUpdate = Data::Session::SendActionAnimationUpdate; using AnimationUpdate = Data::Session::SendActionAnimationUpdate;
Auth().data().sendActionAnimationUpdated( Auth().data().sendActionAnimationUpdated(
@ -172,7 +169,9 @@ void TopBarWidget::refreshLang() {
} }
void TopBarWidget::onSearch() { void TopBarWidget::onSearch() {
if (_activeChat) { if (_activeChat.folder()) {
_controller->closeFolder();
} else if (_activeChat) {
App::main()->searchInChat(_activeChat); App::main()->searchInChat(_activeChat);
} }
} }
@ -190,27 +189,27 @@ void TopBarWidget::showMenu() {
return; return;
} }
_menu.create(parentWidget()); _menu.create(parentWidget());
_menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()] { _menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()]{
menu->deleteLater(); menu->deleteLater();
if (weak && weak->_menu == menu) { if (weak && weak->_menu == menu) {
weak->_menu = nullptr; weak->_menu = nullptr;
weak->_menuToggle->setForceRippled(false); 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) { if (_menu == menu) {
_menuToggle->setForceRippled(true); _menuToggle->setForceRippled(true);
} }
})); }));
_menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()] { _menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()]{
if (_menu == menu) { if (_menu == menu) {
_menuToggle->setForceRippled(false); _menuToggle->setForceRippled(false);
} }
})); }));
_menuToggle->installEventFilter(_menu); _menuToggle->installEventFilter(_menu);
const auto addAction = [&]( const auto addAction = [&](
const QString &text, const QString & text,
Fn<void()> callback) { Fn<void()> callback) {
return _menu->addAction(text, std::move(callback)); return _menu->addAction(text, std::move(callback));
}; };
if (const auto peer = _activeChat.peer()) { if (const auto peer = _activeChat.peer()) {
@ -228,8 +227,12 @@ void TopBarWidget::showMenu() {
} else { } else {
Unexpected("Empty active chat in TopBarWidget::showMenu."); Unexpected("Empty active chat in TopBarWidget::showMenu.");
} }
_menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y()); if (_menu->actions().empty()) {
_menu->showAnimated(Ui::PanelAnimation::Origin::TopRight); _menu.destroy();
} else {
_menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y());
_menu->showAnimated(Ui::PanelAnimation::Origin::TopRight);
}
} }
void TopBarWidget::toggleInfoSection() { void TopBarWidget::toggleInfoSection() {
@ -297,7 +300,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) {
} }
void TopBarWidget::paintTopBar(Painter &p) { void TopBarWidget::paintTopBar(Painter &p) {
if (!_activeChat.peer()) { // #feed if (!_activeChat) {
return; return;
} }
auto nameleft = _leftTaken; auto nameleft = _leftTaken;
@ -308,8 +311,8 @@ void TopBarWidget::paintTopBar(Painter &p) {
auto history = _activeChat.history(); auto history = _activeChat.history();
p.setPen(st::dialogsNameFg); p.setPen(st::dialogsNameFg);
/*if (const auto feed = _activeChat.feed()) { // #feed if (const auto folder = _activeChat.folder()) {
auto text = feed->chatListName(); // TODO feed name emoji auto text = folder->chatListName(); // TODO feed name emoji
auto textWidth = st::historySavedFont->width(text); auto textWidth = st::historySavedFont->width(text);
if (namewidth < textWidth) { if (namewidth < textWidth) {
text = st::historySavedFont->elided(text, namewidth); text = st::historySavedFont->elided(text, namewidth);
@ -320,7 +323,7 @@ void TopBarWidget::paintTopBar(Painter &p) {
(height() - st::historySavedFont->height) / 2, (height() - st::historySavedFont->height) / 2,
width(), width(),
text); text);
} else */if (_activeChat.peer()->isSelf()) { } else if (_activeChat.peer()->isSelf()) {
auto text = lang(lng_saved_messages); auto text = lang(lng_saved_messages);
auto textWidth = st::historySavedFont->width(text); auto textWidth = st::historySavedFont->width(text);
if (namewidth < textWidth) { if (namewidth < textWidth) {
@ -411,8 +414,10 @@ void TopBarWidget::mousePressEvent(QMouseEvent *e) {
} }
void TopBarWidget::infoClicked() { void TopBarWidget::infoClicked() {
if (!_activeChat.peer()) { if (!_activeChat) {
return; return;
} else if (_activeChat.folder()) {
_controller->closeFolder();
//} else if (const auto feed = _activeChat.feed()) { // #feed //} else if (const auto feed = _activeChat.feed()) { // #feed
// _controller->showSection(Info::Memento( // _controller->showSection(Info::Memento(
// feed, // feed,
@ -427,24 +432,30 @@ void TopBarWidget::infoClicked() {
} }
void TopBarWidget::backClicked() { void TopBarWidget::backClicked() {
_controller->showBackFromStack(); if (_activeChat.folder()) {
_controller->closeFolder();
} else {
_controller->showBackFromStack();
}
} }
void TopBarWidget::setActiveChat(Dialogs::Key chat) { void TopBarWidget::setActiveChat(Dialogs::Key chat) {
if (_activeChat != chat) { if (_activeChat == chat) {
_activeChat = chat; return;
_back->clearState();
update();
updateUnreadBadge();
refreshInfoButton();
if (_menu) {
_menuToggle->removeEventFilter(_menu);
_menu->hideFast();
}
updateOnlineDisplay();
updateControlsVisibility();
} }
_activeChat = chat;
_back->clearState();
update();
updateUnreadBadge();
refreshInfoButton();
if (_menu) {
_menuToggle->removeEventFilter(_menu);
_menu->hideFast();
}
updateOnlineDisplay();
updateControlsVisibility();
refreshUnreadBadge();
} }
void TopBarWidget::refreshInfoButton() { void TopBarWidget::refreshInfoButton() {
@ -473,6 +484,9 @@ void TopBarWidget::refreshInfoButton() {
void TopBarWidget::resizeEvent(QResizeEvent *e) { void TopBarWidget::resizeEvent(QResizeEvent *e) {
updateControlsGeometry(); updateControlsGeometry();
const auto smallDialogsColumn = _activeChat.folder()
&& (width() < _back->width() + _search->width());
_search->setVisible(!smallDialogsColumn);
} }
int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) { int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) {
@ -502,18 +516,20 @@ void TopBarWidget::updateControlsGeometry() {
_delete->moveToLeft(buttonsLeft, selectedButtonsTop); _delete->moveToLeft(buttonsLeft, selectedButtonsTop);
_clear->moveToRight(st::topBarActionSkip, selectedButtonsTop); _clear->moveToRight(st::topBarActionSkip, selectedButtonsTop);
if (_unreadBadge) {
_unreadBadge->setGeometryToLeft(
0,
otherButtonsTop + st::titleUnreadCounterTop,
_back->width(),
st::dialogsUnreadHeight);
}
if (_back->isHidden()) { if (_back->isHidden()) {
_leftTaken = st::topBarArrowPadding.right(); _leftTaken = st::topBarArrowPadding.right();
} else { } else {
_leftTaken = 0; const auto smallDialogsColumn = _activeChat.folder()
&& (width() < _back->width() + _search->width());
_leftTaken = smallDialogsColumn ? (width() - _back->width()) / 2 : 0;
_back->moveToLeft(_leftTaken, otherButtonsTop); _back->moveToLeft(_leftTaken, otherButtonsTop);
if (_unreadBadge) {
_unreadBadge->setGeometryToLeft(
_leftTaken,
otherButtonsTop + st::titleUnreadCounterTop,
_back->width(),
st::dialogsUnreadHeight);
}
_leftTaken += _back->width(); _leftTaken += _back->width();
if (_info && !_info->isHidden()) { if (_info && !_info->isHidden()) {
_info->moveToLeft(_leftTaken, otherButtonsTop); _info->moveToLeft(_leftTaken, otherButtonsTop);
@ -523,7 +539,11 @@ void TopBarWidget::updateControlsGeometry() {
_rightTaken = 0; _rightTaken = 0;
_menuToggle->moveToRight(_rightTaken, otherButtonsTop); _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); _infoToggle->moveToRight(_rightTaken, otherButtonsTop);
if (!_infoToggle->isHidden()) { if (!_infoToggle->isHidden()) {
_rightTaken += _infoToggle->width() + st::topBarSkip; _rightTaken += _infoToggle->width() + st::topBarSkip;
@ -560,7 +580,8 @@ void TopBarWidget::updateControlsVisibility() {
_forward->setVisible(_canForward); _forward->setVisible(_canForward);
auto backVisible = Adaptive::OneColumn() auto backVisible = Adaptive::OneColumn()
|| (App::main() && !App::main()->stackIsEmpty()); || (App::main() && !App::main()->stackIsEmpty())
|| _activeChat.folder();
_back->setVisible(backVisible); _back->setVisible(backVisible);
if (_info) { if (_info) {
_info->setVisible(Adaptive::OneColumn()); _info->setVisible(Adaptive::OneColumn());
@ -568,9 +589,12 @@ void TopBarWidget::updateControlsVisibility() {
if (_unreadBadge) { if (_unreadBadge) {
_unreadBadge->show(); _unreadBadge->show();
} }
_search->show(); const auto smallDialogsColumn = _activeChat.folder()
_menuToggle->show(); && (width() < _back->width() + _search->width());
_infoToggle->setVisible(!Adaptive::OneColumn() _search->setVisible(!smallDialogsColumn);
_menuToggle->setVisible(!_activeChat.folder());
_infoToggle->setVisible(!_activeChat.folder()
&& !Adaptive::OneColumn()
&& _controller->canShowThirdSection()); && _controller->canShowThirdSection());
const auto callsEnabled = [&] { const auto callsEnabled = [&] {
if (const auto peer = _activeChat.peer()) { if (const auto peer = _activeChat.peer()) {
@ -669,35 +693,39 @@ void TopBarWidget::selectedShowCallback() {
void TopBarWidget::updateAdaptiveLayout() { void TopBarWidget::updateAdaptiveLayout() {
updateControlsVisibility(); updateControlsVisibility();
if (Adaptive::OneColumn()) {
createUnreadBadge();
} else if (_unreadBadge) {
unsubscribe(base::take(_unreadCounterSubscription));
_unreadBadge.destroy();
}
updateInfoToggleActive(); updateInfoToggleActive();
refreshUnreadBadge();
} }
void TopBarWidget::createUnreadBadge() { void TopBarWidget::refreshUnreadBadge() {
if (_unreadBadge) { if (!Adaptive::OneColumn() && !_activeChat.folder()) {
if (_unreadBadge) {
unsubscribe(base::take(_unreadCounterSubscription));
_unreadBadge.destroy();
}
return;
} else if (_unreadBadge) {
return; return;
} }
_unreadBadge.create(this); _unreadBadge.create(this);
_unreadBadge->setGeometryToLeft(0, st::titleUnreadCounterTop, _back->width(), st::dialogsUnreadHeight); _unreadBadge->setGeometryToLeft(
0,
st::titleUnreadCounterTop,
_back->width(),
st::dialogsUnreadHeight);
_unreadBadge->show(); _unreadBadge->show();
_unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents); _unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents);
_unreadCounterSubscription = subscribe( _unreadCounterSubscription = subscribe(
Global::RefUnreadCounterUpdate(), Global::RefUnreadCounterUpdate(),
[this] { updateUnreadBadge(); }); [=] { updateUnreadBadge(); });
updateUnreadBadge(); updateUnreadBadge();
} }
void TopBarWidget::updateUnreadBadge() { void TopBarWidget::updateUnreadBadge() {
if (!_unreadBadge) return; if (!_unreadBadge) return;
const auto history = _activeChat.history(); const auto muted = Auth().data().unreadBadgeMutedIgnoreOne(_activeChat);
const auto active = !Auth().data().unreadBadgeMutedIgnoreOne(history); const auto counter = Auth().data().unreadBadgeIgnoreOne(_activeChat);
const auto counter = Auth().data().unreadBadgeIgnoreOne(history);
const auto text = [&] { const auto text = [&] {
if (!counter) { if (!counter) {
return QString(); return QString();
@ -706,7 +734,7 @@ void TopBarWidget::updateUnreadBadge() {
? qsl("..%1").arg(counter % 100, 2, 10, QChar('0')) ? qsl("..%1").arg(counter % 100, 2, 10, QChar('0'))
: QString::number(counter); : QString::number(counter);
}(); }();
_unreadBadge->setText(text, active); _unreadBadge->setText(text, !muted);
} }
void TopBarWidget::updateInfoToggleActive() { void TopBarWidget::updateInfoToggleActive() {

View File

@ -104,7 +104,7 @@ private:
void infoClicked(); void infoClicked();
void backClicked(); void backClicked();
void createUnreadBadge(); void refreshUnreadBadge();
void updateUnreadBadge(); void updateUnreadBadge();
not_null<Window::Controller*> _controller; not_null<Window::Controller*> _controller;

View File

@ -385,7 +385,9 @@ MainWidget::MainWidget(
connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll())); connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll()));
connect(_history, SIGNAL(cancelled()), _dialogs, SLOT(activate())); connect(_history, &HistoryWidget::cancelled, [=] {
_dialogs->setInnerFocus();
});
subscribe( subscribe(
Media::Player::instance()->updatedNotifier(), Media::Player::instance()->updatedNotifier(),
[=](const Media::Player::TrackState &state) { handleAudioUpdate(state); }); [=](const Media::Player::TrackState &state) { handleAudioUpdate(state); });
@ -808,7 +810,7 @@ void MainWidget::hiderLayer(base::unique_qptr<Window::HistoryHider> hider) {
} else { } else {
_hider->show(); _hider->show();
updateControlsGeometry(); updateControlsGeometry();
_dialogs->activate(); _dialogs->setInnerFocus();
} }
floatPlayerCheckVisibility(); floatPlayerCheckVisibility();
} }
@ -900,10 +902,6 @@ bool MainWidget::selectingPeer() const {
return _hider ? true : false; return _hider ? true : false;
} }
void MainWidget::dialogsActivate() {
_dialogs->activate();
}
void MainWidget::removeDialog(Dialogs::Key key) { void MainWidget::removeDialog(Dialogs::Key key) {
_dialogs->removeDialog(key); _dialogs->removeDialog(key);
} }
@ -1009,7 +1007,7 @@ void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) {
if (Adaptive::OneColumn()) { if (Adaptive::OneColumn()) {
Ui::showChatsList(); Ui::showChatsList();
} else { } else {
_dialogs->activate(); _dialogs->setInnerFocus();
} }
} }
@ -1462,7 +1460,7 @@ void MainWidget::setInnerFocus() {
} else if (!_hider && _thirdSection) { } else if (!_hider && _thirdSection) {
_thirdSection->setInnerFocus(); _thirdSection->setInnerFocus();
} else { } else {
dialogsActivate(); _dialogs->setInnerFocus();
} }
} else if (_mainSection) { } else if (_mainSection) {
_mainSection->setInnerFocus(); _mainSection->setInnerFocus();
@ -1594,7 +1592,7 @@ void MainWidget::ui_showPeerHistory(
bool back = (way == Way::Backward || !peerId); bool back = (way == Way::Backward || !peerId);
bool foundInStack = !peerId; bool foundInStack = !peerId;
if (foundInStack || (way == Way::ClearStack)) { if (foundInStack || (way == Way::ClearStack)) {
for_const (auto &item, _stack) { for (const auto &item : _stack) {
clearBotStartToken(item->peer()); clearBotStartToken(item->peer());
} }
_stack.clear(); _stack.clear();
@ -2047,7 +2045,9 @@ bool MainWidget::stackIsEmpty() const {
void MainWidget::showBackFromStack( void MainWidget::showBackFromStack(
const SectionShow &params) { const SectionShow &params) {
if (selectingPeer()) return; if (selectingPeer()) {
return;
}
if (_stack.empty()) { if (_stack.empty()) {
_controller->clearSectionStack(params); _controller->clearSectionStack(params);
crl::on_main(App::wnd(), [] { crl::on_main(App::wnd(), [] {
@ -2790,11 +2790,14 @@ int MainWidget::backgroundFromY() const {
} }
void MainWidget::searchInChat(Dialogs::Key chat) { void MainWidget::searchInChat(Dialogs::Key chat) {
if (_controller->openedFolder().current()) {
_controller->closeFolder();
}
_dialogs->searchInChat(chat); _dialogs->searchInChat(chat);
if (Adaptive::OneColumn()) { if (Adaptive::OneColumn()) {
Ui::showChatsList(); Ui::showChatsList();
} else { } else {
_dialogs->activate(); _dialogs->setInnerFocus();
} }
} }
@ -3453,7 +3456,7 @@ void MainWidget::activate() {
if (_a_show.animating()) return; if (_a_show.animating()) return;
if (!_mainSection) { if (!_mainSection) {
if (_hider) { if (_hider) {
_dialogs->activate(); _dialogs->setInnerFocus();
} else if (App::wnd() && !Ui::isLayerShown()) { } else if (App::wnd() && !Ui::isLayerShown()) {
if (!cSendPaths().isEmpty()) { if (!cSendPaths().isEmpty()) {
const auto interpret = qstr("interpret://"); const auto interpret = qstr("interpret://");
@ -3470,7 +3473,7 @@ void MainWidget::activate() {
} else if (_history->peer()) { } else if (_history->peer()) {
_history->activate(); _history->activate();
} else { } else {
_dialogs->activate(); _dialogs->setInnerFocus();
} }
} }
} }

View File

@ -192,7 +192,6 @@ public:
bool sendPaths(PeerId peerId); bool sendPaths(PeerId peerId);
void onFilesOrForwardDrop(const PeerId &peer, const QMimeData *data); void onFilesOrForwardDrop(const PeerId &peer, const QMimeData *data);
bool selectingPeer() const; bool selectingPeer() const;
void dialogsActivate();
void deletePhotoLayer(PhotoData *photo); void deletePhotoLayer(PhotoData *photo);