From 1b876bb78f1f434ec0a76496cf2be9a56064157b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 31 Dec 2022 16:38:54 -0500 Subject: [PATCH] *Always respond with a created message, and if the entry is not updated, respond with the existing entry --- src/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4f0f2a1..8bca7da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,15 +108,15 @@ const plugin: Plugin = { } let entry = (await getEntry(newEntry.pk)) as SignedRegistryEntry; - async function setAndRespond() { + async function setAndRespond(entry: SignedRegistryEntry) { await setEntry(newEntry); sendDirectOrBroadcast( Message.create({ type: MessageType.CREATED, - pubkey: newEntry.pk, - revision: newEntry.revision, - signature: newEntry.signature, - data: newEntry.data, + pubkey: entry.pk, + revision: entry.revision, + signature: entry.signature, + data: entry.data, }), origin ); @@ -124,11 +124,13 @@ const plugin: Plugin = { if (entry) { if (newEntry.revision <= entry.revision) { - setAndRespond(); + setAndRespond(newEntry); + return; } - } else { - setAndRespond(); + setAndRespond(entry); + return; } + setAndRespond(newEntry); }); events.on("query", async (query: Query, origin: Buffer) => {