chatgui: don't save scroll position when at bottom — restore to bottom on reopen

When scrollbar is at max, save lastPosMsgId=0 so restoreScrollPosition
falls through to scrollToBottom() instead of restoring a stale mid-scroll pos.
This commit is contained in:
Evgeny committed 2026-07-24 03:52:05 +03:00
1 parent ed94ab7bea
commit 39b4ca3238
1 file changed
+6 -2
+6 -2
View File
@@ -288,9 +288,11 @@ void MessageList::saveChannelState() {
int vpHeight = m_view->viewport()->height();
QModelIndex topIdx = m_view->indexAt(QPoint(0, 0));
QScrollBar* sb = m_view->verticalScrollBar();
bool atBottom = sb && (sb->value() >= sb->maximum());
qint64 lastPosMsgId = 0;
if (topIdx.isValid())
if (!atBottom && topIdx.isValid())
lastPosMsgId = topIdx.data(MsgIdRole).toLongLong();
qint64 lastReadMsgId = m_lastReadMsgId;
@@ -353,7 +355,9 @@ void MessageList::updateReadPosition() {
}
QModelIndex topIdx = m_view->indexAt(QPoint(0, 0));
qint64 lastPosMsgId = topIdx.isValid() ? topIdx.data(MsgIdRole).toLongLong() : 0;
QScrollBar* sb = m_view->verticalScrollBar();
bool atBottom = sb && (sb->value() >= sb->maximum());
qint64 lastPosMsgId = (!atBottom && topIdx.isValid()) ? topIdx.data(MsgIdRole).toLongLong() : 0;
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG,
"MessageList::updateReadPosition ch=%s oldRead=%lld newRead=%lld pos=%lld lastVisRow=%d/%d",