feat: mute
This commit is contained in:
parent
34ff0cd314
commit
cbae26e492
26 changed files with 564 additions and 45 deletions
|
|
@ -1,10 +1,7 @@
|
|||
import { BIG_RELAY_URLS } from '@/constants'
|
||||
import {
|
||||
getFollowingsFromFollowListEvent,
|
||||
getProfileFromProfileEvent,
|
||||
getRelayListFromRelayListEvent
|
||||
} from '@/lib/event'
|
||||
import { getProfileFromProfileEvent, getRelayListFromRelayListEvent } from '@/lib/event'
|
||||
import { formatPubkey, userIdToPubkey } from '@/lib/pubkey'
|
||||
import { extractPubkeysFromEventTags } from '@/lib/tag'
|
||||
import { TDraftEvent, TProfile, TRelayInfo, TRelayList } from '@/types'
|
||||
import { sha256 } from '@noble/hashes/sha2'
|
||||
import DataLoader from 'dataloader'
|
||||
|
|
@ -437,7 +434,7 @@ class ClientService extends EventTarget {
|
|||
|
||||
async fetchFollowings(pubkey: string) {
|
||||
const followListEvent = await this.fetchFollowListEvent(pubkey)
|
||||
return followListEvent ? getFollowingsFromFollowListEvent(followListEvent) : []
|
||||
return followListEvent ? extractPubkeysFromEventTags(followListEvent.tags) : []
|
||||
}
|
||||
|
||||
updateFollowListCache(pubkey: string, event: NEvent) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class StorageService {
|
|||
private currentAccount: TAccount | null = null
|
||||
private accountRelayListEventMap: Record<string, Event | undefined> = {} // pubkey -> relayListEvent
|
||||
private accountFollowListEventMap: Record<string, Event | undefined> = {} // pubkey -> followListEvent
|
||||
private accountMuteListEventMap: Record<string, Event | undefined> = {} // pubkey -> muteListEvent
|
||||
private accountProfileEventMap: Record<string, Event | undefined> = {} // pubkey -> profileEvent
|
||||
|
||||
constructor() {
|
||||
|
|
@ -60,6 +61,12 @@ class StorageService {
|
|||
this.accountFollowListEventMap = accountFollowListEventMapStr
|
||||
? JSON.parse(accountFollowListEventMapStr)
|
||||
: {}
|
||||
const accountMuteListEventMapStr = window.localStorage.getItem(
|
||||
StorageKey.ACCOUNT_MUTE_LIST_EVENT_MAP
|
||||
)
|
||||
this.accountMuteListEventMap = accountMuteListEventMapStr
|
||||
? JSON.parse(accountMuteListEventMapStr)
|
||||
: {}
|
||||
const accountProfileEventMapStr = window.localStorage.getItem(
|
||||
StorageKey.ACCOUNT_PROFILE_EVENT_MAP
|
||||
)
|
||||
|
|
@ -176,12 +183,17 @@ class StorageService {
|
|||
this.accounts = this.accounts.filter((act) => !isSameAccount(act, account))
|
||||
delete this.accountFollowListEventMap[account.pubkey]
|
||||
delete this.accountRelayListEventMap[account.pubkey]
|
||||
delete this.accountMuteListEventMap[account.pubkey]
|
||||
delete this.accountProfileEventMap[account.pubkey]
|
||||
window.localStorage.setItem(StorageKey.ACCOUNTS, JSON.stringify(this.accounts))
|
||||
window.localStorage.setItem(
|
||||
StorageKey.ACCOUNT_FOLLOW_LIST_EVENT_MAP,
|
||||
JSON.stringify(this.accountFollowListEventMap)
|
||||
)
|
||||
window.localStorage.setItem(
|
||||
StorageKey.ACCOUNT_MUTE_LIST_EVENT_MAP,
|
||||
JSON.stringify(this.accountMuteListEventMap)
|
||||
)
|
||||
window.localStorage.setItem(
|
||||
StorageKey.ACCOUNT_RELAY_LIST_EVENT_MAP,
|
||||
JSON.stringify(this.accountRelayListEventMap)
|
||||
|
|
@ -244,6 +256,26 @@ class StorageService {
|
|||
return true
|
||||
}
|
||||
|
||||
getAccountMuteListEvent(pubkey: string) {
|
||||
return this.accountMuteListEventMap[pubkey]
|
||||
}
|
||||
|
||||
setAccountMuteListEvent(muteListEvent: Event) {
|
||||
const pubkey = muteListEvent.pubkey
|
||||
if (
|
||||
this.accountMuteListEventMap[pubkey] &&
|
||||
this.accountMuteListEventMap[pubkey].created_at > muteListEvent.created_at
|
||||
) {
|
||||
return false
|
||||
}
|
||||
this.accountMuteListEventMap[pubkey] = muteListEvent
|
||||
window.localStorage.setItem(
|
||||
StorageKey.ACCOUNT_MUTE_LIST_EVENT_MAP,
|
||||
JSON.stringify(this.accountMuteListEventMap)
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
getAccountProfileEvent(pubkey: string) {
|
||||
return this.accountProfileEventMap[pubkey]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue