Skip to content

Commit

Permalink
Fixed redundant peer adding to always/never lists in filter from menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Aug 30, 2023
1 parent 1493b23 commit 3dc0e38
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Telegram/SourceFiles/boxes/choose_filter_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ For license and copyright information please follow this link:
#include "history/history.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "ui/filter_icons.h"
#include "ui/text/text_utilities.h" // Ui::Text::Bold
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "styles/style_settings.h"
#include "styles/style_payments.h" // paymentsSectionButton
#include "styles/style_media_player.h" // mediaPlayerMenuCheck

namespace {
Expand All @@ -32,16 +29,30 @@ Data::ChatFilter ChangedFilter(
not_null<History*> history,
bool add) {
auto always = base::duplicate(filter.always());
if (add) {
always.insert(history);
} else {
always.remove(history);
}
auto never = base::duplicate(filter.never());
if (add) {
never.remove(history);
const auto result = Data::ChatFilter(
filter.id(),
filter.title(),
filter.iconEmoji(),
filter.flags(),
filter.always(),
filter.pinned(),
std::move(never));
if (result.contains(history)) {
return result;
} else {
never = base::duplicate(result.never());
always.insert(history);
}
} else {
never.insert(history);
const auto alwaysIt = always.find(history);
if (alwaysIt != end(always)) {
always.erase(alwaysIt);
} else {
never.insert(history);
}
}
return Data::ChatFilter(
filter.id(),
Expand Down

0 comments on commit 3dc0e38

Please sign in to comment.