Skip to content

Commit 7e71a84

Browse files
authored
Merge pull request #7803 from element-hq/stefan/decency
Better explicit term room directory search filtering
2 parents 0a0c866 + ae271f2 commit 7e71a84

File tree

8 files changed

+95
-65
lines changed

8 files changed

+95
-65
lines changed

Config/BuildSettings.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ final class BuildSettings: NSObject {
297297
static let settingsScreenShowChangePassword:Bool = true
298298
static let settingsScreenShowEnableStunServerFallback: Bool = true
299299
static let settingsScreenShowNotificationDecodedContentOption: Bool = true
300-
static let settingsScreenShowNsfwRoomsOption: Bool = true
301300
static let settingsSecurityScreenShowSessions:Bool = true
302301
static let settingsSecurityScreenShowSetupBackup:Bool = true
303302
static let settingsSecurityScreenShowRestoreBackup:Bool = true

Riot/Managers/Settings/RiotSettings.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ final class RiotSettings: NSObject {
9797
@UserDefault(key: UserDefaultsKeys.pinRoomsWithUnreadMessagesOnHome, defaultValue: false, storage: defaults)
9898
var pinRoomsWithUnreadMessagesOnHome
9999

100-
/// Indicate to show Not Safe For Work public rooms.
101-
@UserDefault(key: "showNSFWPublicRooms", defaultValue: false, storage: defaults)
102-
var showNSFWPublicRooms
103-
104100
// MARK: User interface
105101

106102
@UserDefault<String?>(key: "userInterfaceTheme", defaultValue: nil, storage: defaults)
@@ -329,10 +325,7 @@ final class RiotSettings: NSObject {
329325

330326
@UserDefault(key: "settingsScreenShowNotificationDecodedContentOption", defaultValue: BuildSettings.settingsScreenShowNotificationDecodedContentOption, storage: defaults)
331327
var settingsScreenShowNotificationDecodedContentOption
332-
333-
@UserDefault(key: "settingsScreenShowNsfwRoomsOption", defaultValue: BuildSettings.settingsScreenShowNsfwRoomsOption, storage: defaults)
334-
var settingsScreenShowNsfwRoomsOption
335-
328+
336329
@UserDefault(key: "settingsSecurityScreenShowSessions", defaultValue: BuildSettings.settingsSecurityScreenShowSessions, storage: defaults)
337330
var settingsSecurityScreenShowSessions
338331

Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ - (MXKSessionRecentsDataSource *)addMatrixSession:(MXSession *)mxSession
471471
if (!_publicRoomsDirectoryDataSource)
472472
{
473473
_publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession];
474-
_publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms;
475474
_publicRoomsDirectoryDataSource.delegate = self;
476475
}
477476

Riot/Modules/GlobalSearch/UnifiedSearchViewController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ - (void)viewWillAppear:(BOOL)animated
141141

142142
// Reset searches
143143
[recentsDataSource searchWithPatterns:nil];
144-
// TODO: Notify RiotSettings.shared.showNSFWPublicRooms change for iPad as viewWillAppear may not be called
145-
recentsDataSource.publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms;
146144

147145
[self updateSearch];
148146

Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
*/
4646
@property (nonatomic) BOOL includeAllNetworks;
4747

48-
/**
49-
Flag to indicate to show Not Safe For Work rooms in the public room list.
50-
*/
51-
@property (nonatomic) BOOL showNSFWRooms;
52-
5348
/**
5449
List public rooms from a third party protocol.
5550
Default is nil.

Riot/Modules/PublicRoomList/DataSources/PublicRoomsDirectoryDataSource.m

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ @interface PublicRoomsDirectoryDataSource ()
4646
NSString *nextBatch;
4747
}
4848

49+
@property (nonatomic, strong) NSRegularExpression *forbiddenTermsRegex;
50+
4951
@end
5052

5153
@implementation PublicRoomsDirectoryDataSource
@@ -57,6 +59,15 @@ - (instancetype)init
5759
{
5860
rooms = [NSMutableArray array];
5961
_paginationLimit = 20;
62+
63+
NSString *path = [[NSBundle mainBundle] pathForResource:@"forbidden_terms" ofType:@"txt"];
64+
NSString *fileContents = [NSString stringWithContentsOfFile:path encoding: NSUTF8StringEncoding error:nil];
65+
NSArray *forbiddenTerms = [fileContents componentsSeparatedByCharactersInSet: NSCharacterSet.whitespaceAndNewlineCharacterSet];
66+
67+
NSString *pattern = [NSString stringWithFormat:@"\\b(%@)\\b", [forbiddenTerms componentsJoinedByString:@"|"]];
68+
pattern = [pattern stringByAppendingString:@"|(\\b18\\+)"]; // Special case "18+"
69+
70+
_forbiddenTermsRegex = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
6071
}
6172
return self;
6273
}
@@ -155,16 +166,6 @@ - (void)setSearchPattern:(NSString *)searchPattern
155166
}
156167
}
157168

158-
- (void)setShowNSFWRooms:(BOOL)showNSFWRooms
159-
{
160-
if (showNSFWRooms != _showNSFWRooms)
161-
{
162-
_showNSFWRooms = showNSFWRooms;
163-
164-
[self resetPagination];
165-
}
166-
}
167-
168169
- (NSUInteger)roomsCount
169170
{
170171
return rooms.count;
@@ -254,14 +255,7 @@ - (MXHTTPOperation *)paginate:(void (^)(NSUInteger))complete failure:(void (^)(N
254255

255256
NSArray<MXPublicRoom*> *publicRooms;
256257

257-
if (self.showNSFWRooms)
258-
{
259-
publicRooms = publicRoomsResponse.chunk;
260-
}
261-
else
262-
{
263-
publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk containingKeyword:kNSFWKeyword];
264-
}
258+
publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk];
265259

266260
[self->rooms addObjectsFromArray:publicRooms];
267261
self->nextBatch = publicRoomsResponse.nextBatch;
@@ -338,15 +332,23 @@ - (void)setState:(MXKDataSourceState)newState
338332
}
339333
}
340334

341-
- (NSArray<MXPublicRoom*>*)filterPublicRooms:(NSArray<MXPublicRoom*>*)publicRooms containingKeyword:(NSString*)keyword
335+
- (NSArray<MXPublicRoom*>*)filterPublicRooms:(NSArray<MXPublicRoom*>*)publicRooms
342336
{
343337
NSMutableArray *filteredRooms = [NSMutableArray new];
344338

345339
for (MXPublicRoom *publicRoom in publicRooms)
346340
{
347-
if (NO == [[publicRoom.name lowercaseString] containsString:keyword]
348-
&& NO == [[publicRoom.topic lowercaseString] containsString:keyword])
349-
{
341+
BOOL shouldAllow = YES;
342+
343+
if (publicRoom.name != nil) {
344+
shouldAllow &= [self.forbiddenTermsRegex numberOfMatchesInString:publicRoom.name options:0 range:NSMakeRange(0, publicRoom.name.length)] == 0;
345+
}
346+
347+
if (publicRoom.topic != nil) {
348+
shouldAllow &= [self.forbiddenTermsRegex numberOfMatchesInString:publicRoom.topic options:0 range:NSMakeRange(0, publicRoom.topic.length)] == 0;
349+
}
350+
351+
if (shouldAllow) {
350352
[filteredRooms addObject:publicRoom];
351353
}
352354
}

Riot/Modules/Settings/SettingsViewController.m

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ typedef NS_ENUM(NSUInteger, PRESENCE)
152152

153153
typedef NS_ENUM(NSUInteger, ADVANCED)
154154
{
155-
ADVANCED_SHOW_NSFW_ROOMS_INDEX = 0,
156-
ADVANCED_CRASH_REPORT_INDEX,
155+
ADVANCED_CRASH_REPORT_INDEX = 0,
157156
ADVANCED_ENABLE_RAGESHAKE_INDEX,
158157
ADVANCED_MARK_ALL_AS_READ_INDEX,
159158
ADVANCED_CLEAR_CACHE_INDEX,
@@ -567,11 +566,6 @@ - (void)updateSections
567566
Section *sectionAdvanced = [Section sectionWithTag:SECTION_TAG_ADVANCED];
568567
sectionAdvanced.headerTitle = [VectorL10n settingsAdvanced];
569568

570-
if (RiotSettings.shared.settingsScreenShowNsfwRoomsOption)
571-
{
572-
[sectionAdvanced addRowWithTag:ADVANCED_SHOW_NSFW_ROOMS_INDEX];
573-
}
574-
575569
if (BuildSettings.settingsScreenAllowChangingCrashUsageDataSettings)
576570
{
577571
[sectionAdvanced addRowWithTag:ADVANCED_CRASH_REPORT_INDEX];
@@ -2372,20 +2366,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
23722366
}
23732367
else if (section == SECTION_TAG_ADVANCED)
23742368
{
2375-
if (row == ADVANCED_SHOW_NSFW_ROOMS_INDEX)
2376-
{
2377-
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
2378-
2379-
labelAndSwitchCell.mxkLabel.text = [VectorL10n settingsShowNSFWPublicRooms];
2380-
2381-
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.showNSFWPublicRooms;
2382-
labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
2383-
labelAndSwitchCell.mxkSwitch.enabled = YES;
2384-
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleNSFWPublicRoomsFiltering:) forControlEvents:UIControlEventTouchUpInside];
2385-
2386-
cell = labelAndSwitchCell;
2387-
}
2388-
else if (row == ADVANCED_CRASH_REPORT_INDEX)
2369+
if (row == ADVANCED_CRASH_REPORT_INDEX)
23892370
{
23902371
MXKTableViewCellWithLabelAndSwitch* sendCrashReportCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
23912372

@@ -4082,11 +4063,6 @@ - (void)togglePresenceOfflineMode:(UISwitch *)sender
40824063
}
40834064
}
40844065

4085-
- (void)toggleNSFWPublicRoomsFiltering:(UISwitch *)sender
4086-
{
4087-
RiotSettings.shared.showNSFWPublicRooms = sender.isOn;
4088-
}
4089-
40904066
- (void)toggleEnableRoomMessageBubbles:(UISwitch *)sender
40914067
{
40924068
RiotSettings.shared.roomScreenEnableMessageBubbles = sender.isOn;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
anal
2+
bbw
3+
bdsm
4+
beast
5+
bestiality
6+
blowjob
7+
bondage
8+
boobs
9+
clit
10+
cock
11+
cuck
12+
cum
13+
cunt
14+
daddy
15+
dick
16+
dildo
17+
erotic
18+
exhibitionism
19+
faggot
20+
femboy
21+
fisting
22+
flogging
23+
fmf
24+
foursome
25+
futa
26+
gangbang
27+
gore
28+
h3ntai
29+
handjob
30+
hentai
31+
incest
32+
jizz
33+
kink
34+
loli
35+
m4f
36+
masturbate
37+
masturbation
38+
mfm
39+
milf
40+
moresome
41+
naked
42+
neet
43+
nsfw
44+
nude
45+
nudity
46+
orgy
47+
pedo
48+
pegging
49+
penis
50+
petplay
51+
porn
52+
pussy
53+
rape
54+
rimming
55+
sadism
56+
sadomasochism
57+
sexy
58+
shota
59+
spank
60+
squirt
61+
strap-on
62+
threesome
63+
vagina
64+
vibrator
65+
voyeur
66+
watersports
67+
xxx
68+
zoo

0 commit comments

Comments
 (0)