mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: basic AP Flag support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user