diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 318c11d53b..1dec3302b8 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -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)) { diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 096c8580bf..ed69a64885 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -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); } diff --git a/src/activitypub/index.js b/src/activitypub/index.js index c5a4629a4f..94460c6d52 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -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; diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 9d01d5bc00..ee3eb3b2a7 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -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; }