Merge pull request #7803 from element-hq/stefan/decency

Better explicit term room directory search filtering
This commit is contained in:
Stefan Ceriu
2024-06-12 10:48:02 +03:00
committed by GitHub
8 changed files with 95 additions and 65 deletions

View File

@@ -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

View File

@@ -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<String?>(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

View File

@@ -471,7 +471,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
if (!_publicRoomsDirectoryDataSource)
{
_publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession];
_publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms;
_publicRoomsDirectoryDataSource.delegate = self;
}

View File

@@ -141,8 +141,6 @@
// 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];

View File

@@ -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.

View File

@@ -46,6 +46,8 @@ static NSString *const kNSFWKeyword = @"nsfw";
NSString *nextBatch;
}
@property (nonatomic, strong) NSRegularExpression *forbiddenTermsRegex;
@end
@implementation PublicRoomsDirectoryDataSource
@@ -57,6 +59,15 @@ static NSString *const kNSFWKeyword = @"nsfw";
{
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;
}
@@ -155,16 +166,6 @@ static NSString *const kNSFWKeyword = @"nsfw";
}
}
- (void)setShowNSFWRooms:(BOOL)showNSFWRooms
{
if (showNSFWRooms != _showNSFWRooms)
{
_showNSFWRooms = showNSFWRooms;
[self resetPagination];
}
}
- (NSUInteger)roomsCount
{
return rooms.count;
@@ -254,14 +255,7 @@ static NSString *const kNSFWKeyword = @"nsfw";
NSArray<MXPublicRoom*> *publicRooms;
if (self.showNSFWRooms)
{
publicRooms = publicRoomsResponse.chunk;
}
else
{
publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk containingKeyword:kNSFWKeyword];
}
publicRooms = [self filterPublicRooms:publicRoomsResponse.chunk];
[self->rooms addObjectsFromArray:publicRooms];
self->nextBatch = publicRoomsResponse.nextBatch;
@@ -338,15 +332,23 @@ static NSString *const kNSFWKeyword = @"nsfw";
}
}
- (NSArray<MXPublicRoom*>*)filterPublicRooms:(NSArray<MXPublicRoom*>*)publicRooms containingKeyword:(NSString*)keyword
- (NSArray<MXPublicRoom*>*)filterPublicRooms:(NSArray<MXPublicRoom*>*)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];
}
}

View File

@@ -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 @@ SSOAuthenticationPresenterDelegate>
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 @@ SSOAuthenticationPresenterDelegate>
}
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 @@ SSOAuthenticationPresenterDelegate>
}
}
- (void)toggleNSFWPublicRoomsFiltering:(UISwitch *)sender
{
RiotSettings.shared.showNSFWPublicRooms = sender.isOn;
}
- (void)toggleEnableRoomMessageBubbles:(UISwitch *)sender
{
RiotSettings.shared.roomScreenEnableMessageBubbles = sender.isOn;

View File

@@ -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