diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index b1ed12e1f..bce441f81 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -596,6 +596,7 @@ Tap the + to start adding people."; "settings_identity_server_no_is" = "No identity server configured"; "settings_identity_server_no_is_description" = "You are not currently using an identity server. To discover and be discoverable by existing contacts you know, add one above."; +"settings_show_NSFW_public_rooms" = "Show NSFW public rooms"; // Security settings "security_settings_title" = "Security"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 4c32ffefe..31f1c3260 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -4278,6 +4278,10 @@ internal enum VectorL10n { internal static var settingsShowDecryptedContent: String { return VectorL10n.tr("Vector", "settings_show_decrypted_content") } + /// Show NSFW public rooms + internal static var settingsShowNSFWPublicRooms: String { + return VectorL10n.tr("Vector", "settings_show_NSFW_public_rooms") + } /// Sign Out internal static var settingsSignOut: String { return VectorL10n.tr("Vector", "settings_sign_out") diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 43933b026..5627d7369 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -36,6 +36,7 @@ final class RiotSettings: NSObject { static let hideVerifyThisSessionAlert = "hideVerifyThisSessionAlert" static let hideReviewSessionsAlert = "hideReviewSessionsAlert" static let matrixApps = "matrixApps" + static let showNSFWPublicRooms = "showNSFWPublicRooms" } static let shared = RiotSettings() @@ -119,6 +120,15 @@ final class RiotSettings: NSObject { } } + /// Indicate to show Not Safe For Work public rooms. + var showNSFWPublicRooms: Bool { + get { + return defaults.bool(forKey: UserDefaultsKeys.showNSFWPublicRooms) + } set { + defaults.set(newValue, forKey: UserDefaultsKeys.showNSFWPublicRooms) + } + } + // MARK: User interface var userInterfaceTheme: String? { diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 6b20cf3ea..fdac6daff 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -132,6 +132,7 @@ enum OTHER_TERM_CONDITIONS_INDEX, OTHER_PRIVACY_INDEX, OTHER_THIRD_PARTY_INDEX, + OTHER_SHOW_NSFW_ROOMS_INDEX, OTHER_CRASH_REPORT_INDEX, OTHER_ENABLE_RAGESHAKE_INDEX, OTHER_MARK_ALL_AS_READ_INDEX, @@ -435,6 +436,8 @@ TableViewSectionsDelegate> [sectionOther addRowWithTag:OTHER_TERM_CONDITIONS_INDEX]; [sectionOther addRowWithTag:OTHER_PRIVACY_INDEX]; [sectionOther addRowWithTag:OTHER_THIRD_PARTY_INDEX]; + [sectionOther addRowWithTag:OTHER_SHOW_NSFW_ROOMS_INDEX]; + if (BuildSettings.settingsScreenAllowChangingCrashUsageDataSettings) { [sectionOther addRowWithTag:OTHER_CRASH_REPORT_INDEX]; @@ -2104,6 +2107,19 @@ TableViewSectionsDelegate> cell = thirdPartyCell; } + else if (row == OTHER_SHOW_NSFW_ROOMS_INDEX) + { + MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; + + labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_NSFW_public_rooms", @"Vector", nil); + + 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 == OTHER_CRASH_REPORT_INDEX) { MXKTableViewCellWithLabelAndSwitch* sendCrashReportCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; @@ -3599,6 +3615,18 @@ TableViewSectionsDelegate> animated:YES]; } +- (void)toggleNSFWPublicRoomsFiltering:(id)sender +{ + if (sender && [sender isKindOfClass:UISwitch.class]) + { + UISwitch *switchButton = (UISwitch*)sender; + + RiotSettings.shared.showNSFWPublicRooms = switchButton.isOn; + + [self.tableView reloadData]; + } +} + #pragma mark - TextField listener - (IBAction)textFieldDidChange:(id)sender