mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-20 15:17:41 +00:00
Added support of filters limit to side bar.
This commit is contained in:
parent
b45f97d384
commit
8e6825771e
@ -903,3 +903,12 @@ int CurrentPremiumLimit(
|
|||||||
premium ? keyPremium : keyDefault,
|
premium ? keyPremium : keyDefault,
|
||||||
premium ? limitPremium : limitDefault);
|
premium ? limitPremium : limitDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CurrentPremiumFiltersLimit(not_null<Main::Session*> session) {
|
||||||
|
return CurrentPremiumLimit(
|
||||||
|
session,
|
||||||
|
"dialog_filters_limit_default",
|
||||||
|
10,
|
||||||
|
"dialog_filters_limit_premium",
|
||||||
|
20);
|
||||||
|
}
|
||||||
|
@ -62,3 +62,6 @@ void FileSizeLimitBox(
|
|||||||
int limitDefault,
|
int limitDefault,
|
||||||
const QString &keyPremium,
|
const QString &keyPremium,
|
||||||
int limitPremium);
|
int limitPremium);
|
||||||
|
|
||||||
|
[[nodiscard]] int CurrentPremiumFiltersLimit(
|
||||||
|
not_null<Main::Session*> session);
|
||||||
|
@ -327,12 +327,7 @@ void FilterRowButton::paintEvent(QPaintEvent *e) {
|
|||||||
|
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto limit = [=] {
|
const auto limit = [=] {
|
||||||
return CurrentPremiumLimit(
|
return CurrentPremiumFiltersLimit(session);
|
||||||
session,
|
|
||||||
"dialog_filters_limit_default",
|
|
||||||
10,
|
|
||||||
"dialog_filters_limit_premium",
|
|
||||||
20);
|
|
||||||
};
|
};
|
||||||
AddSkip(container, st::settingsSectionSkip);
|
AddSkip(container, st::settingsSectionSkip);
|
||||||
AddSubsectionTitle(container, tr::lng_filters_subtitle());
|
AddSubsectionTitle(container, tr::lng_filters_subtitle());
|
||||||
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "boxes/filters/edit_filter_box.h"
|
#include "boxes/filters/edit_filter_box.h"
|
||||||
|
#include "boxes/premium_limits_box.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
#include "settings/settings_folders.h"
|
#include "settings/settings_folders.h"
|
||||||
#include "api/api_chat_filters.h"
|
#include "api/api_chat_filters.h"
|
||||||
@ -127,17 +128,12 @@ void FiltersMenu::setup() {
|
|||||||
const auto i = _filters.find(_activeFilterId);
|
const auto i = _filters.find(_activeFilterId);
|
||||||
if (i != end(_filters)) {
|
if (i != end(_filters)) {
|
||||||
i->second->setActive(false);
|
i->second->setActive(false);
|
||||||
} else if (!_activeFilterId && _all) {
|
|
||||||
_all->setActive(false);
|
|
||||||
}
|
}
|
||||||
_activeFilterId = id;
|
_activeFilterId = id;
|
||||||
const auto j = _filters.find(_activeFilterId);
|
const auto j = _filters.find(_activeFilterId);
|
||||||
if (j != end(_filters)) {
|
if (j != end(_filters)) {
|
||||||
j->second->setActive(true);
|
j->second->setActive(true);
|
||||||
scrollToButton(j->second);
|
scrollToButton(j->second);
|
||||||
} else if (!_activeFilterId && _all) {
|
|
||||||
_all->setActive(true);
|
|
||||||
scrollToButton(_all);
|
|
||||||
}
|
}
|
||||||
_reorder->finishReordering();
|
_reorder->finishReordering();
|
||||||
}, _outer.lifetime());
|
}, _outer.lifetime());
|
||||||
@ -194,24 +190,29 @@ void FiltersMenu::refresh() {
|
|||||||
const auto reorderAll = premium();
|
const auto reorderAll = premium();
|
||||||
if (!_list) {
|
if (!_list) {
|
||||||
setupList();
|
setupList();
|
||||||
} else if (reorderAll && _all) {
|
|
||||||
_all = nullptr;
|
|
||||||
} else if (!reorderAll && !_all) {
|
|
||||||
_all = prepareAll();
|
|
||||||
}
|
}
|
||||||
_reorder->cancel();
|
_reorder->cancel();
|
||||||
|
|
||||||
|
_reorder->clearPinnedIntervals();
|
||||||
|
const auto maxLimit = CurrentPremiumFiltersLimit(&_session->session());
|
||||||
|
const auto premiumFrom = (reorderAll ? 0 : 1) + maxLimit;
|
||||||
|
if (!reorderAll) {
|
||||||
|
_reorder->addPinnedInterval(0, 1);
|
||||||
|
}
|
||||||
|
_reorder->addPinnedInterval(
|
||||||
|
premiumFrom,
|
||||||
|
std::max(1, int(filters->list().size()) - maxLimit));
|
||||||
|
|
||||||
auto now = base::flat_map<int, base::unique_qptr<Ui::SideBarButton>>();
|
auto now = base::flat_map<int, base::unique_qptr<Ui::SideBarButton>>();
|
||||||
for (const auto &filter : filters->list()) {
|
for (const auto &filter : filters->list()) {
|
||||||
if (!reorderAll && !filter.id()) {
|
const auto nextIsLocked = (now.size() >= premiumFrom);
|
||||||
continue;
|
auto button = prepareButton(
|
||||||
}
|
_list,
|
||||||
now.emplace(
|
|
||||||
filter.id(),
|
filter.id(),
|
||||||
prepareButton(
|
filter.title(),
|
||||||
_list,
|
Ui::ComputeFilterIcon(filter));
|
||||||
filter.id(),
|
button->setLocked(nextIsLocked);
|
||||||
filter.title(),
|
now.emplace(filter.id(), std::move(button));
|
||||||
Ui::ComputeFilterIcon(filter)));
|
|
||||||
}
|
}
|
||||||
_filters = std::move(now);
|
_filters = std::move(now);
|
||||||
_reorder->start();
|
_reorder->start();
|
||||||
@ -222,14 +223,13 @@ void FiltersMenu::refresh() {
|
|||||||
// so we have to restore it.
|
// so we have to restore it.
|
||||||
_scroll.scrollToY(oldTop);
|
_scroll.scrollToY(oldTop);
|
||||||
const auto i = _filters.find(_activeFilterId);
|
const auto i = _filters.find(_activeFilterId);
|
||||||
const auto button = ((i != end(_filters)) ? i->second : _all).get();
|
const auto button = ((i != end(_filters)) ? i->second.get() : nullptr);
|
||||||
if (button) {
|
if (button) {
|
||||||
scrollToButton(button);
|
scrollToButton(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FiltersMenu::setupList() {
|
void FiltersMenu::setupList() {
|
||||||
_all = premium() ? nullptr : prepareAll();
|
|
||||||
_list = _container->add(object_ptr<Ui::VerticalLayout>(_container));
|
_list = _container->add(object_ptr<Ui::VerticalLayout>(_container));
|
||||||
_setup = prepareButton(
|
_setup = prepareButton(
|
||||||
_container,
|
_container,
|
||||||
@ -300,6 +300,8 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
|
|||||||
raw->setClickedCallback([=] {
|
raw->setClickedCallback([=] {
|
||||||
if (_reordering) {
|
if (_reordering) {
|
||||||
return;
|
return;
|
||||||
|
} else if (raw->locked()) {
|
||||||
|
_session->show(Box(FiltersLimitBox, &_session->session()));
|
||||||
} else if (id >= 0) {
|
} else if (id >= 0) {
|
||||||
_session->setActiveChatsFilter(id);
|
_session->setActiveChatsFilter(id);
|
||||||
} else {
|
} else {
|
||||||
@ -318,9 +320,12 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
|
|||||||
});
|
});
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
raw->events(
|
raw->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
) | rpl::filter([](not_null<QEvent*> e) {
|
||||||
return e->type() == QEvent::ContextMenu;
|
return e->type() == QEvent::ContextMenu;
|
||||||
}) | rpl::start_with_next([=] {
|
}) | rpl::start_with_next([=] {
|
||||||
|
if (raw->locked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
showMenu(QCursor::pos(), id);
|
showMenu(QCursor::pos(), id);
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
}
|
}
|
||||||
@ -401,12 +406,10 @@ void FiltersMenu::applyReorder(
|
|||||||
|
|
||||||
const auto filters = &_session->session().data().chatsFilters();
|
const auto filters = &_session->session().data().chatsFilters();
|
||||||
const auto &list = filters->list();
|
const auto &list = filters->list();
|
||||||
if (_all) {
|
if (!premium()) {
|
||||||
if (list[0].id() != FilterId()) {
|
if (list[0].id() != FilterId()) {
|
||||||
filters->moveAllToFront();
|
filters->moveAllToFront();
|
||||||
}
|
}
|
||||||
++oldPosition;
|
|
||||||
++newPosition;
|
|
||||||
}
|
}
|
||||||
Assert(oldPosition >= 0 && oldPosition < list.size());
|
Assert(oldPosition >= 0 && oldPosition < list.size());
|
||||||
Assert(newPosition >= 0 && newPosition < list.size());
|
Assert(newPosition >= 0 && newPosition < list.size());
|
||||||
|
@ -64,7 +64,6 @@ private:
|
|||||||
not_null<Ui::VerticalLayout*> _container;
|
not_null<Ui::VerticalLayout*> _container;
|
||||||
Ui::VerticalLayout *_list = nullptr;
|
Ui::VerticalLayout *_list = nullptr;
|
||||||
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
|
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
|
||||||
base::unique_qptr<Ui::SideBarButton> _all;
|
|
||||||
base::unique_qptr<Ui::SideBarButton> _setup;
|
base::unique_qptr<Ui::SideBarButton> _setup;
|
||||||
base::flat_map<FilterId, base::unique_qptr<Ui::SideBarButton>> _filters;
|
base::flat_map<FilterId, base::unique_qptr<Ui::SideBarButton>> _filters;
|
||||||
FilterId _activeFilterId = 0;
|
FilterId _activeFilterId = 0;
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit a78089716bf153b4283ec79757268d1047913f12
|
Subproject commit 676d8697c6c704c6c5494f03f0bc78d006052768
|
Loading…
Reference in New Issue
Block a user