diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 9ed264ec3..4d1cd7597 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -535,6 +535,13 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) { std::optional ListWidget::scrollTopForPosition( Data::MessagePosition position) const { + auto messageUnknown = !position.date && position.fullId; + if (messageUnknown) { + if (const auto item = session().data().message(position.fullId)) { + position = item->position(); + messageUnknown = false; + } + } if (position == Data::UnreadMessagePosition) { if (_bar.element && !_bar.hidden && _bar.focus) { const auto shift = st::lineWidth + st::historyUnreadBarMargin; @@ -549,6 +556,15 @@ std::optional ListWidget::scrollTopForPosition( return height() - (_visibleBottom - _visibleTop); } return std::nullopt; + } else if (!_items.empty() + && (_aroundPosition == position + || _initialAroundPosition == position) + && messageUnknown) { + if (_refreshingViewer) { + return std::nullopt; + } + const auto available = _visibleBottom - _visibleTop; + return std::max((height() / 2) - available / 2, 0); } else if (_items.empty() || isBelowPosition(position) || isAbovePosition(position)) { @@ -871,6 +887,7 @@ void ListWidget::updateAroundPositionFromNearest(int nearestIndex) { } const auto newPosition = _items[_aroundIndex]->data()->position(); if (_aroundPosition != newPosition) { + _initialAroundPosition = _aroundPosition; _aroundPosition = newPosition; crl::on_main(this, [=] { refreshViewer(); }); } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index e33194d94..eec023c11 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -612,6 +612,7 @@ private: Data::MessagePosition _aroundPosition; Data::MessagePosition _shownAtPosition; + Data::MessagePosition _initialAroundPosition; Context _context; int _aroundIndex = -1; int _idsLimit = kMinimalIdsLimit; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 35afc1d2b..aceb70c2c 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -133,19 +133,26 @@ rpl::producer RootViewContent( } // namespace RepliesMemento::RepliesMemento( - not_null commentsItem, - MsgId commentId) -: RepliesMemento(commentsItem->history(), commentsItem->id, commentId) { - if (commentId) { + not_null history, + MsgId rootId, + MsgId highlightId) +: _history(history) +, _rootId(rootId) +, _highlightId(highlightId) { + if (highlightId) { _list.setAroundPosition({ - .fullId = FullMsgId( - commentsItem->history()->peer->id, - commentId), + .fullId = FullMsgId(_history->peer->id, highlightId), .date = TimeId(0), }); } } +RepliesMemento::RepliesMemento( + not_null commentsItem, + MsgId commentId) +: RepliesMemento(commentsItem->history(), commentsItem->id, commentId) { +} + void RepliesMemento::setFromTopic(not_null topic) { _replies = topic->replies(); if (!_list.aroundPosition()) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 1b7456df7..8376d8044 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -365,11 +365,7 @@ public: RepliesMemento( not_null history, MsgId rootId, - MsgId highlightId = 0) - : _history(history) - , _rootId(rootId) - , _highlightId(highlightId) { - } + MsgId highlightId = 0); explicit RepliesMemento( not_null commentsItem, MsgId commentId = 0);