forked from activitypods/activitypods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.js
31 lines (26 loc) · 1.02 KB
/
manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { ActivitiesHandlerMixin } = require('@semapps/activitypub');
const { REMOVE_CONTACT } = require("../config/patterns");
module.exports = {
name: 'contacts.manager',
mixins: [ActivitiesHandlerMixin],
activities: {
removeContact: {
match: REMOVE_CONTACT,
async onEmit(ctx, activity, emitterUri) {
if (!activity.origin)
throw new Error('The origin property is missing from the Remove activity');
if (!activity.origin.startsWith(emitterUri))
throw new Error(`Cannot remove from collection ${activity.origin} as it is not owned by the emitter`);
await ctx.call('activitypub.collection.detach', {
collectionUri: activity.origin,
item: activity.object.id,
});
const actor = await ctx.call('activitypub.actor.get', { actorUri: activity.object.id, webId: activity.object.id });
await ctx.call('activitypub.object.deleteFromCache', {
actorUri: emitterUri,
objectUri: actor.url,
});
}
},
}
};