Skip to content

Node.js based forum software built for the modern web

feat: handle Update(note)

Julian Lamac672f08a756
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js
index 530edbddb4..d6598e39eb 100644
--- a/src/activitypub/inbox.js
+++ b/src/activitypub/inbox.js
@@ -23,6 +23,18 @@ inbox.create = async (req) => {
}
};
+inbox.update = async (req) => {
+ const { object } = req.body;
+ const postData = await activitypub.mocks.post(object);
+
+ if (postData) {
+ await activitypub.notes.assert(1, [postData], { update: true });
+ winston.info(`[activitypub/inbox] Updating note ${postData.pid}`);
+ } else {
+ winston.warn('[activitypub/inbox] Received object was not a note');
+ }
+};
+
inbox.follow = async (req) => {
// Sanity checks
const localUid = await helpers.resolveLocalUid(req.body.object);
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index 870a0364e1..893a79d62f 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -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`);
diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.js
index 98d58104d5..9c516f7d01 100644
--- a/src/controllers/activitypub/index.js
+++ b/src/controllers/activitypub/index.js
@@ -110,6 +110,11 @@ Controller.postInbox = async (req, res) => {
break;
}
+ case 'Update': {
+ await activitypub.inbox.update(req);
+ break;
+ }
+
case 'Follow': {
await activitypub.inbox.follow(req);
break;