*Always respond with a created message, and if the entry is not updated, respond with the existing entry
This commit is contained in:
parent
c7d963c9b1
commit
1b876bb78f
18
src/index.ts
18
src/index.ts
|
@ -108,15 +108,15 @@ const plugin: Plugin = {
|
||||||
}
|
}
|
||||||
let entry = (await getEntry(newEntry.pk)) as SignedRegistryEntry;
|
let entry = (await getEntry(newEntry.pk)) as SignedRegistryEntry;
|
||||||
|
|
||||||
async function setAndRespond() {
|
async function setAndRespond(entry: SignedRegistryEntry) {
|
||||||
await setEntry(newEntry);
|
await setEntry(newEntry);
|
||||||
sendDirectOrBroadcast(
|
sendDirectOrBroadcast(
|
||||||
Message.create({
|
Message.create({
|
||||||
type: MessageType.CREATED,
|
type: MessageType.CREATED,
|
||||||
pubkey: newEntry.pk,
|
pubkey: entry.pk,
|
||||||
revision: newEntry.revision,
|
revision: entry.revision,
|
||||||
signature: newEntry.signature,
|
signature: entry.signature,
|
||||||
data: newEntry.data,
|
data: entry.data,
|
||||||
}),
|
}),
|
||||||
origin
|
origin
|
||||||
);
|
);
|
||||||
|
@ -124,11 +124,13 @@ const plugin: Plugin = {
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
if (newEntry.revision <= entry.revision) {
|
if (newEntry.revision <= entry.revision) {
|
||||||
setAndRespond();
|
setAndRespond(newEntry);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
setAndRespond(entry);
|
||||||
setAndRespond();
|
return;
|
||||||
}
|
}
|
||||||
|
setAndRespond(newEntry);
|
||||||
});
|
});
|
||||||
|
|
||||||
events.on("query", async (query: Query, origin: Buffer) => {
|
events.on("query", async (query: Query, origin: Buffer) => {
|
||||||
|
|
Reference in New Issue