feat: trust score filter
This commit is contained in:
parent
43f4c34fb3
commit
5f785e5553
48 changed files with 974 additions and 480 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { userIdToPubkey } from '@/lib/pubkey'
|
||||
import DataLoader from 'dataloader'
|
||||
|
||||
class FayanService {
|
||||
|
|
@ -22,7 +23,12 @@ class FayanService {
|
|||
return new Array(pubkeys.length).fill(null)
|
||||
}
|
||||
},
|
||||
{ maxBatchSize: 50 }
|
||||
{
|
||||
maxBatchSize: 50,
|
||||
cacheKeyFn: (userId) => {
|
||||
return userIdToPubkey(userId)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -45,9 +45,6 @@ class LocalStorageService {
|
|||
private accountFeedInfoMap: Record<string, TFeedInfo | undefined> = {}
|
||||
private mediaUploadService: string = DEFAULT_NIP_96_SERVICE
|
||||
private autoplay: boolean = true
|
||||
private hideUntrustedInteractions: boolean = false
|
||||
private hideUntrustedNotifications: boolean = false
|
||||
private hideUntrustedNotes: boolean = false
|
||||
private translationServiceConfigMap: Record<string, TTranslationServiceConfig> = {}
|
||||
private mediaUploadServiceConfigMap: Record<string, TMediaUploadServiceConfig> = {}
|
||||
private dismissedTooManyRelaysAlert: boolean = false
|
||||
|
|
@ -66,6 +63,7 @@ class LocalStorageService {
|
|||
private quickReaction: boolean = false
|
||||
private quickReactionEmoji: string | TEmoji = '+'
|
||||
private nsfwDisplayPolicy: TNsfwDisplayPolicy = NSFW_DISPLAY_POLICY.HIDE_CONTENT
|
||||
private minTrustScore: number = 40
|
||||
|
||||
constructor() {
|
||||
if (!LocalStorageService.instance) {
|
||||
|
|
@ -134,25 +132,6 @@ class LocalStorageService {
|
|||
|
||||
this.autoplay = window.localStorage.getItem(StorageKey.AUTOPLAY) !== 'false'
|
||||
|
||||
const hideUntrustedEvents =
|
||||
window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_EVENTS) === 'true'
|
||||
const storedHideUntrustedInteractions = window.localStorage.getItem(
|
||||
StorageKey.HIDE_UNTRUSTED_INTERACTIONS
|
||||
)
|
||||
const storedHideUntrustedNotifications = window.localStorage.getItem(
|
||||
StorageKey.HIDE_UNTRUSTED_NOTIFICATIONS
|
||||
)
|
||||
const storedHideUntrustedNotes = window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_NOTES)
|
||||
this.hideUntrustedInteractions = storedHideUntrustedInteractions
|
||||
? storedHideUntrustedInteractions === 'true'
|
||||
: hideUntrustedEvents
|
||||
this.hideUntrustedNotifications = storedHideUntrustedNotifications
|
||||
? storedHideUntrustedNotifications === 'true'
|
||||
: hideUntrustedEvents
|
||||
this.hideUntrustedNotes = storedHideUntrustedNotes
|
||||
? storedHideUntrustedNotes === 'true'
|
||||
: hideUntrustedEvents
|
||||
|
||||
const translationServiceConfigMapStr = window.localStorage.getItem(
|
||||
StorageKey.TRANSLATION_SERVICE_CONFIG_MAP
|
||||
)
|
||||
|
|
@ -274,6 +253,28 @@ class LocalStorageService {
|
|||
this.quickReactionEmoji = quickReactionEmojiStr
|
||||
}
|
||||
|
||||
const minTrustScoreStr = window.localStorage.getItem(StorageKey.MIN_TRUST_SCORE)
|
||||
if (minTrustScoreStr) {
|
||||
const score = parseInt(minTrustScoreStr, 10)
|
||||
if (!isNaN(score) && score >= 0 && score <= 100) {
|
||||
this.minTrustScore = score
|
||||
}
|
||||
} else {
|
||||
const storedHideUntrustedInteractions =
|
||||
window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_INTERACTIONS) === 'true'
|
||||
const storedHideUntrustedNotifications =
|
||||
window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_NOTIFICATIONS) === 'true'
|
||||
const storedHideUntrustedNotes =
|
||||
window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_NOTES) === 'true'
|
||||
if (
|
||||
storedHideUntrustedInteractions ||
|
||||
storedHideUntrustedNotifications ||
|
||||
storedHideUntrustedNotes
|
||||
) {
|
||||
this.minTrustScore = 100 // set to max if any of the old settings were true
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up deprecated data
|
||||
window.localStorage.removeItem(StorageKey.PINNED_PUBKEYS)
|
||||
window.localStorage.removeItem(StorageKey.ACCOUNT_PROFILE_EVENT_MAP)
|
||||
|
|
@ -425,39 +426,6 @@ class LocalStorageService {
|
|||
window.localStorage.setItem(StorageKey.AUTOPLAY, autoplay.toString())
|
||||
}
|
||||
|
||||
getHideUntrustedInteractions() {
|
||||
return this.hideUntrustedInteractions
|
||||
}
|
||||
|
||||
setHideUntrustedInteractions(hideUntrustedInteractions: boolean) {
|
||||
this.hideUntrustedInteractions = hideUntrustedInteractions
|
||||
window.localStorage.setItem(
|
||||
StorageKey.HIDE_UNTRUSTED_INTERACTIONS,
|
||||
hideUntrustedInteractions.toString()
|
||||
)
|
||||
}
|
||||
|
||||
getHideUntrustedNotifications() {
|
||||
return this.hideUntrustedNotifications
|
||||
}
|
||||
|
||||
setHideUntrustedNotifications(hideUntrustedNotifications: boolean) {
|
||||
this.hideUntrustedNotifications = hideUntrustedNotifications
|
||||
window.localStorage.setItem(
|
||||
StorageKey.HIDE_UNTRUSTED_NOTIFICATIONS,
|
||||
hideUntrustedNotifications.toString()
|
||||
)
|
||||
}
|
||||
|
||||
getHideUntrustedNotes() {
|
||||
return this.hideUntrustedNotes
|
||||
}
|
||||
|
||||
setHideUntrustedNotes(hideUntrustedNotes: boolean) {
|
||||
this.hideUntrustedNotes = hideUntrustedNotes
|
||||
window.localStorage.setItem(StorageKey.HIDE_UNTRUSTED_NOTES, hideUntrustedNotes.toString())
|
||||
}
|
||||
|
||||
getTranslationServiceConfig(pubkey?: string | null) {
|
||||
return this.translationServiceConfigMap[pubkey ?? '_'] ?? { service: 'jumble' }
|
||||
}
|
||||
|
|
@ -633,6 +601,17 @@ class LocalStorageService {
|
|||
this.nsfwDisplayPolicy = policy
|
||||
window.localStorage.setItem(StorageKey.NSFW_DISPLAY_POLICY, policy)
|
||||
}
|
||||
|
||||
getMinTrustScore() {
|
||||
return this.minTrustScore
|
||||
}
|
||||
|
||||
setMinTrustScore(score: number) {
|
||||
if (score >= 0 && score <= 100) {
|
||||
this.minTrustScore = score
|
||||
window.localStorage.setItem(StorageKey.MIN_TRUST_SCORE, score.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const instance = new LocalStorageService()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue