Show first (may be non-"All Chats") folder by default.

This commit is contained in:
John Preston 2022-05-17 17:56:15 +04:00
parent fe91887ea2
commit 3b5ec78f4f
6 changed files with 53 additions and 8 deletions

View File

@ -534,6 +534,28 @@ const std::vector<ChatFilter> &ChatFilters::list() const {
return _list;
}
FilterId ChatFilters::defaultId() const {
return lookupId(0);
}
FilterId ChatFilters::lookupId(int index) const {
Expects(index >= 0 && index < _list.size());
if (_owner->session().user()->isPremium() || !_list.front().id()) {
return _list[index].id();
}
const auto i = ranges::find(_list, FilterId(0), &ChatFilter::id);
return !index
? FilterId()
: (index <= int(i - begin(_list)))
? _list[index - 1].id()
: _list[index].id();
}
bool ChatFilters::loaded() const {
return _loaded;
}
bool ChatFilters::has() const {
return _list.size() > 1;
}

View File

@ -102,8 +102,12 @@ public:
void moveAllToFront();
[[nodiscard]] const std::vector<ChatFilter> &list() const;
[[nodiscard]] rpl::producer<> changed() const;
[[nodiscard]] bool loaded() const;
[[nodiscard]] bool has() const;
[[nodiscard]] FilterId defaultId() const;
[[nodiscard]] FilterId lookupId(int index) const;
bool loadNextExceptions(bool chatsListLoaded);
void refreshHistory(not_null<History*> history);

View File

@ -3205,20 +3205,19 @@ void InnerWidget::setupShortcuts() {
});
if (session().data().chatsFilters().has()) {
const auto filters = &session().data().chatsFilters().list();
const auto filtersCount = int(filters->size());
const auto filters = &session().data().chatsFilters();
const auto filtersCount = int(filters->list().size());
auto &&folders = ranges::views::zip(
Shortcuts::kShowFolder,
ranges::views::ints(0, ranges::unreachable));
for (const auto [command, index] : folders) {
const auto select = (command == Command::ShowFolderLast)
? filtersCount
: std::clamp(index, 0, int(filtersCount));
? (filtersCount - 1)
: std::clamp(index, 0, filtersCount - 1);
request->check(command) && request->handle([=] {
if (select <= filtersCount) {
_controller->setActiveChatsFilter((select > 0)
? (*filters)[select - 1].id()
: 0);
_controller->setActiveChatsFilter(
filters->lookupId(select));
}
return true;
});

View File

@ -121,8 +121,12 @@ void FiltersMenu::setup() {
_activeFilterId = _session->activeChatsFilterCurrent();
_session->activeChatsFilter(
) | rpl::filter([=](FilterId id) {
return id != _activeFilterId;
return (id != _activeFilterId);
}) | rpl::start_with_next([=](FilterId id) {
if (!_list) {
_activeFilterId = id;
return;
}
const auto i = _filters.find(_activeFilterId);
if (i != end(_filters)) {
i->second->setActive(false);

View File

@ -600,6 +600,7 @@ SessionController::SessionController(
_window->widget(),
this))
, _invitePeekTimer([=] { checkInvitePeek(); })
, _activeChatsFilter(session->data().chatsFilters().defaultId())
, _defaultChatTheme(std::make_shared<Ui::ChatTheme>())
, _chatStyle(std::make_unique<Ui::ChatStyle>())
, _cachedReactionIconFactory(std::make_unique<ReactionIconFactory>()) {
@ -657,6 +658,10 @@ SessionController::SessionController(
}, _lifetime);
session->addWindow(this);
crl::on_main(this, [=] {
activateFirstChatsFilter();
});
}
void SessionController::suggestArchiveAndMute() {
@ -772,6 +777,7 @@ rpl::producer<> SessionController::filtersMenuChanged() const {
}
void SessionController::checkOpenedFilter() {
activateFirstChatsFilter();
if (const auto filterId = activeChatsFilterCurrent()) {
const auto &list = session().data().chatsFilters().list();
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
@ -781,6 +787,14 @@ void SessionController::checkOpenedFilter() {
}
}
void SessionController::activateFirstChatsFilter() {
if (_filtersActivated || !session().data().chatsFilters().loaded()) {
return;
}
_filtersActivated = true;
setActiveChatsFilter(session().data().chatsFilters().defaultId());
}
bool SessionController::uniqueChatsInSearchResults() const {
return session().supportMode()
&& !session().settings().supportAllSearchResults()

View File

@ -513,6 +513,7 @@ private:
void refreshFiltersMenu();
void checkOpenedFilter();
void suggestArchiveAndMute();
void activateFirstChatsFilter();
int minimalThreeColumnWidth() const;
int countDialogsWidthFromRatio(int bodyWidth) const;
@ -562,6 +563,7 @@ private:
base::Variable<bool> _dialogsListDisplayForced = { false };
std::deque<Dialogs::RowDescriptor> _chatEntryHistory;
int _chatEntryHistoryPosition = -1;
bool _filtersActivated = false;
bool _selectingPeer = false;
base::Timer _invitePeekTimer;