From 72d7ca79d78576cf07d62e7203abe4fce01b0eff Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 10 Jun 2024 13:35:11 +0300 Subject: [PATCH 1/2] Remove NSFW advanced settings option --- Config/BuildSettings.swift | 1 - Riot/Managers/Settings/RiotSettings.swift | 9 +----- .../Recents/DataSources/RecentsDataSource.m | 1 - .../UnifiedSearchViewController.m | 2 -- .../PublicRoomsDirectoryDataSource.h | 5 ---- .../PublicRoomsDirectoryDataSource.m | 19 +------------ .../Modules/Settings/SettingsViewController.m | 28 ++----------------- 7 files changed, 4 insertions(+), 61 deletions(-) diff --git a/Config/BuildSettings.swift b/Config/BuildSettings.swift index e3e3e55e82..48a4deed83 100644 --- a/Config/BuildSettings.swift +++ b/Config/BuildSettings.swift @@ -297,7 +297,6 @@ final class BuildSettings: NSObject { static let settingsScreenShowChangePassword:Bool = true static let settingsScreenShowEnableStunServerFallback: Bool = true static let settingsScreenShowNotificationDecodedContentOption: Bool = true - static let settingsScreenShowNsfwRoomsOption: Bool = true static let settingsSecurityScreenShowSessions:Bool = true static let settingsSecurityScreenShowSetupBackup:Bool = true static let settingsSecurityScreenShowRestoreBackup:Bool = true diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 06746801ce..4710eba63d 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -97,10 +97,6 @@ final class RiotSettings: NSObject { @UserDefault(key: UserDefaultsKeys.pinRoomsWithUnreadMessagesOnHome, defaultValue: false, storage: defaults) var pinRoomsWithUnreadMessagesOnHome - /// Indicate to show Not Safe For Work public rooms. - @UserDefault(key: "showNSFWPublicRooms", defaultValue: false, storage: defaults) - var showNSFWPublicRooms - // MARK: User interface @UserDefault(key: "userInterfaceTheme", defaultValue: nil, storage: defaults) @@ -329,10 +325,7 @@ final class RiotSettings: NSObject { @UserDefault(key: "settingsScreenShowNotificationDecodedContentOption", defaultValue: BuildSettings.settingsScreenShowNotificationDecodedContentOption, storage: defaults) var settingsScreenShowNotificationDecodedContentOption - - @UserDefault(key: "settingsScreenShowNsfwRoomsOption", defaultValue: BuildSettings.settingsScreenShowNsfwRoomsOption, storage: defaults) - var settingsScreenShowNsfwRoomsOption - + @UserDefault(key: "settingsSecurityScreenShowSessions", defaultValue: BuildSettings.settingsSecurityScreenShowSessions, storage: defaults) var settingsSecurityScreenShowSessions diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index 85393a2d0d..edf05bedcf 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -471,7 +471,6 @@ - (MXKSessionRecentsDataSource *)addMatrixSession:(MXSession *)mxSession if (!_publicRoomsDirectoryDataSource) { _publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession]; - _publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms; _publicRoomsDirectoryDataSource.delegate = self; } diff --git a/Riot/Modules/GlobalSearch/UnifiedSearchViewController.m b/Riot/Modules/GlobalSearch/UnifiedSearchViewController.m index 8703623bba..94ae50f5a2 100644 --- a/Riot/Modules/GlobalSearch/UnifiedSearchViewController.m +++ b/Riot/Modules/GlobalSearch/UnifiedSearchViewController.m @@ -141,8 +141,6 @@ - (void)viewWillAppear:(BOOL)animated // Reset searches [recentsDataSource searchWithPatterns:nil]; - // TODO: Notify RiotSettings.shared.showNSFWPublicRooms change for iPad as viewWillAppear may not be called - recentsDataSource.publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms; [self updateSearch]; diff --git a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.h b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.h index 6fce1d92b0..121722ed46 100644 --- a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.h +++ b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.h @@ -45,11 +45,6 @@ */ @property (nonatomic) BOOL includeAllNetworks; -/** - Flag to indicate to show Not Safe For Work rooms in the public room list. - */ -@property (nonatomic) BOOL showNSFWRooms; - /** List public rooms from a third party protocol. Default is nil. diff --git a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m index cad8560125..257f68d2ed 100644 --- a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m +++ b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m @@ -155,16 +155,6 @@ - (void)setSearchPattern:(NSString *)searchPattern } } -- (void)setShowNSFWRooms:(BOOL)showNSFWRooms -{ - if (showNSFWRooms != _showNSFWRooms) - { - _showNSFWRooms = showNSFWRooms; - - [self resetPagination]; - } -} - - (NSUInteger)roomsCount { return rooms.count; @@ -254,14 +244,7 @@ - (MXHTTPOperation *)paginate:(void (^)(NSUInteger))complete failure:(void (^)(N NSArray *publicRooms; - if (self.showNSFWRooms) - { - publicRooms = publicRoomsResponse.chunk; - } - else - { - publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk containingKeyword:kNSFWKeyword]; - } + publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk containingKeyword:kNSFWKeyword]; [self->rooms addObjectsFromArray:publicRooms]; self->nextBatch = publicRoomsResponse.nextBatch; diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 39698f765f..41372d2e06 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -152,8 +152,7 @@ typedef NS_ENUM(NSUInteger, PRESENCE) typedef NS_ENUM(NSUInteger, ADVANCED) { - ADVANCED_SHOW_NSFW_ROOMS_INDEX = 0, - ADVANCED_CRASH_REPORT_INDEX, + ADVANCED_CRASH_REPORT_INDEX = 0, ADVANCED_ENABLE_RAGESHAKE_INDEX, ADVANCED_MARK_ALL_AS_READ_INDEX, ADVANCED_CLEAR_CACHE_INDEX, @@ -567,11 +566,6 @@ - (void)updateSections Section *sectionAdvanced = [Section sectionWithTag:SECTION_TAG_ADVANCED]; sectionAdvanced.headerTitle = [VectorL10n settingsAdvanced]; - if (RiotSettings.shared.settingsScreenShowNsfwRoomsOption) - { - [sectionAdvanced addRowWithTag:ADVANCED_SHOW_NSFW_ROOMS_INDEX]; - } - if (BuildSettings.settingsScreenAllowChangingCrashUsageDataSettings) { [sectionAdvanced addRowWithTag:ADVANCED_CRASH_REPORT_INDEX]; @@ -2372,20 +2366,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } else if (section == SECTION_TAG_ADVANCED) { - if (row == ADVANCED_SHOW_NSFW_ROOMS_INDEX) - { - MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; - - labelAndSwitchCell.mxkLabel.text = [VectorL10n settingsShowNSFWPublicRooms]; - - labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.showNSFWPublicRooms; - labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor; - labelAndSwitchCell.mxkSwitch.enabled = YES; - [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleNSFWPublicRoomsFiltering:) forControlEvents:UIControlEventTouchUpInside]; - - cell = labelAndSwitchCell; - } - else if (row == ADVANCED_CRASH_REPORT_INDEX) + if (row == ADVANCED_CRASH_REPORT_INDEX) { MXKTableViewCellWithLabelAndSwitch* sendCrashReportCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; @@ -4082,11 +4063,6 @@ - (void)togglePresenceOfflineMode:(UISwitch *)sender } } -- (void)toggleNSFWPublicRoomsFiltering:(UISwitch *)sender -{ - RiotSettings.shared.showNSFWPublicRooms = sender.isOn; -} - - (void)toggleEnableRoomMessageBubbles:(UISwitch *)sender { RiotSettings.shared.roomScreenEnableMessageBubbles = sender.isOn; From ae271f202f0f235b36618e4761d44c34b49c18c4 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 10 Jun 2024 14:53:09 +0300 Subject: [PATCH 2/2] Adopt the EXA forbidden terms list when searching for public rooms --- .../PublicRoomsDirectoryDataSource.m | 29 ++++++-- Riot/SupportingFiles/forbidden_terms.txt | 68 +++++++++++++++++++ 2 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 Riot/SupportingFiles/forbidden_terms.txt diff --git a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m index 257f68d2ed..5ae737549c 100644 --- a/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m +++ b/Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m @@ -46,6 +46,8 @@ @interface PublicRoomsDirectoryDataSource () NSString *nextBatch; } +@property (nonatomic, strong) NSRegularExpression *forbiddenTermsRegex; + @end @implementation PublicRoomsDirectoryDataSource @@ -57,6 +59,15 @@ - (instancetype)init { rooms = [NSMutableArray array]; _paginationLimit = 20; + + NSString *path = [[NSBundle mainBundle] pathForResource:@"forbidden_terms" ofType:@"txt"]; + NSString *fileContents = [NSString stringWithContentsOfFile:path encoding: NSUTF8StringEncoding error:nil]; + NSArray *forbiddenTerms = [fileContents componentsSeparatedByCharactersInSet: NSCharacterSet.whitespaceAndNewlineCharacterSet]; + + NSString *pattern = [NSString stringWithFormat:@"\\b(%@)\\b", [forbiddenTerms componentsJoinedByString:@"|"]]; + pattern = [pattern stringByAppendingString:@"|(\\b18\\+)"]; // Special case "18+" + + _forbiddenTermsRegex = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil]; } return self; } @@ -244,7 +255,7 @@ - (MXHTTPOperation *)paginate:(void (^)(NSUInteger))complete failure:(void (^)(N NSArray *publicRooms; - publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk containingKeyword:kNSFWKeyword]; + publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk]; [self->rooms addObjectsFromArray:publicRooms]; self->nextBatch = publicRoomsResponse.nextBatch; @@ -321,15 +332,23 @@ - (void)setState:(MXKDataSourceState)newState } } -- (NSArray*)filterPublicRooms:(NSArray*)publicRooms containingKeyword:(NSString*)keyword +- (NSArray*)filterPublicRooms:(NSArray*)publicRooms { NSMutableArray *filteredRooms = [NSMutableArray new]; for (MXPublicRoom *publicRoom in publicRooms) { - if (NO == [[publicRoom.name lowercaseString] containsString:keyword] - && NO == [[publicRoom.topic lowercaseString] containsString:keyword]) - { + BOOL shouldAllow = YES; + + if (publicRoom.name != nil) { + shouldAllow &= [self.forbiddenTermsRegex numberOfMatchesInString:publicRoom.name options:0 range:NSMakeRange(0, publicRoom.name.length)] == 0; + } + + if (publicRoom.topic != nil) { + shouldAllow &= [self.forbiddenTermsRegex numberOfMatchesInString:publicRoom.topic options:0 range:NSMakeRange(0, publicRoom.topic.length)] == 0; + } + + if (shouldAllow) { [filteredRooms addObject:publicRoom]; } } diff --git a/Riot/SupportingFiles/forbidden_terms.txt b/Riot/SupportingFiles/forbidden_terms.txt new file mode 100644 index 0000000000..ff22aa40fc --- /dev/null +++ b/Riot/SupportingFiles/forbidden_terms.txt @@ -0,0 +1,68 @@ +anal +bbw +bdsm +beast +bestiality +blowjob +bondage +boobs +clit +cock +cuck +cum +cunt +daddy +dick +dildo +erotic +exhibitionism +faggot +femboy +fisting +flogging +fmf +foursome +futa +gangbang +gore +h3ntai +handjob +hentai +incest +jizz +kink +loli +m4f +masturbate +masturbation +mfm +milf +moresome +naked +neet +nsfw +nude +nudity +orgy +pedo +pegging +penis +petplay +porn +pussy +rape +rimming +sadism +sadomasochism +sexy +shota +spank +squirt +strap-on +threesome +vagina +vibrator +voyeur +watersports +xxx +zoo \ No newline at end of file