Make sure nsfw rooms are always page-loaded as blocked

This commit is contained in:
Eric Eastwood 2023-05-02 18:12:30 -05:00
parent 931cf1cf58
commit 647ebc4f98
1 changed files with 15 additions and 9 deletions

View File

@ -230,32 +230,38 @@ class RoomDirectoryViewModel extends ViewModel {
} }
loadSafeSearchEnabledFromPersistence() { loadSafeSearchEnabledFromPersistence() {
// Safe search is enabled by default and only disabled with the correct 'false' value
let safeSearchEnabled = true;
if (window.localStorage) { if (window.localStorage) {
const safeSearchEnabledFromPersistence = window.localStorage.getItem( const safeSearchEnabledFromPersistence = window.localStorage.getItem(
LOCAL_STORAGE_KEYS.safeSearch LOCAL_STORAGE_KEYS.safeSearch
); );
// Safe search is enabled by default and only disabled with the correct 'false' value
let safeSearchEnabled = true;
if (safeSearchEnabledFromPersistence === 'false') { if (safeSearchEnabledFromPersistence === 'false') {
safeSearchEnabled = false; safeSearchEnabled = false;
} }
this.setSafeSearchEnabled(safeSearchEnabled);
return;
} else { } else {
console.warn( console.warn(
`Skipping \`${LOCAL_STORAGE_KEYS.safeSearch}\` read from LocalStorage since LocalStorage is not available` `Skipping \`${LOCAL_STORAGE_KEYS.safeSearch}\` read from LocalStorage since LocalStorage is not available`
); );
} }
this.setSafeSearchEnabled(safeSearchEnabled);
} }
setSafeSearchEnabled(safeSearchEnabled) { setSafeSearchEnabled(safeSearchEnabled) {
this._safeSearchEnabled = safeSearchEnabled; this._safeSearchEnabled = safeSearchEnabled;
window.localStorage.setItem( if (window.localStorage) {
LOCAL_STORAGE_KEYS.safeSearch, window.localStorage.setItem(
safeSearchEnabled ? 'true' : 'false' LOCAL_STORAGE_KEYS.safeSearch,
); safeSearchEnabled ? 'true' : 'false'
);
} else {
console.warn(
`Skipping \`${LOCAL_STORAGE_KEYS.safeSearch}\` write to LocalStorage since LocalStorage is not available`
);
}
if (safeSearchEnabled) { if (safeSearchEnabled) {
this._roomCardViewModelsFilterMap.setApply((roomId, vm) => { this._roomCardViewModelsFilterMap.setApply((roomId, vm) => {