2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Added saving of scroll state in dialogs widget for restoring from forum.

This commit is contained in:
23rd
2022-11-07 14:42:13 +03:00
parent c320917069
commit 629314cfa2
3 changed files with 27 additions and 11 deletions

View File

@@ -426,6 +426,9 @@ void InnerWidget::changeOpenedForum(ChannelData *forum) {
stopReorderPinned();
clearSelection();
if (forum) {
saveChatsFilterScrollState(_filterId);
}
_filterId = forum
? 0
: _controller->activeChatsFilterCurrent();
@@ -450,6 +453,10 @@ void InnerWidget::changeOpenedForum(ChannelData *forum) {
if (_loadMoreCallback) {
_loadMoreCallback();
}
if (!forum) {
restoreChatsFilterScrollState(_filterId);
}
}
void InnerWidget::paintEvent(QPaintEvent *e) {
@@ -2971,7 +2978,7 @@ void InnerWidget::switchToFilter(FilterId filterId) {
_mustScrollTo.fire({ 0, 0 });
return;
}
_chatsFilterScrollStates[_filterId] = -pos().y();
saveChatsFilterScrollState(_filterId);
if (_openedFolder) {
_filterId = filterId;
} else {
@@ -2982,18 +2989,26 @@ void InnerWidget::switchToFilter(FilterId filterId) {
}
refreshEmptyLabel();
{
const auto it = _chatsFilterScrollStates.find(filterId);
if (it != end(_chatsFilterScrollStates)) {
const auto skip = found
// Don't save a scroll state for very flexible chat filters.
&& (filterIt->flags() & (Data::ChatFilter::Flag::NoRead));
if (!skip) {
_mustScrollTo.fire({ it->second, -1 });
}
const auto skip = found
// Don't save a scroll state for very flexible chat filters.
&& (filterIt->flags() & (Data::ChatFilter::Flag::NoRead));
if (!skip) {
restoreChatsFilterScrollState(filterId);
}
}
}
void InnerWidget::saveChatsFilterScrollState(FilterId filterId) {
_chatsFilterScrollStates[filterId] = -pos().y();
}
void InnerWidget::restoreChatsFilterScrollState(FilterId filterId) {
const auto it = _chatsFilterScrollStates.find(filterId);
if (it != end(_chatsFilterScrollStates)) {
_mustScrollTo.fire({ it->second, -1 });
}
}
bool InnerWidget::chooseHashtag() {
if (_state != WidgetState::Filtered) {
return false;

View File

@@ -357,6 +357,9 @@ private:
void handleChatListEntryRefreshes();
void moveCancelSearchButtons();
void saveChatsFilterScrollState(FilterId filterId);
void restoreChatsFilterScrollState(FilterId filterId);
const not_null<Window::SessionController*> _controller;
FilterId _filterId = 0;