]>
Commit | Line | Data |
---|---|---|
d26836cd C |
1 | import { logger } from '@server/helpers/logger' |
2 | import { UserModel } from '@server/models/user/user' | |
3 | import { UserNotificationModel } from '@server/models/user/user-notification' | |
4 | import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | |
5 | import { UserNotificationType, UserRight } from '@shared/models' | |
6 | import { AbstractNotification } from '../common/abstract-notification' | |
7 | ||
8 | export class AutoFollowForInstance extends AbstractNotification <MActorFollowFull> { | |
9 | private admins: MUserDefault[] | |
10 | ||
11 | async prepare () { | |
12 | this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW) | |
13 | } | |
14 | ||
15 | log () { | |
16 | logger.info('Notifying %d administrators of auto instance following: %s.', this.admins.length, this.actorFollow.ActorFollowing.url) | |
17 | } | |
18 | ||
19 | getSetting (user: MUserWithNotificationSetting) { | |
20 | return user.NotificationSetting.autoInstanceFollowing | |
21 | } | |
22 | ||
23 | getTargetUsers () { | |
24 | return this.admins | |
25 | } | |
26 | ||
27 | async createNotification (user: MUserWithNotificationSetting) { | |
28 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | |
29 | type: UserNotificationType.AUTO_INSTANCE_FOLLOWING, | |
30 | userId: user.id, | |
31 | actorFollowId: this.actorFollow.id | |
32 | }) | |
33 | notification.ActorFollow = this.actorFollow | |
34 | ||
35 | return notification | |
36 | } | |
37 | ||
98ab5dc8 | 38 | createEmail (to: string) { |
d26836cd C |
39 | const instanceUrl = this.actorFollow.ActorFollowing.url |
40 | ||
41 | return { | |
42 | to, | |
43 | subject: 'Auto instance following', | |
44 | text: `Your instance automatically followed a new instance: <a href="${instanceUrl}">${instanceUrl}</a>.` | |
45 | } | |
46 | } | |
47 | ||
48 | private get actorFollow () { | |
49 | return this.payload | |
50 | } | |
51 | } |