diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 1e7134c6de..1d414d5f8a 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -10,6 +10,7 @@ const posts = require('../posts'); const topics = require('../topics'); const categories = require('../categories'); const notifications = require('../notifications'); +const flags = require('../flags'); const activitypub = require('.'); const socketHelpers = require('../socket.io/helpers'); @@ -350,3 +351,23 @@ inbox.undo = async (req) => { } } }; + +inbox.flag = async (req) => { + const { actor, object, content } = req.body; + const objects = Array.isArray(object) ? object : [object]; + const subjects = await Promise.all(objects.map(helpers.resolveLocalId)); + + // Check if the actor is valid + if (!await activitypub.actors.assert(actor)) { + reject('Flag', objects, actor); + } + + await Promise.all(subjects.map(async (subject, index) => { + const { type, id } = subject; + try { + await flags.create(type, id, activitypub._constants.uid, content); + } catch (e) { + reject('Flag', objects[index], actor); + } + })); +};