feat: prevent posting duplicate notes
This commit is contained in:
@@ -60,6 +60,7 @@ export function createRepostDraftEvent(event: Event): TDraftEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shortTextNoteDraftEventCache: Map<string, TDraftEvent> = new Map()
|
||||||
export async function createShortTextNoteDraftEvent(
|
export async function createShortTextNoteDraftEvent(
|
||||||
content: string,
|
content: string,
|
||||||
mentions: string[],
|
mentions: string[],
|
||||||
@@ -106,12 +107,20 @@ export async function createShortTextNoteDraftEvent(
|
|||||||
tags.push(['-'])
|
tags.push(['-'])
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const baseDraft = {
|
||||||
kind: kinds.ShortTextNote,
|
kind: kinds.ShortTextNote,
|
||||||
content,
|
content,
|
||||||
tags,
|
tags
|
||||||
created_at: dayjs().unix()
|
|
||||||
}
|
}
|
||||||
|
const cacheKey = JSON.stringify(baseDraft)
|
||||||
|
const cache = shortTextNoteDraftEventCache.get(cacheKey)
|
||||||
|
if (cache) {
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
const draftEvent = { ...baseDraft, created_at: dayjs().unix() }
|
||||||
|
shortTextNoteDraftEventCache.set(cacheKey, draftEvent)
|
||||||
|
|
||||||
|
return draftEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/nostr-protocol/nips/blob/master/51.md
|
// https://github.com/nostr-protocol/nips/blob/master/51.md
|
||||||
@@ -165,6 +174,7 @@ export async function createPictureNoteDraftEvent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commentDraftEventCache: Map<string, TDraftEvent> = new Map()
|
||||||
export async function createCommentDraftEvent(
|
export async function createCommentDraftEvent(
|
||||||
content: string,
|
content: string,
|
||||||
parentEvent: Event,
|
parentEvent: Event,
|
||||||
@@ -229,12 +239,20 @@ export async function createCommentDraftEvent(
|
|||||||
tags.push(['-'])
|
tags.push(['-'])
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const baseDraft = {
|
||||||
kind: ExtendedKind.COMMENT,
|
kind: ExtendedKind.COMMENT,
|
||||||
content,
|
content,
|
||||||
tags,
|
tags
|
||||||
created_at: dayjs().unix()
|
|
||||||
}
|
}
|
||||||
|
const cacheKey = JSON.stringify(baseDraft)
|
||||||
|
const cache = commentDraftEventCache.get(cacheKey)
|
||||||
|
if (cache) {
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
const draftEvent = { ...baseDraft, created_at: dayjs().unix() }
|
||||||
|
commentDraftEventCache.set(cacheKey, draftEvent)
|
||||||
|
|
||||||
|
return draftEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRelayListDraftEvent(mailboxRelays: TMailboxRelay[]): TDraftEvent {
|
export function createRelayListDraftEvent(mailboxRelays: TMailboxRelay[]): TDraftEvent {
|
||||||
|
|||||||
Reference in New Issue
Block a user