fix: bug of lost followers

This commit is contained in:
codytseng
2025-02-12 22:59:09 +08:00
parent d5f46690c4
commit 5e3fd93a23
4 changed files with 14 additions and 17 deletions

View File

@@ -58,9 +58,8 @@ export function FollowListProvider({ children }: { children: React.ReactNode })
}, [accountPubkey]) }, [accountPubkey])
const updateFollowListEvent = async (event: Event) => { const updateFollowListEvent = async (event: Event) => {
const isNew = await indexedDb.putReplaceableEvent(event) const newEvent = await indexedDb.putReplaceableEvent(event)
if (!isNew) return setFollowListEvent(newEvent)
setFollowListEvent(event)
} }
const follow = async (pubkey: string) => { const follow = async (pubkey: string) => {

View File

@@ -47,9 +47,9 @@ export function MuteListProvider({ children }: { children: React.ReactNode }) {
}) })
const muteEvent = getLatestEvent(events) as Event | undefined const muteEvent = getLatestEvent(events) as Event | undefined
if (muteEvent) { if (muteEvent) {
await indexedDb.putReplaceableEvent(muteEvent) const newMuteEvent = await indexedDb.putReplaceableEvent(muteEvent)
setMuteListEvent(muteEvent) setMuteListEvent(newMuteEvent)
const tags = await extractMuteTags(muteEvent) const tags = await extractMuteTags(newMuteEvent)
setTags(tags) setTags(tags)
} }
} }

View File

@@ -403,17 +403,15 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
} }
const updateRelayListEvent = async (relayListEvent: Event) => { const updateRelayListEvent = async (relayListEvent: Event) => {
const isNew = await indexedDb.putReplaceableEvent(relayListEvent) const newRelayList = await indexedDb.putReplaceableEvent(relayListEvent)
if (!isNew) return setRelayList(getRelayListFromRelayListEvent(newRelayList))
setRelayList(getRelayListFromRelayListEvent(relayListEvent))
} }
const updateProfileEvent = async (profileEvent: Event) => { const updateProfileEvent = async (profileEvent: Event) => {
const isNew = await indexedDb.putReplaceableEvent(profileEvent) const newProfileEvent = await indexedDb.putReplaceableEvent(profileEvent)
if (!isNew) return setProfileEvent(newProfileEvent)
setProfileEvent(profileEvent) setProfile(getProfileFromProfileEvent(newProfileEvent))
setProfile(getProfileFromProfileEvent(profileEvent)) client.updateProfileCache(newProfileEvent)
client.updateProfileCache(profileEvent)
} }
return ( return (

View File

@@ -70,7 +70,7 @@ class IndexedDbService {
return this.initPromise return this.initPromise
} }
async putReplaceableEvent(event: Event): Promise<boolean> { async putReplaceableEvent(event: Event): Promise<Event> {
const storeName = this.getStoreNameByKind(event.kind) const storeName = this.getStoreNameByKind(event.kind)
if (!storeName) { if (!storeName) {
return Promise.reject('store name not found') return Promise.reject('store name not found')
@@ -87,11 +87,11 @@ class IndexedDbService {
getRequest.onsuccess = () => { getRequest.onsuccess = () => {
const oldValue = getRequest.result as TValue<Event> | undefined const oldValue = getRequest.result as TValue<Event> | undefined
if (oldValue && oldValue.value.created_at >= event.created_at) { if (oldValue && oldValue.value.created_at >= event.created_at) {
return resolve(false) return resolve(oldValue.value)
} }
const putRequest = store.put(this.formatValue(event.pubkey, event)) const putRequest = store.put(this.formatValue(event.pubkey, event))
putRequest.onsuccess = () => { putRequest.onsuccess = () => {
resolve(true) resolve(event)
} }
putRequest.onerror = (event) => { putRequest.onerror = (event) => {