-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add safe search filter for NSFW rooms (#208)
Fix #89
- Loading branch information
1 parent
858c9dd
commit b70439e
Showing
13 changed files
with
547 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const assert = require('./assert'); | ||
|
||
const LOCAL_STORAGE_KEYS = { | ||
addedHomeservers: 'addedHomeservers', | ||
safeSearchEnabled: 'safeSearchEnabled', | ||
debugActiveDateIntersectionObserver: 'debugActiveDateIntersectionObserver', | ||
}; | ||
|
||
// Just make sure they match for sanity. All we really care about is that they are | ||
// unique amongst each other. | ||
Object.keys(LOCAL_STORAGE_KEYS).every((key) => { | ||
const value = LOCAL_STORAGE_KEYS[key]; | ||
const doesKeyMatchValue = key === value; | ||
assert( | ||
doesKeyMatchValue, | ||
`LOCAL_STORAGE_KEYS should have keys that are the same as their values for sanity but saw ${key}=${value}.` | ||
); | ||
}); | ||
|
||
// Make sure all of the keys/values are unique | ||
assert( | ||
new Set(Object.values(LOCAL_STORAGE_KEYS)).length !== Object.values(LOCAL_STORAGE_KEYS).length, | ||
'Duplicate values in LOCAL_STORAGE_KEYS. They should be unique otherwise ' + | ||
'there will be collisions and LocalStorage will be overwritten.' | ||
); | ||
|
||
module.exports = LOCAL_STORAGE_KEYS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
|
||
const { ViewModel } = require('hydrogen-view-sdk'); | ||
|
||
const assert = require('matrix-public-archive-shared/lib/assert'); | ||
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator'); | ||
|
||
class RoomCardViewModel extends ViewModel { | ||
constructor(options) { | ||
super(options); | ||
const { room, basePath, homeserverUrlToPullMediaFrom, viaServers } = options; | ||
assert(room); | ||
assert(basePath); | ||
assert(homeserverUrlToPullMediaFrom); | ||
assert(viaServers); | ||
|
||
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath); | ||
|
||
this._roomId = room.room_id; | ||
this._canonicalAlias = room.canonical_alias; | ||
this._name = room.name; | ||
this._mxcAvatarUrl = room.avatar_url; | ||
this._homeserverUrlToPullMediaFrom = homeserverUrlToPullMediaFrom; | ||
this._numJoinedMembers = room.num_joined_members; | ||
this._topic = room.topic; | ||
|
||
this._viaServers = viaServers; | ||
|
||
this._blockedBySafeSearch = false; | ||
} | ||
|
||
get roomId() { | ||
return this._roomId; | ||
} | ||
|
||
get canonicalAlias() { | ||
return this._canonicalAlias; | ||
} | ||
|
||
get name() { | ||
return this._name; | ||
} | ||
|
||
get mxcAvatarUrl() { | ||
return this._mxcAvatarUrl; | ||
} | ||
|
||
get homeserverUrlToPullMediaFrom() { | ||
return this._homeserverUrlToPullMediaFrom; | ||
} | ||
|
||
get numJoinedMembers() { | ||
return this._numJoinedMembers; | ||
} | ||
|
||
get topic() { | ||
return this._topic; | ||
} | ||
|
||
get archiveRoomUrl() { | ||
return this._matrixPublicArchiveURLCreator.archiveUrlForRoom( | ||
this._canonicalAlias || this._roomId, | ||
{ | ||
// Only include via servers when we have to fallback to the room ID | ||
viaServers: this._canonicalAlias ? undefined : this._viaServers, | ||
} | ||
); | ||
} | ||
|
||
get blockedBySafeSearch() { | ||
return this._blockedBySafeSearch; | ||
} | ||
|
||
setBlockedBySafeSearch(blockedBySafeSearch) { | ||
if (blockedBySafeSearch !== this._blockedBySafeSearch) { | ||
this._blockedBySafeSearch = blockedBySafeSearch; | ||
this.emitChange('blockedBySafeSearch'); | ||
} | ||
} | ||
} | ||
|
||
module.exports = RoomCardViewModel; |
Oops, something went wrong.