-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanager.js
94 lines (82 loc) · 3.16 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const { ActivitiesHandlerMixin, ACTOR_TYPES } = require('@semapps/activitypub');
const { REMOVE_CONTACT, IGNORE_CONTACT, UNDO_IGNORE_CONTACT } = require('../config/patterns');
module.exports = {
name: 'contacts.manager',
mixins: [ActivitiesHandlerMixin],
dependencies: ['activitypub.registry', 'activity-mapping', 'webacl'],
async started() {
await this.broker.call('activitypub.registry.register', {
path: '/ignored-contacts',
attachToTypes: Object.values(ACTOR_TYPES),
attachPredicate: 'http://activitypods.org/ns/core#ignoredContacts',
ordered: false,
dereferenceItems: false,
});
},
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,
});
},
},
ignoreContact: {
match: IGNORE_CONTACT,
async onEmit(ctx, activity, emitterUri) {
const emitter = await ctx.call('activitypub.actor.get', { actorUri: emitterUri });
// Add the actor to its ignore contacts list
await ctx.call('activitypub.collection.attach', {
collectionUri: emitter['apods:ignoredContacts'],
item: activity.object,
});
},
},
undoIngoreContact: {
match: UNDO_IGNORE_CONTACT,
async onEmit(ctx, activity, emitterUri) {
const emitter = await ctx.call('activitypub.actor.get', { actorUri: emitterUri });
// Add the actor to its ignore contacts list
await ctx.call('activitypub.collection.detach', {
collectionUri: emitter['apods:ignoredContacts'],
item: activity.object.object,
});
},
},
ignoreContact: {
match: IGNORE_CONTACT,
async onEmit(ctx, activity, emitterUri) {
const emitter = await ctx.call('activitypub.actor.get', { actorUri: emitterUri });
// Add the actor to the emitter's ignore contacts list.
await ctx.call('activitypub.collection.attach', {
collectionUri: emitter['apods:ignoredContacts'],
item: activity.object,
});
},
},
undoIgnoreContact: {
match: UNDO_IGNORE_CONTACT,
async onEmit(ctx, activity, emitterUri) {
const emitter = await ctx.call('activitypub.actor.get', { actorUri: emitterUri });
// Remove the actor from the emitter's ignore contacts list.
await ctx.call('activitypub.collection.detach', {
collectionUri: emitter['apods:ignoredContacts'],
item: activity.object,
});
},
},
},
};