forked from thieflord06/activitypods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.js
37 lines (36 loc) · 1.21 KB
/
message.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
const { ControlledContainerMixin, defaultToArray } = require('@semapps/ldp');
const { OBJECT_TYPES, ActivitiesHandlerMixin } = require('@semapps/activitypub');
const { NEW_MESSAGE } = require('../config/patterns');
const { NEW_MESSAGE_MAPPING } = require('../config/mappings');
module.exports = {
name: 'messages.message',
mixins: [ControlledContainerMixin, ActivitiesHandlerMixin],
settings: {
path: '/notes',
acceptedTypes: [OBJECT_TYPES.NOTE],
permissions: {},
newResourcesPermissions: {},
},
dependencies: ['activity-mapping'],
async started() {
await this.broker.call('activity-mapping.addMapper', {
match: NEW_MESSAGE,
mapping: NEW_MESSAGE_MAPPING,
});
},
activities: {
createNote: {
match: NEW_MESSAGE,
async onEmit(ctx, activity, emitterUri) {
// Ensure the recipients are in the contacts WebACL group of the emitter so they can see his profile (and respond him)
for (let targetUri of defaultToArray(activity.to)) {
await ctx.call('webacl.group.addMember', {
groupSlug: new URL(emitterUri).pathname + '/contacts',
memberUri: targetUri,
webId: emitterUri,
});
}
},
},
},
};