Fix opening topic on non-existent message error display.

This commit is contained in:
John Preston 2023-01-21 21:07:13 +04:00
parent 6258aa01b8
commit b0f8846d12
4 changed files with 33 additions and 12 deletions

View file

@ -535,6 +535,13 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) {
std::optional<int> ListWidget::scrollTopForPosition( std::optional<int> ListWidget::scrollTopForPosition(
Data::MessagePosition position) const { 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 (position == Data::UnreadMessagePosition) {
if (_bar.element && !_bar.hidden && _bar.focus) { if (_bar.element && !_bar.hidden && _bar.focus) {
const auto shift = st::lineWidth + st::historyUnreadBarMargin; const auto shift = st::lineWidth + st::historyUnreadBarMargin;
@ -549,6 +556,15 @@ std::optional<int> ListWidget::scrollTopForPosition(
return height() - (_visibleBottom - _visibleTop); return height() - (_visibleBottom - _visibleTop);
} }
return std::nullopt; 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() } else if (_items.empty()
|| isBelowPosition(position) || isBelowPosition(position)
|| isAbovePosition(position)) { || isAbovePosition(position)) {
@ -871,6 +887,7 @@ void ListWidget::updateAroundPositionFromNearest(int nearestIndex) {
} }
const auto newPosition = _items[_aroundIndex]->data()->position(); const auto newPosition = _items[_aroundIndex]->data()->position();
if (_aroundPosition != newPosition) { if (_aroundPosition != newPosition) {
_initialAroundPosition = _aroundPosition;
_aroundPosition = newPosition; _aroundPosition = newPosition;
crl::on_main(this, [=] { refreshViewer(); }); crl::on_main(this, [=] { refreshViewer(); });
} }

View file

@ -612,6 +612,7 @@ private:
Data::MessagePosition _aroundPosition; Data::MessagePosition _aroundPosition;
Data::MessagePosition _shownAtPosition; Data::MessagePosition _shownAtPosition;
Data::MessagePosition _initialAroundPosition;
Context _context; Context _context;
int _aroundIndex = -1; int _aroundIndex = -1;
int _idsLimit = kMinimalIdsLimit; int _idsLimit = kMinimalIdsLimit;

View file

@ -133,19 +133,26 @@ rpl::producer<Ui::MessageBarContent> RootViewContent(
} // namespace } // namespace
RepliesMemento::RepliesMemento( RepliesMemento::RepliesMemento(
not_null<HistoryItem*> commentsItem, not_null<History*> history,
MsgId commentId) MsgId rootId,
: RepliesMemento(commentsItem->history(), commentsItem->id, commentId) { MsgId highlightId)
if (commentId) { : _history(history)
, _rootId(rootId)
, _highlightId(highlightId) {
if (highlightId) {
_list.setAroundPosition({ _list.setAroundPosition({
.fullId = FullMsgId( .fullId = FullMsgId(_history->peer->id, highlightId),
commentsItem->history()->peer->id,
commentId),
.date = TimeId(0), .date = TimeId(0),
}); });
} }
} }
RepliesMemento::RepliesMemento(
not_null<HistoryItem*> commentsItem,
MsgId commentId)
: RepliesMemento(commentsItem->history(), commentsItem->id, commentId) {
}
void RepliesMemento::setFromTopic(not_null<Data::ForumTopic*> topic) { void RepliesMemento::setFromTopic(not_null<Data::ForumTopic*> topic) {
_replies = topic->replies(); _replies = topic->replies();
if (!_list.aroundPosition()) { if (!_list.aroundPosition()) {

View file

@ -365,11 +365,7 @@ public:
RepliesMemento( RepliesMemento(
not_null<History*> history, not_null<History*> history,
MsgId rootId, MsgId rootId,
MsgId highlightId = 0) MsgId highlightId = 0);
: _history(history)
, _rootId(rootId)
, _highlightId(highlightId) {
}
explicit RepliesMemento( explicit RepliesMemento(
not_null<HistoryItem*> commentsItem, not_null<HistoryItem*> commentsItem,
MsgId commentId = 0); MsgId commentId = 0);