mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Added warning of limitation on excluding chats from filter from menu.
This commit is contained in:
parent
717041a462
commit
8a24f33c06
2 changed files with 20 additions and 15 deletions
|
@ -70,8 +70,6 @@ void ChangeFilterById(
|
||||||
MTP_int(filter.id()),
|
MTP_int(filter.id()),
|
||||||
filter.tl()
|
filter.tl()
|
||||||
)).done([=, chat = history->peer->name(), name = filter.title()] {
|
)).done([=, chat = history->peer->name(), name = filter.title()] {
|
||||||
// Since only the primary window has dialogs list,
|
|
||||||
// We can safely show toast there.
|
|
||||||
const auto account = &history->session().account();
|
const auto account = &history->session().account();
|
||||||
if (const auto controller = Core::App().windowFor(account)) {
|
if (const auto controller = Core::App().windowFor(account)) {
|
||||||
controller->showToast((add
|
controller->showToast((add
|
||||||
|
@ -120,17 +118,19 @@ bool ChooseFilterValidator::canRemove(FilterId filterId) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChooseFilterValidator::LimitData ChooseFilterValidator::limitReached(
|
ChooseFilterValidator::LimitData ChooseFilterValidator::limitReached(
|
||||||
FilterId filterId) const {
|
FilterId filterId,
|
||||||
|
bool always) const {
|
||||||
Expects(filterId != 0);
|
Expects(filterId != 0);
|
||||||
|
|
||||||
const auto list = _history->owner().chatsFilters().list();
|
const auto list = _history->owner().chatsFilters().list();
|
||||||
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
||||||
const auto limit = _history->owner().pinnedChatsLimit(filterId);
|
const auto limit = _history->owner().pinnedChatsLimit(filterId);
|
||||||
|
const auto &chatsList = always ? i->always() : i->never();
|
||||||
return {
|
return {
|
||||||
.reached = (i != end(list))
|
.reached = (i != end(list))
|
||||||
&& !ranges::contains(i->always(), _history)
|
&& !ranges::contains(chatsList, _history)
|
||||||
&& (i->always().size() >= limit),
|
&& (chatsList.size() >= limit),
|
||||||
.count = int(i->always().size()),
|
.count = int(chatsList.size()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,18 +156,21 @@ void FillChooseFilterMenu(
|
||||||
|
|
||||||
const auto contains = filter.contains(history);
|
const auto contains = filter.contains(history);
|
||||||
const auto action = menu->addAction(filter.title(), [=] {
|
const auto action = menu->addAction(filter.title(), [=] {
|
||||||
if (filter.contains(history)) {
|
const auto toAdd = !filter.contains(history);
|
||||||
if (validator.canRemove(id)) {
|
const auto r = validator.limitReached(id, toAdd);
|
||||||
validator.remove(id);
|
if (r.reached) {
|
||||||
}
|
|
||||||
} else if (const auto r = validator.limitReached(id); r.reached) {
|
|
||||||
controller->show(Box(
|
controller->show(Box(
|
||||||
FilterChatsLimitBox,
|
FilterChatsLimitBox,
|
||||||
&controller->session(),
|
&controller->session(),
|
||||||
r.count,
|
r.count,
|
||||||
true));
|
toAdd));
|
||||||
} else if (validator.canAdd()) {
|
return;
|
||||||
validator.add(id);
|
} else if (toAdd ? validator.canAdd() : validator.canRemove(id)) {
|
||||||
|
if (toAdd) {
|
||||||
|
validator.add(id);
|
||||||
|
} else {
|
||||||
|
validator.remove(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, contains ? &st::mediaPlayerMenuCheck : nullptr);
|
}, contains ? &st::mediaPlayerMenuCheck : nullptr);
|
||||||
action->setEnabled(contains
|
action->setEnabled(contains
|
||||||
|
|
|
@ -27,7 +27,9 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] bool canAdd() const;
|
[[nodiscard]] bool canAdd() const;
|
||||||
[[nodiscard]] bool canRemove(FilterId filterId) const;
|
[[nodiscard]] bool canRemove(FilterId filterId) const;
|
||||||
[[nodiscard]] LimitData limitReached(FilterId filterId) const;
|
[[nodiscard]] LimitData limitReached(
|
||||||
|
FilterId filterId,
|
||||||
|
bool always) const;
|
||||||
|
|
||||||
void add(FilterId filterId) const;
|
void add(FilterId filterId) const;
|
||||||
void remove(FilterId filterId) const;
|
void remove(FilterId filterId) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue