EventsDB: normalize the event to only NIP-01 event properties

This commit is contained in:
Alex Gleason 2024-01-23 12:12:34 -06:00
parent aaf01462c1
commit 0b6874bb44
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 14 additions and 0 deletions

View File

@ -68,6 +68,7 @@ class EventsDB implements EventStore {
/** Insert an event (and its tags) into the database. */ /** Insert an event (and its tags) into the database. */
async add(event: NostrEvent): Promise<void> { async add(event: NostrEvent): Promise<void> {
event = cloneEvent(event);
this.#debug('EVENT', JSON.stringify(event)); this.#debug('EVENT', JSON.stringify(event));
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) { if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {
@ -408,6 +409,19 @@ function buildSearchContent(event: NostrEvent): string {
} }
} }
/** Return a normalized event without any non-standard keys. */
function cloneEvent(event: NostrEvent): NostrEvent {
return {
id: event.id,
pubkey: event.pubkey,
kind: event.kind,
content: event.content,
tags: event.tags,
sig: event.sig,
created_at: event.created_at,
};
}
/** Build search content for a user. */ /** Build search content for a user. */
function buildUserSearchContent(event: NostrEvent): string { function buildUserSearchContent(event: NostrEvent): string {
const { name, nip05, about } = jsonMetaContentSchema.parse(event.content); const { name, nip05, about } = jsonMetaContentSchema.parse(event.content);