fix: support reporting remote content in Flag

This commit is contained in:
Opliko
2024-04-14 02:42:30 +02:00
parent a1a7fb77da
commit 026449dc4a
4 changed files with 20 additions and 4 deletions

View File

@@ -177,6 +177,20 @@ Helpers.resolveActivity = async (activity, data, id, resolved) => {
}
};
Helpers.mapToLocalType = (type) => {
if (type === 'Person') {
return 'user';
}
if (type === 'Group') {
return 'category';
}
if (type === 'Hashtag') {
return 'tag';
}
if (activitypub._constants.acceptedPostTypes.includes(type)) {
return 'post';
}
};
Helpers.resolveObjects = async (ids) => {
if (!Array.isArray(ids)) {

View File

@@ -386,9 +386,9 @@ inbox.flag = async (req) => {
}
await Promise.all(objects.map(async (subject, index) => {
const { type, id } = await activitypub.helpers.resolveLocalId(subject.id);
const { type, id } = await activitypub.helpers.resolveObjects(subject.id);
try {
await flags.create(type, id, actor, content);
await flags.create(activitypub.helpers.mapToLocalType(type), id, actor, content);
} catch (e) {
reject('Flag', objects[index], actor);
}

View File

@@ -21,6 +21,9 @@ ActivityPub._constants = Object.freeze({
'application/activity+json',
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
],
acceptedPostTypes: [
'Note', 'Page', 'Article', 'Question',
],
});
ActivityPub._cache = requestCache;

View File

@@ -78,8 +78,7 @@ Mocks.post = async (objects) => {
}
const posts = await Promise.all(objects.map(async (object) => {
const acceptedTypes = ['Note', 'Page', 'Article', 'Question'];
if (!acceptedTypes.includes(object.type)) {
if (!activitypub._constants.acceptedPostTypes.includes(object.type)) {
return null;
}