feat: support for generic repost
This commit is contained in:
parent
14b3fbd496
commit
a40d7b0676
11 changed files with 92 additions and 68 deletions
|
|
@ -23,6 +23,7 @@ import {
|
|||
TThemeSetting,
|
||||
TTranslationServiceConfig
|
||||
} from '@/types'
|
||||
import { kinds } from 'nostr-tools'
|
||||
|
||||
class LocalStorageService {
|
||||
static instance: LocalStorageService
|
||||
|
|
@ -181,10 +182,13 @@ class LocalStorageService {
|
|||
showKindSet.delete(24236) // remove typo kind
|
||||
showKindSet.add(ExtendedKind.ADDRESSABLE_SHORT_VIDEO)
|
||||
}
|
||||
if (showKindsVersion < 4 && showKindSet.has(kinds.Repost)) {
|
||||
showKindSet.add(kinds.GenericRepost)
|
||||
}
|
||||
this.showKinds = Array.from(showKindSet)
|
||||
}
|
||||
window.localStorage.setItem(StorageKey.SHOW_KINDS, JSON.stringify(this.showKinds))
|
||||
window.localStorage.setItem(StorageKey.SHOW_KINDS_VERSION, '3')
|
||||
window.localStorage.setItem(StorageKey.SHOW_KINDS_VERSION, '4')
|
||||
|
||||
this.hideContentMentioningMutedUsers =
|
||||
window.localStorage.getItem(StorageKey.HIDE_CONTENT_MENTIONING_MUTED_USERS) === 'true'
|
||||
|
|
|
|||
|
|
@ -107,7 +107,10 @@ class StuffStatsService {
|
|||
? {
|
||||
'#e': [event.id],
|
||||
authors: [pubkey],
|
||||
kinds: [kinds.Reaction, kinds.Repost]
|
||||
kinds:
|
||||
event.kind === kinds.ShortTextNote
|
||||
? [kinds.Reaction, kinds.Repost]
|
||||
: [kinds.Reaction, kinds.Repost, kinds.GenericRepost]
|
||||
}
|
||||
: {
|
||||
'#i': [externalContent],
|
||||
|
|
@ -120,7 +123,7 @@ class StuffStatsService {
|
|||
filters.push({
|
||||
'#a': [replaceableCoordinate],
|
||||
authors: [pubkey],
|
||||
kinds: [kinds.Reaction, kinds.Repost]
|
||||
kinds: [kinds.Reaction, kinds.Repost, kinds.GenericRepost]
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +221,7 @@ class StuffStatsService {
|
|||
targetKey = this.addLikeByEvent(evt)
|
||||
} else if (evt.kind === ExtendedKind.EXTERNAL_CONTENT_REACTION) {
|
||||
targetKey = this.addExternalContentLikeByEvent(evt)
|
||||
} else if (evt.kind === kinds.Repost) {
|
||||
} else if (evt.kind === kinds.Repost || evt.kind === kinds.GenericRepost) {
|
||||
targetKey = this.addRepostByEvent(evt)
|
||||
} else if (evt.kind === kinds.Zap) {
|
||||
targetKey = this.addZapByEvent(evt)
|
||||
|
|
@ -291,18 +294,25 @@ class StuffStatsService {
|
|||
}
|
||||
|
||||
private addRepostByEvent(evt: Event) {
|
||||
const eventId = evt.tags.find(tagNameEquals('e'))?.[1]
|
||||
if (!eventId) return
|
||||
let targetEventKey
|
||||
targetEventKey = evt.tags.find(tagNameEquals('a'))?.[1]
|
||||
if (!targetEventKey) {
|
||||
targetEventKey = evt.tags.find(tagNameEquals('e'))?.[1]
|
||||
}
|
||||
|
||||
const old = this.stuffStatsMap.get(eventId) || {}
|
||||
if (!targetEventKey) {
|
||||
return
|
||||
}
|
||||
|
||||
const old = this.stuffStatsMap.get(targetEventKey) || {}
|
||||
const repostPubkeySet = old.repostPubkeySet || new Set()
|
||||
const reposts = old.reposts || []
|
||||
if (repostPubkeySet.has(evt.pubkey)) return
|
||||
|
||||
repostPubkeySet.add(evt.pubkey)
|
||||
reposts.push({ id: evt.id, pubkey: evt.pubkey, created_at: evt.created_at })
|
||||
this.stuffStatsMap.set(eventId, { ...old, repostPubkeySet, reposts })
|
||||
return eventId
|
||||
this.stuffStatsMap.set(targetEventKey, { ...old, repostPubkeySet, reposts })
|
||||
return targetEventKey
|
||||
}
|
||||
|
||||
private addZapByEvent(evt: Event) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue