Skip to content

Commit

Permalink
Fix isEventMuted
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Staab committed Feb 17, 2025
1 parent 229d670 commit a989af2
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/engine/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
pushToMapKey,
setContext,
simpleCache,
cached,
sort,
take,
uniq,
Expand Down Expand Up @@ -361,28 +362,32 @@ export const isEventMuted = withGetter(
? new RegExp(`\\b(${words.map(w => w.toLowerCase().trim()).join("|")})\\b`)
: null

return simpleCache(([e, strict = false]: [e: HashedEvent, strict?: boolean]) => {
if (!$pubkey || !e.pubkey) return false
return cached({
maxSize: 5000,
getKey: ([e, strict = false]: [e: HashedEvent, strict?: boolean]) => `${e.id}:${strict}`,
getValue: ([e, strict = false]: [e: HashedEvent, strict?: boolean]) => {
if (!$pubkey || !e.pubkey) return false

const {roots, replies} = getReplyTagValues(e.tags)
const {roots, replies} = getReplyTagValues(e.tags)

if ([e.id, e.pubkey, ...roots, ...replies].some(x => x !== $pubkey && $userMutes.has(x)))
return true
if ([e.id, e.pubkey, ...roots, ...replies].some(x => x !== $pubkey && $userMutes.has(x)))
return true

if (regex) {
if (e.content?.toLowerCase().match(regex)) return true
if (displayProfileByPubkey(e.pubkey).toLowerCase().match(regex)) return true
}
if (regex) {
if (e.content?.toLowerCase().match(regex)) return true
if (displayProfileByPubkey(e.pubkey).toLowerCase().match(regex)) return true
}

if (strict || $userFollows.has(e.pubkey)) return false
if (strict || $userFollows.has(e.pubkey)) return false

const wotScore = getUserWotScore(e.pubkey)
const okWot = wotScore >= minWot
const powDifficulty = Number(getTag("nonce", e.tags)?.[2] || "0")
const isValidPow = getPow(e.id) >= powDifficulty
const okPow = isValidPow && powDifficulty > minPow
const wotScore = getUserWotScore(e.pubkey)
const okWot = wotScore >= minWot
const powDifficulty = Number(getTag("nonce", e.tags)?.[2] || "0")
const isValidPow = getPow(e.id) >= powDifficulty
const okPow = isValidPow && powDifficulty > minPow

return !okWot && !okPow
return !okWot && !okPow
},
})
},
),
Expand Down

0 comments on commit a989af2

Please sign in to comment.