]>
Commit | Line | Data |
---|---|---|
1 | import { logger } from '@server/helpers/logger' | |
2 | import { WEBSERVER } from '@server/initializers/constants' | |
3 | import { isBlockedByServerOrAccount } from '@server/lib/blocklist' | |
4 | import { UserModel } from '@server/models/user/user' | |
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | |
6 | import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | |
7 | import { UserNotificationType, UserRight } from '@shared/models' | |
8 | import { AbstractNotification } from '../common/abstract-notification' | |
9 | ||
10 | export class FollowForInstance extends AbstractNotification <MActorFollowFull> { | |
11 | private admins: MUserDefault[] | |
12 | ||
13 | async prepare () { | |
14 | this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW) | |
15 | } | |
16 | ||
17 | isDisabled () { | |
18 | const follower = Object.assign(this.actorFollow.ActorFollower.Account, { Actor: this.actorFollow.ActorFollower }) | |
19 | ||
20 | return isBlockedByServerOrAccount(follower) | |
21 | } | |
22 | ||
23 | log () { | |
24 | logger.info('Notifying %d administrators of new instance follower: %s.', this.admins.length, this.actorFollow.ActorFollower.url) | |
25 | } | |
26 | ||
27 | getSetting (user: MUserWithNotificationSetting) { | |
28 | return user.NotificationSetting.newInstanceFollower | |
29 | } | |
30 | ||
31 | getTargetUsers () { | |
32 | return this.admins | |
33 | } | |
34 | ||
35 | createNotification (user: MUserWithNotificationSetting) { | |
36 | const notification = UserNotificationModel.build<UserNotificationModelForApi>({ | |
37 | type: UserNotificationType.NEW_INSTANCE_FOLLOWER, | |
38 | userId: user.id, | |
39 | actorFollowId: this.actorFollow.id | |
40 | }) | |
41 | notification.ActorFollow = this.actorFollow | |
42 | ||
43 | return notification | |
44 | } | |
45 | ||
46 | createEmail (to: string) { | |
47 | const awaitingApproval = this.actorFollow.state === 'pending' | |
48 | ? ' awaiting manual approval.' | |
49 | : '' | |
50 | ||
51 | return { | |
52 | to, | |
53 | subject: 'New instance follower', | |
54 | text: `Your instance has a new follower: ${this.actorFollow.ActorFollower.url}${awaitingApproval}.`, | |
55 | locals: { | |
56 | title: 'New instance follower', | |
57 | action: { | |
58 | text: 'Review followers', | |
59 | url: WEBSERVER.URL + '/admin/follows/followers-list' | |
60 | } | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | private get actorFollow () { | |
66 | return this.payload | |
67 | } | |
68 | } |