feat: handle Update(note)

This commit is contained in:
Julian Lam
2024-01-16 13:55:58 -05:00
parent 641a94d64a
commit ac672f08a7
3 changed files with 23 additions and 2 deletions

View File

@@ -15,14 +15,18 @@ Notes.resolveId = async (uid, id) => {
// todo: when asserted, notes aren't added to a global sorted set
// also, db.exists call is probably expensive
Notes.assert = async (uid, input) => {
Notes.assert = async (uid, input, options = {}) => {
// Ensures that each note has been saved to the database
await Promise.all(input.map(async (item) => {
const id = activitypub.helpers.isUri(item) ? item : item.pid;
const key = `post:${id}`;
const exists = await db.exists(key);
let exists = await db.exists(key);
winston.verbose(`[activitypub/notes.assert] Asserting note id ${id}`);
if (options.update === true) {
exists = false;
}
if (!exists) {
let postData;
winston.verbose(`[activitypub/notes.assert] Not found, saving note to database`);