From 2f69c506cc753062d9f4df3146e5ac76f399adaa Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 16 Feb 2022 16:02:58 +0100 Subject: [PATCH] Support AP remote following to accounts (not accept yet) --- api/src/activity/federation.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/api/src/activity/federation.js b/api/src/activity/federation.js index e94596c..64e1e4c 100644 --- a/api/src/activity/federation.js +++ b/api/src/activity/federation.js @@ -1,3 +1,5 @@ +const utils = require('../api-utils.js') + async function areActorsValid(actors, ourDomain) { if (!actors instanceof Array && typeof actors !== 'string') { console.error('Unexpected type of "actors" in "federation.doesActorsExistAndOurs"') @@ -48,13 +50,18 @@ module.exports = { } if (msg.activity.type === 'Block') { - if (areActorsValid(msg.activity.object, true)) { - if (msg.activity.actor instanceof Array && - msg.activity.actor.length > 0) - msg.activity.actor = msg.activity.actor[0] - if (msg.activity.object instanceof Array && - msg.activity.object.length > 0) - msg.activity.object = msg.activity.object[0] + if (await areActorsValid(msg.activity.object, true)) { + msg.activity.actor = utils.firstIfArray(msg.activity.actor) + msg.activity.object = utils.firstIfArray(msg.activity.object) + await apex.store.saveObject(msg.activity) + } + return true + } + if (msg.activity.type === 'Follow') + { + if (await areActorsValid(msg.activity.object, true)) { + msg.activity.actor = utils.firstIfArray(msg.activity.actor) + msg.activity.object = utils.firstIfArray(msg.activity.object) await apex.store.saveObject(msg.activity) } return true @@ -66,6 +73,11 @@ module.exports = { { id: msg.object.id, type: 'Block' }) return true } + if (msg.object.type === 'Follow') { + const actorid = utils.firstIfArray(msg.object.id) + await db.table.objects().deleteOne({ id: actorid, type: 'Follow' }) + return true + } } console.log('INBOX')