Escape muted words and drop blank ones so a list from another client can't throw or mute everyone
This commit is contained in:
parent
ada5496abe
commit
c49650bbca
1 changed files with 6 additions and 5 deletions
|
|
@ -181,11 +181,12 @@ export const isEventMuted = withGetter(
|
||||||
const mutedPubkeys = new Set(tagValues(hexTags("p"), tags))
|
const mutedPubkeys = new Set(tagValues(hexTags("p"), tags))
|
||||||
const mutedAddresses = new Set(tagValues(addressTags("a"), tags))
|
const mutedAddresses = new Set(tagValues(addressTags("a"), tags))
|
||||||
const mutedTopics = new Set(tagValues(topicTags("t"), tags))
|
const mutedTopics = new Set(tagValues(topicTags("t"), tags))
|
||||||
|
// Words come from any client, so a blank or a regex character must not mute everyone or throw.
|
||||||
const mutedWords = tagValues(tagSpec("word"), tags)
|
const mutedWords = tagValues(tagSpec("word"), tags)
|
||||||
const regex =
|
.map(word => word.toLowerCase().trim())
|
||||||
mutedWords.length > 0
|
.filter(Boolean)
|
||||||
? new RegExp(`\\b(${mutedWords.map(w => w.toLowerCase().trim()).join("|")})\\b`)
|
.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
||||||
: undefined
|
const regex = mutedWords.length > 0 ? new RegExp(`\\b(${mutedWords.join("|")})\\b`) : undefined
|
||||||
|
|
||||||
return (e: TrustedEvent) => {
|
return (e: TrustedEvent) => {
|
||||||
if (!$muteList) {
|
if (!$muteList) {
|
||||||
|
|
@ -216,7 +217,7 @@ export const isEventMuted = withGetter(
|
||||||
if (profile?.display().toLowerCase().match(regex)) {
|
if (profile?.display().toLowerCase().match(regex)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (profile?.nip05()?.match(regex)) {
|
if (profile?.nip05()?.toLowerCase().match(regex)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue