Removed unnecessary rebuild of chats filters strip when order is same.

This commit is contained in:
23rd 2024-11-23 06:01:23 +03:00
parent 71efd95136
commit ec83f4ae72
3 changed files with 33 additions and 8 deletions

View file

@ -57,6 +57,26 @@ ChatsFiltersTabs::ChatsFiltersTabs(
Ui::DiscreteSlider::setSelectOnPress(false);
}
bool ChatsFiltersTabs::setSectionsAndCheckChanged(
std::vector<QString> &&sections) {
const auto &was = sectionsRef();
const auto changed = [&] {
if (was.size() != sections.size()) {
return true;
}
for (auto i = 0; i < sections.size(); i++) {
if (was[i].label.toString() != sections[i]) {
return true;
}
}
return false;
}();
if (changed) {
Ui::DiscreteSlider::setSections(std::move(sections));
}
return changed;
}
int ChatsFiltersTabs::centerOfSection(int section) const {
const auto widths = countSectionsWidths(0);
auto result = 0;

View file

@ -27,6 +27,8 @@ public:
not_null<Ui::RpWidget*> parent,
const style::SettingsSlider &st);
bool setSectionsAndCheckChanged(std::vector<QString> &&sections);
[[nodiscard]] int centerOfSection(int section) const;
void fitWidthToSections();
void setUnreadCount(int index, int unreadCount, bool muted);

View file

@ -293,15 +293,18 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
if ((list.size() <= 1 && !slider->width()) || state->ignoreRefresh) {
return;
}
const auto sectionsChanged = slider->setSectionsAndCheckChanged(
ranges::views::all(
list
) | ranges::views::transform([](const Data::ChatFilter &filter) {
return filter.title().isEmpty()
? tr::lng_filters_all_short(tr::now)
: filter.title();
}) | ranges::to_vector);
if (!sectionsChanged) {
return;
}
state->rebuildLifetime.destroy();
auto sections = ranges::views::all(
list
) | ranges::views::transform([](const Data::ChatFilter &filter) {
return filter.title().isEmpty()
? tr::lng_filters_all_short(tr::now)
: filter.title();
}) | ranges::to_vector;
slider->setSections(std::move(sections));
slider->fitWidthToSections();
{
const auto reorderAll = session->user()->isPremium();