diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index 8d580abf4..e143d1439 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -380,13 +380,6 @@ void Entry::updateChatListEntryPostponed() { } void Entry::updateChatListEntryHeight() { - auto &filters = _owner->chatsFilters(); - for (auto &[filterId, rows] : _chatListLinks) { - const auto list = filterId - ? filters.chatsList(filterId) - : _owner->chatsList(folder()); - list->updateEntryHeight(rows); - } session().changes().entryUpdated(this, Data::EntryUpdate::Flag::Height); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp index 7d480946e..132b946eb 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp @@ -61,13 +61,12 @@ void IndexedList::adjustByDate(const RowsByLetter &links) { } } -void IndexedList::updateHeight(const RowsByLetter &links) { - _list.updateHeight(links.main); - for (const auto &[ch, row] : links.letters) { - if (auto it = _index.find(ch); it != _index.cend()) { - it->second.updateHeight(row); - } - } +bool IndexedList::updateHeights(float64 narrowRatio) { + return _list.updateHeights(narrowRatio); +} + +bool IndexedList::updateHeight(Key key, float64 narrowRatio) { + return _list.updateHeight(key, narrowRatio); } void IndexedList::moveToTop(Key key) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h index ae8040271..62128d92e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h @@ -22,7 +22,8 @@ public: Row *addByName(Key key); void adjustByDate(const RowsByLetter &links); void moveToTop(Key key); - void updateHeight(const RowsByLetter &links); + bool updateHeight(Key key, float64 narrowRatio); + bool updateHeights(float64 narrowRatio); // row must belong to this indexed list all(). void movePinned(Row *row, int deltaSign); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 1dee86f74..9209a44ca 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -294,8 +294,9 @@ InnerWidget::InnerWidget( ) | rpl::start_with_next([=](const Data::EntryUpdate &update) { const auto entry = update.entry; if (update.flags & Data::EntryUpdate::Flag::Height) { - updateFilteredEntryHeight(entry); - refresh(); + if (updateEntryHeight(entry)) { + refresh(); + } return; } const auto repaintId = (_state == WidgetState::Default) @@ -331,7 +332,10 @@ InnerWidget::InnerWidget( setupShortcuts(); } -void InnerWidget::updateFilteredEntryHeight(not_null entry) { +bool InnerWidget::updateEntryHeight(not_null entry) { + if (!_geometryInited) { + return false; + } auto changing = false; auto top = 0; for (auto &result : _filterResults) { @@ -339,7 +343,7 @@ void InnerWidget::updateFilteredEntryHeight(not_null entry) { result.top = top; } if (result.row->key().entry() == entry) { - result.row->recountHeight(); + result.row->recountHeight(_narrowRatio); changing = true; top = result.top; } @@ -347,6 +351,18 @@ void InnerWidget::updateFilteredEntryHeight(not_null entry) { top += result.row->height(); } } + return _shownList->updateHeight(entry, _narrowRatio) || changing; +} + +void InnerWidget::setNarrowRatio(float64 narrowRatio) { + if (_geometryInited && _narrowRatio == narrowRatio) { + return; + } + _geometryInited = true; + _narrowRatio = narrowRatio; + if (_shownList->updateHeights(_narrowRatio) || !height()) { + refresh(); + } } Main::Session &InnerWidget::session() const { @@ -2070,11 +2086,14 @@ void InnerWidget::updateSelectedRow(Key key) { } void InnerWidget::refreshShownList() { - _shownList = _openedForum + const auto list = _openedForum ? _openedForum->topicsList()->indexed() : _filterId ? session().data().chatsFilters().chatsList(_filterId)->indexed() : session().data().chatsList(_openedFolder)->indexed(); + if (_shownList != list) { + _shownList = list; + } } void InnerWidget::leaveEventHook(QEvent *e) { @@ -2240,6 +2259,7 @@ void InnerWidget::applyFilterUpdate(QString newFilter, bool force) { end(results)); for (const auto e = end(_filterResults); i != e; ++i) { i->top = top; + i->row->recountHeight(_narrowRatio); top += i->row->height(); } }; @@ -2672,7 +2692,9 @@ void InnerWidget::editOpenedFilter() { } void InnerWidget::refresh(bool toTop) { - if (needCollapsedRowsRefresh()) { + if (!_geometryInited) { + return; + } else if (needCollapsedRowsRefresh()) { return refreshWithCollapsedRows(toTop); } refreshEmptyLabel(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 7646bb7f5..50445011a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -112,6 +112,7 @@ public: void selectSkipPage(int32 pixels, int32 direction); void dragLeft(); + void setNarrowRatio(float64 narrowRatio); void clearFilter(); void refresh(bool toTop = false); @@ -235,7 +236,7 @@ private: void repaintDialogRow(FilterId filterId, not_null row); void repaintDialogRow(RowDescriptor row); void refreshDialogRow(RowDescriptor row); - void updateFilteredEntryHeight(not_null entry); + bool updateEntryHeight(not_null entry); void clearMouseSelection(bool clearSelection = false); void mousePressReleased( @@ -496,6 +497,8 @@ private: rpl::event_stream<> _refreshHashtagsRequests; rpl::variable _childListShown; + float64 _narrowRatio = 0.; + bool _geometryInited = false; base::unique_qptr _menu; diff --git a/Telegram/SourceFiles/dialogs/dialogs_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_list.cpp index b8242b8da..d821acb6b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_list.cpp @@ -33,6 +33,7 @@ not_null List::addToEnd(Key key) { key, std::make_unique(key, _rows.size(), height()) ).first->second.get(); + result->recountHeight(_narrowRatio); _rows.emplace_back(result); if (_sortMode == SortMode::Date) { adjustByDate(result); @@ -103,15 +104,36 @@ void List::adjustByDate(not_null row) { } } -void List::updateHeight(not_null row) { - row->recountHeight(); - +bool List::updateHeight(Key key, float64 narrowRatio) { + const auto i = _rowByKey.find(key); + if (i == _rowByKey.cend()) { + return false; + } + const auto row = i->second.get(); const auto index = row->index(); auto top = row->top(); + const auto was = row->height(); + row->recountHeight(narrowRatio); + if (row->height() == was) { + return false; + } for (auto i = _rows.begin() + index, e = _rows.end(); i != e; ++i) { (*i)->_top = top; top += (*i)->height(); } + return true; +} + +bool List::updateHeights(float64 narrowRatio) { + _narrowRatio = narrowRatio; + auto was = height(); + auto top = 0; + for (const auto &row : _rows) { + row->_top = top; + row->recountHeight(narrowRatio); + top += row->height(); + } + return (height() != was); } bool List::moveToTop(Key key) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_list.h b/Telegram/SourceFiles/dialogs/dialogs_list.h index 998fce5ad..baf0a3eea 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_list.h +++ b/Telegram/SourceFiles/dialogs/dialogs_list.h @@ -48,7 +48,8 @@ public: not_null addByName(Key key); bool moveToTop(Key key); void adjustByDate(not_null row); - void updateHeight(not_null row); + bool updateHeight(Key key, float64 narrowRatio); + bool updateHeights(float64 narrowRatio); bool remove(Key key, Row *replacedBy = nullptr); using const_iterator = std::vector>::const_iterator; @@ -76,6 +77,7 @@ private: SortMode _sortMode = SortMode(); FilterId _filterId = 0; + float64 _narrowRatio = 0.; std::vector> _rows; std::map> _rowByKey; diff --git a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp index d6c24f18b..d0197d391 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp @@ -107,10 +107,6 @@ void MainList::removeEntry(Key key) { recomputeFullListSize(); } -void MainList::updateEntryHeight(const RowsByLetter &links) { - _all.updateHeight(links); -} - void MainList::recomputeFullListSize() { _fullListSize = std::max(_all.size(), loaded() ? 0 : _cloudListSize); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_main_list.h b/Telegram/SourceFiles/dialogs/dialogs_main_list.h index 27ec539a9..157e48e31 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_main_list.h +++ b/Telegram/SourceFiles/dialogs/dialogs_main_list.h @@ -35,7 +35,6 @@ public: RowsByLetter addEntry(Key key); void removeEntry(Key key); - void updateEntryHeight(const RowsByLetter &links); void unreadStateChanged( const UnreadState &wasState, diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index b757252dc..cffed86a4 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -101,13 +101,15 @@ Row::Row(Key key, int index, int top) : _id(key), _top(top), _index(index) { if (const auto history = key.history()) { updateCornerBadgeShown(history->peer); } - recountHeight(); } -void Row::recountHeight() { +void Row::recountHeight(float64 narrowRatio) { if (const auto history = _id.history()) { _height = history->peer->isForum() - ? st::forumDialogRow.height + ? anim::interpolate( + st::forumDialogRow.height, + st::defaultDialogRow.height, + narrowRatio) : st::defaultDialogRow.height; } else if (_id.folder()) { _height = st::defaultDialogRow.height; diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.h b/Telegram/SourceFiles/dialogs/dialogs_row.h index 1a1e8d5d9..58cd551eb 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -89,9 +89,11 @@ public: return _top; } [[nodiscard]] int height() const { + Expects(_height != 0); + return _height; } - void recountHeight(); + void recountHeight(float64 narrowRatio); void updateCornerBadgeShown( not_null peer, diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 9420913bf..a43d81f8a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -436,15 +436,19 @@ void Widget::chosenRow(const ChosenRow &row) { ? history->peer->forumTopicFor(row.message.fullId.msg) : nullptr; if (topicJump) { - if (!controller()->adaptive().isOneColumn()) { - controller()->showForum( - topicJump->forum(), - Window::SectionShow().withChildColumn()); + if (controller()->shownForum().current() == topicJump->forum()) { + controller()->closeForum(); + } else { + if (!controller()->adaptive().isOneColumn()) { + controller()->showForum( + topicJump->forum(), + Window::SectionShow().withChildColumn()); + } + controller()->showThread( + topicJump, + ShowAtUnreadMsgId, + Window::SectionShow::Way::ClearStack); } - controller()->showThread( - topicJump, - ShowAtUnreadMsgId, - Window::SectionShow::Way::ClearStack); return; } else if (const auto topic = row.key.topic()) { controller()->showThread( @@ -2334,6 +2338,9 @@ void Widget::updateSearchFromVisibility(bool fast) { } void Widget::updateControlsGeometry() { + if (width() < _narrowWidth) { + return; + } auto filterAreaTop = 0; const auto ratiow = anim::interpolate( @@ -2434,6 +2441,7 @@ void Widget::updateControlsGeometry() { const auto wasScrollHeight = _scroll->height(); _scroll->setGeometry(0, scrollTop, scrollw, scrollHeight); _inner->resize(scrollw, _inner->height()); + _inner->setNarrowRatio(narrowRatio); if (scrollHeight != wasScrollHeight) { controller()->floatPlayerAreaUpdated(); }