*Always respond with a created message, and if the entry is not updated, respond with the existing entry

This commit is contained in:
Derrick Hammer 2022-12-31 16:38:54 -05:00
parent c7d963c9b1
commit 1b876bb78f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 8 deletions

View File

@ -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) => {