Node.js based forum software built for the modern web
feat: Update(Person)
Julian Lam6e87cf57a2fb
diff --git a/src/activitypub/actors.js b/src/activitypub/actors.jsindex d013cedc73..40a3052e56 100644--- a/src/activitypub/actors.js+++ b/src/activitypub/actors.js@@ -9,7 +9,7 @@ const activitypub = module.parent.exports;const Actors = module.exports;-Actors.assert = async (ids) => {+Actors.assert = async (ids, options = {}) => {// Handle single valuesif (!Array.isArray(ids)) {ids = [ids];@@ -19,8 +19,10 @@ Actors.assert = async (ids) => {ids = ids.filter(id => !utils.isNumber(id));// Filter out existing- const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids);- ids = ids.filter((id, idx) => !exists[idx]);+ if (!options.update) {+ const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids.map(id => ((typeof id === 'object' && id.hasOwnProperty('id')) ? id.id : id)));+ ids = ids.filter((id, idx) => !exists[idx]);+ }if (!ids.length) {return true;@@ -28,7 +30,7 @@ Actors.assert = async (ids) => {const actors = await Promise.all(ids.map(async (id) => {try {- const actor = await activitypub.get(0, id);+ const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? await activitypub.get(0, id) : id;// Follow countstry {@@ -40,7 +42,7 @@ Actors.assert = async (ids) => {actor.followingCount = following.totalItems;} catch (e) {// no action required- winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${id}`);+ winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${actor.id}`);}// Post countdiff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex f6730a2b3f..4a5efec706 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -25,13 +25,24 @@ 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(0, [postData], { update: true });- winston.info(`[activitypub/inbox] Updating note ${postData.pid}`);- } else {- winston.warn('[activitypub/inbox] Received object was not a note');+ switch (object.type) {+ case 'Note': {+ const postData = await activitypub.mocks.post(object);++ if (postData) {+ await activitypub.notes.assert(0, [postData], { update: true });+ winston.info(`[activitypub/inbox.update] Updating note ${postData.pid}`);+ } else {+ winston.warn(`[activitypub/inbox.update] Received note did not parse properly (id: ${object.id})`);+ }+ break;+ }++ case 'Person': {+ await activitypub.actors.assert(object, { update: true });+ break;+ }}};