feat: support configurable trust score threshold per context
This commit is contained in:
parent
28a1b3096a
commit
ca9610b711
46 changed files with 350 additions and 122 deletions
|
|
@ -6,10 +6,11 @@ import { useUserTrust } from '@/providers/UserTrustProvider'
|
|||
import { NostrEvent } from 'nostr-tools'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useAllDescendantThreads } from './useThread'
|
||||
import { SPECIAL_TRUST_SCORE_FILTER_ID } from '@/constants'
|
||||
|
||||
export function useFilteredReplies(stuffKey: string) {
|
||||
const { pubkey } = useNostr()
|
||||
const { minTrustScore, meetsMinTrustScore } = useUserTrust()
|
||||
const { getMinTrustScore, meetsMinTrustScore } = useUserTrust()
|
||||
const { mutePubkeySet } = useMuteList()
|
||||
const { hideContentMentioningMutedUsers } = useContentPolicy()
|
||||
const allThreads = useAllDescendantThreads(stuffKey)
|
||||
|
|
@ -22,6 +23,7 @@ export function useFilteredReplies(stuffKey: string) {
|
|||
const thread = allThreads.get(stuffKey) || []
|
||||
const filtered: NostrEvent[] = []
|
||||
|
||||
const trustScoreThreshold = getMinTrustScore(SPECIAL_TRUST_SCORE_FILTER_ID.INTERACTIONS)
|
||||
await Promise.all(
|
||||
thread.map(async (evt) => {
|
||||
const key = getEventKey(evt)
|
||||
|
|
@ -31,7 +33,7 @@ export function useFilteredReplies(stuffKey: string) {
|
|||
if (mutePubkeySet.has(evt.pubkey)) return
|
||||
if (hideContentMentioningMutedUsers && isMentioningMutedUsers(evt, mutePubkeySet)) return
|
||||
|
||||
const meetsTrust = await meetsMinTrustScore(evt.pubkey)
|
||||
const meetsTrust = await meetsMinTrustScore(evt.pubkey, trustScoreThreshold)
|
||||
if (!meetsTrust) {
|
||||
const replyKey = getEventKey(evt)
|
||||
const repliesForThisReply = allThreads.get(replyKey)
|
||||
|
|
@ -39,7 +41,7 @@ export function useFilteredReplies(stuffKey: string) {
|
|||
if (repliesForThisReply && repliesForThisReply.length > 0) {
|
||||
let hasTrustedReply = false
|
||||
for (const reply of repliesForThisReply) {
|
||||
if (await meetsMinTrustScore(reply.pubkey)) {
|
||||
if (await meetsMinTrustScore(reply.pubkey, trustScoreThreshold)) {
|
||||
hasTrustedReply = true
|
||||
break
|
||||
}
|
||||
|
|
@ -63,7 +65,7 @@ export function useFilteredReplies(stuffKey: string) {
|
|||
allThreads,
|
||||
mutePubkeySet,
|
||||
hideContentMentioningMutedUsers,
|
||||
minTrustScore,
|
||||
getMinTrustScore,
|
||||
meetsMinTrustScore
|
||||
])
|
||||
|
||||
|
|
@ -84,7 +86,7 @@ export function useFilteredReplies(stuffKey: string) {
|
|||
export function useFilteredAllReplies(stuffKey: string) {
|
||||
const { pubkey } = useNostr()
|
||||
const allThreads = useAllDescendantThreads(stuffKey)
|
||||
const { minTrustScore, meetsMinTrustScore } = useUserTrust()
|
||||
const { getMinTrustScore, meetsMinTrustScore } = useUserTrust()
|
||||
const { mutePubkeySet } = useMuteList()
|
||||
const { hideContentMentioningMutedUsers } = useContentPolicy()
|
||||
const [replies, setReplies] = useState<NostrEvent[]>([])
|
||||
|
|
@ -94,6 +96,7 @@ export function useFilteredAllReplies(stuffKey: string) {
|
|||
const filterReplies = async () => {
|
||||
const replyKeySet = new Set<string>()
|
||||
const replyEvents: NostrEvent[] = []
|
||||
const trustScoreThreshold = getMinTrustScore(SPECIAL_TRUST_SCORE_FILTER_ID.INTERACTIONS)
|
||||
|
||||
let parentKeys = [stuffKey]
|
||||
while (parentKeys.length > 0) {
|
||||
|
|
@ -108,7 +111,7 @@ export function useFilteredAllReplies(stuffKey: string) {
|
|||
if (hideContentMentioningMutedUsers && isMentioningMutedUsers(evt, mutePubkeySet))
|
||||
return
|
||||
|
||||
const meetsTrust = await meetsMinTrustScore(evt.pubkey)
|
||||
const meetsTrust = await meetsMinTrustScore(evt.pubkey, trustScoreThreshold)
|
||||
if (!meetsTrust) {
|
||||
const replyKey = getEventKey(evt)
|
||||
const repliesForThisReply = allThreads.get(replyKey)
|
||||
|
|
@ -116,7 +119,7 @@ export function useFilteredAllReplies(stuffKey: string) {
|
|||
if (repliesForThisReply && repliesForThisReply.length > 0) {
|
||||
let hasTrustedReply = false
|
||||
for (const reply of repliesForThisReply) {
|
||||
if (await meetsMinTrustScore(reply.pubkey)) {
|
||||
if (await meetsMinTrustScore(reply.pubkey, trustScoreThreshold)) {
|
||||
hasTrustedReply = true
|
||||
break
|
||||
}
|
||||
|
|
@ -141,7 +144,7 @@ export function useFilteredAllReplies(stuffKey: string) {
|
|||
allThreads,
|
||||
mutePubkeySet,
|
||||
hideContentMentioningMutedUsers,
|
||||
minTrustScore,
|
||||
getMinTrustScore,
|
||||
meetsMinTrustScore
|
||||
])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue