mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Provided count of dialogs in filter to premium limit boxes.
This commit is contained in:
parent
9b6b5968e2
commit
9e9a269439
5 changed files with 29 additions and 12 deletions
|
@ -121,15 +121,19 @@ bool ChooseFilterValidator::canRemove(FilterId filterId) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ChooseFilterValidator::limitReached(FilterId filterId) const {
|
||||
ChooseFilterValidator::LimitData ChooseFilterValidator::limitReached(
|
||||
FilterId filterId) const {
|
||||
Expects(filterId != 0);
|
||||
|
||||
const auto list = _history->owner().chatsFilters().list();
|
||||
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
||||
const auto limit = _history->owner().pinnedChatsLimit(nullptr, filterId);
|
||||
return (i != end(list))
|
||||
&& !ranges::contains(i->always(), _history)
|
||||
&& (i->always().size() >= limit);
|
||||
return {
|
||||
.reached = (i != end(list))
|
||||
&& !ranges::contains(i->always(), _history)
|
||||
&& (i->always().size() >= limit),
|
||||
.count = int(i->always().size()),
|
||||
};
|
||||
}
|
||||
|
||||
void ChooseFilterValidator::add(FilterId filterId) const {
|
||||
|
@ -158,9 +162,11 @@ void FillChooseFilterMenu(
|
|||
if (validator.canRemove(id)) {
|
||||
validator.remove(id);
|
||||
}
|
||||
} else if (validator.limitReached(id)) {
|
||||
controller->show(
|
||||
Box(FilterChatsLimitBox, &controller->session()));
|
||||
} else if (const auto r = validator.limitReached(id); r.reached) {
|
||||
controller->show(Box(
|
||||
FilterChatsLimitBox,
|
||||
&controller->session(),
|
||||
r.count));
|
||||
} else if (validator.canAdd()) {
|
||||
validator.add(id);
|
||||
}
|
||||
|
|
|
@ -20,10 +20,14 @@ class History;
|
|||
class ChooseFilterValidator final {
|
||||
public:
|
||||
ChooseFilterValidator(not_null<History*> history);
|
||||
struct LimitData {
|
||||
const bool reached = false;
|
||||
const int count = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] bool canAdd() const;
|
||||
[[nodiscard]] bool canRemove(FilterId filterId) const;
|
||||
[[nodiscard]] bool limitReached(FilterId filterId) const;
|
||||
[[nodiscard]] LimitData limitReached(FilterId filterId) const;
|
||||
|
||||
void add(FilterId filterId) const;
|
||||
void remove(FilterId filterId) const;
|
||||
|
|
|
@ -348,7 +348,8 @@ void EditFilterChatsListController::rowClicked(not_null<PeerListRow*> row) {
|
|||
delegate()->peerListSetRowChecked(row, !row->checked());
|
||||
updateTitle();
|
||||
} else {
|
||||
delegate()->peerListShowBox(Box(FilterChatsLimitBox, _session));
|
||||
delegate()->peerListShowBox(
|
||||
Box(FilterChatsLimitBox, _session, count));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -668,7 +668,8 @@ void PublicLinksLimitBox(
|
|||
|
||||
void FilterChatsLimitBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session) {
|
||||
not_null<Main::Session*> session,
|
||||
int currentCount) {
|
||||
const auto premium = session->premium();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
|
@ -679,6 +680,10 @@ void FilterChatsLimitBox(
|
|||
session,
|
||||
"dialog_filters_chats_limit_premium",
|
||||
200);
|
||||
const auto current = std::clamp(
|
||||
float64(currentCount),
|
||||
defaultLimit,
|
||||
premiumLimit);
|
||||
|
||||
auto text = rpl::combine(
|
||||
tr::lng_filter_chats_limit1(
|
||||
|
@ -703,7 +708,7 @@ void FilterChatsLimitBox(
|
|||
tr::lng_filter_chats_limit_title(),
|
||||
std::move(text),
|
||||
"dialog_filters_chats",
|
||||
{ defaultLimit, defaultLimit, premiumLimit, &st::premiumIconChats },
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconChats },
|
||||
premium);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ void PublicLinksLimitBox(
|
|||
Fn<void()> retry);
|
||||
void FilterChatsLimitBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session);
|
||||
not_null<Main::Session*> session,
|
||||
int currentCount);
|
||||
void FiltersLimitBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session);
|
||||
|
|
Loading…
Add table
Reference in a new issue