Fix scroll first to unread then to end.

This commit is contained in:
John Preston 2020-02-21 10:37:57 +04:00
parent ee8028cd53
commit f133210db3
2 changed files with 25 additions and 18 deletions

View File

@ -796,6 +796,7 @@ void HistoryWidget::scrollToCurrentVoiceMessage(FullMsgId fromId, FullMsgId toId
void HistoryWidget::animatedScrollToItem(MsgId msgId) { void HistoryWidget::animatedScrollToItem(MsgId msgId) {
Expects(_history != nullptr); Expects(_history != nullptr);
if (hasPendingResizedItems()) { if (hasPendingResizedItems()) {
updateListSize(); updateListSize();
} }
@ -814,6 +815,7 @@ void HistoryWidget::animatedScrollToItem(MsgId msgId) {
void HistoryWidget::animatedScrollToY(int scrollTo, HistoryItem *attachTo) { void HistoryWidget::animatedScrollToY(int scrollTo, HistoryItem *attachTo) {
Expects(_history != nullptr); Expects(_history != nullptr);
if (hasPendingResizedItems()) { if (hasPendingResizedItems()) {
updateListSize(); updateListSize();
} }
@ -1677,13 +1679,11 @@ void HistoryWidget::showHistory(
setMsgId(showAtMsgId); setMsgId(showAtMsgId);
if (_historyInited) { if (_historyInited) {
const auto to = countInitialScrollTop();
const auto item = getItemFromHistoryOrMigrated( const auto item = getItemFromHistoryOrMigrated(
_showAtMsgId); _showAtMsgId);
animatedScrollToY( animatedScrollToY(
std::clamp( std::clamp(to, 0, _scroll->scrollTopMax()),
countInitialScrollTop(),
0,
_scroll->scrollTopMax()),
item); item);
} else { } else {
historyLoaded(); historyLoaded();
@ -2655,7 +2655,10 @@ void HistoryWidget::loadMessagesDown() {
} }
void HistoryWidget::delayedShowAt(MsgId showAtMsgId) { void HistoryWidget::delayedShowAt(MsgId showAtMsgId) {
if (!_history || (_delayedShowAtRequest && _delayedShowAtMsgId == showAtMsgId)) return; if (!_history
|| (_delayedShowAtRequest && _delayedShowAtMsgId == showAtMsgId)) {
return;
}
clearDelayedShowAt(); clearDelayedShowAt();
_delayedShowAtMsgId = showAtMsgId; _delayedShowAtMsgId = showAtMsgId;
@ -5024,12 +5027,21 @@ void HistoryWidget::createUnreadBarIfBelowVisibleArea(int withScrollTop) {
_history->calculateFirstUnreadMessage(); _history->calculateFirstUnreadMessage();
if (const auto unread = _history->firstUnreadMessage()) { if (const auto unread = _history->firstUnreadMessage()) {
if (_list->itemTop(unread) > withScrollTop) { if (_list->itemTop(unread) > withScrollTop) {
createUnreadBarAndResize();
}
}
}
void HistoryWidget::createUnreadBarAndResize() {
if (!_history->firstUnreadMessage()) {
return;
}
const auto was = base::take(_historyInited);
_history->addUnreadBar(); _history->addUnreadBar();
if (hasPendingResizedItems()) { if (hasPendingResizedItems()) {
updateListSize(); updateListSize();
} }
} _historyInited = was;
}
} }
int HistoryWidget::countAutomaticScrollTop() { int HistoryWidget::countAutomaticScrollTop() {
@ -5042,12 +5054,8 @@ int HistoryWidget::countAutomaticScrollTop() {
+ HistoryView::UnreadBar::height() + HistoryView::UnreadBar::height()
- HistoryView::UnreadBar::marginTop(); - HistoryView::UnreadBar::marginTop();
if (firstUnreadTop < possibleUnreadBarTop) { if (firstUnreadTop < possibleUnreadBarTop) {
const auto history = unread->data()->history(); createUnreadBarAndResize();
history->addUnreadBar(); if (_history->unreadBar() != nullptr) {
if (hasPendingResizedItems()) {
updateListSize();
}
if (history->unreadBar() != nullptr) {
setMsgId(ShowAtUnreadMsgId); setMsgId(ShowAtUnreadMsgId);
return countInitialScrollTop(); return countInitialScrollTop();
} }
@ -5213,9 +5221,7 @@ void HistoryWidget::addMessagesToBack(
_list->messagesReceivedDown(peer, messages); _list->messagesReceivedDown(peer, messages);
if (checkForUnreadStart) { if (checkForUnreadStart) {
_history->calculateFirstUnreadMessage(); _history->calculateFirstUnreadMessage();
if (const auto unread = _history->firstUnreadMessage()) { createUnreadBarAndResize();
_history->addUnreadBar();
}
} }
if (!_firstLoadRequest) { if (!_firstLoadRequest) {
updateHistoryGeometry(false, true, { ScrollChangeNoJumpToBottom, 0 }); updateHistoryGeometry(false, true, { ScrollChangeNoJumpToBottom, 0 });

View File

@ -560,6 +560,7 @@ private:
void destroyUnreadBarOnClose(); void destroyUnreadBarOnClose();
void createUnreadBarIfBelowVisibleArea(int withScrollTop); void createUnreadBarIfBelowVisibleArea(int withScrollTop);
[[nodiscard]] bool insideJumpToEndInsteadOfToUnread() const; [[nodiscard]] bool insideJumpToEndInsteadOfToUnread() const;
void createUnreadBarAndResize();
void saveEditMsg(); void saveEditMsg();
void saveEditMsgDone(History *history, const MTPUpdates &updates, mtpRequestId req); void saveEditMsgDone(History *history, const MTPUpdates &updates, mtpRequestId req);