diff options
Diffstat (limited to 'server/lib/notifier.ts')
-rw-r--r-- | server/lib/notifier.ts | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts index a7dfb0979..f01101b8e 100644 --- a/server/lib/notifier.ts +++ b/server/lib/notifier.ts | |||
@@ -8,13 +8,23 @@ import { UserModel } from '../models/account/user' | |||
8 | import { PeerTubeSocket } from './peertube-socket' | 8 | import { PeerTubeSocket } from './peertube-socket' |
9 | import { CONFIG } from '../initializers/config' | 9 | import { CONFIG } from '../initializers/config' |
10 | import { VideoPrivacy, VideoState } from '../../shared/models/videos' | 10 | import { VideoPrivacy, VideoState } from '../../shared/models/videos' |
11 | import { VideoAbuseModel } from '../models/video/video-abuse' | ||
12 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | 11 | import { VideoBlacklistModel } from '../models/video/video-blacklist' |
13 | import * as Bluebird from 'bluebird' | 12 | import * as Bluebird from 'bluebird' |
14 | import { VideoImportModel } from '../models/video/video-import' | 13 | import { VideoImportModel } from '../models/video/video-import' |
15 | import { AccountBlocklistModel } from '../models/account/account-blocklist' | 14 | import { AccountBlocklistModel } from '../models/account/account-blocklist' |
15 | import { | ||
16 | MCommentOwnerVideo, | ||
17 | MVideo, | ||
18 | MVideoAbuseVideo, | ||
19 | MVideoAccountLight, | ||
20 | MVideoBlacklistVideo, | ||
21 | MVideoFullLight | ||
22 | } from '../typings/models/video' | ||
23 | import { MUser, MUserAccount, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/typings/models/user' | ||
24 | import { MActorFollowActors, MActorFollowFull } from '../typings/models' | ||
16 | import { ActorFollowModel } from '../models/activitypub/actor-follow' | 25 | import { ActorFollowModel } from '../models/activitypub/actor-follow' |
17 | import { AccountModel } from '../models/account/account' | 26 | import { MVideoImportVideo } from '@server/typings/models/video/video-import' |
27 | import { AccountModel } from '@server/models/account/account' | ||
18 | 28 | ||
19 | class Notifier { | 29 | class Notifier { |
20 | 30 | ||
@@ -22,7 +32,7 @@ class Notifier { | |||
22 | 32 | ||
23 | private constructor () {} | 33 | private constructor () {} |
24 | 34 | ||
25 | notifyOnNewVideoIfNeeded (video: VideoModel): void { | 35 | notifyOnNewVideoIfNeeded (video: MVideoAccountLight): void { |
26 | // Only notify on public and published videos which are not blacklisted | 36 | // Only notify on public and published videos which are not blacklisted |
27 | if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return | 37 | if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return |
28 | 38 | ||
@@ -30,7 +40,7 @@ class Notifier { | |||
30 | .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err })) | 40 | .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err })) |
31 | } | 41 | } |
32 | 42 | ||
33 | notifyOnVideoPublishedAfterTranscoding (video: VideoModel): void { | 43 | notifyOnVideoPublishedAfterTranscoding (video: MVideoFullLight): void { |
34 | // don't notify if didn't wait for transcoding or video is still blacklisted/waiting for scheduled update | 44 | // don't notify if didn't wait for transcoding or video is still blacklisted/waiting for scheduled update |
35 | if (!video.waitTranscoding || video.VideoBlacklist || video.ScheduleVideoUpdate) return | 45 | if (!video.waitTranscoding || video.VideoBlacklist || video.ScheduleVideoUpdate) return |
36 | 46 | ||
@@ -38,7 +48,7 @@ class Notifier { | |||
38 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after transcoding.', video.url, { err })) | 48 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after transcoding.', video.url, { err })) |
39 | } | 49 | } |
40 | 50 | ||
41 | notifyOnVideoPublishedAfterScheduledUpdate (video: VideoModel): void { | 51 | notifyOnVideoPublishedAfterScheduledUpdate (video: MVideoFullLight): void { |
42 | // don't notify if video is still blacklisted or waiting for transcoding | 52 | // don't notify if video is still blacklisted or waiting for transcoding |
43 | if (video.VideoBlacklist || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return | 53 | if (video.VideoBlacklist || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return |
44 | 54 | ||
@@ -46,7 +56,7 @@ class Notifier { | |||
46 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after scheduled update.', video.url, { err })) | 56 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after scheduled update.', video.url, { err })) |
47 | } | 57 | } |
48 | 58 | ||
49 | notifyOnVideoPublishedAfterRemovedFromAutoBlacklist (video: VideoModel): void { | 59 | notifyOnVideoPublishedAfterRemovedFromAutoBlacklist (video: MVideoFullLight): void { |
50 | // don't notify if video is still waiting for transcoding or scheduled update | 60 | // don't notify if video is still waiting for transcoding or scheduled update |
51 | if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return | 61 | if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return |
52 | 62 | ||
@@ -54,7 +64,7 @@ class Notifier { | |||
54 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })) // tslint:disable-line:max-line-length | 64 | .catch(err => logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })) // tslint:disable-line:max-line-length |
55 | } | 65 | } |
56 | 66 | ||
57 | notifyOnNewComment (comment: VideoCommentModel): void { | 67 | notifyOnNewComment (comment: MCommentOwnerVideo): void { |
58 | this.notifyVideoOwnerOfNewComment(comment) | 68 | this.notifyVideoOwnerOfNewComment(comment) |
59 | .catch(err => logger.error('Cannot notify video owner of new comment %s.', comment.url, { err })) | 69 | .catch(err => logger.error('Cannot notify video owner of new comment %s.', comment.url, { err })) |
60 | 70 | ||
@@ -62,37 +72,37 @@ class Notifier { | |||
62 | .catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err })) | 72 | .catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err })) |
63 | } | 73 | } |
64 | 74 | ||
65 | notifyOnNewVideoAbuse (videoAbuse: VideoAbuseModel): void { | 75 | notifyOnNewVideoAbuse (videoAbuse: MVideoAbuseVideo): void { |
66 | this.notifyModeratorsOfNewVideoAbuse(videoAbuse) | 76 | this.notifyModeratorsOfNewVideoAbuse(videoAbuse) |
67 | .catch(err => logger.error('Cannot notify of new video abuse of video %s.', videoAbuse.Video.url, { err })) | 77 | .catch(err => logger.error('Cannot notify of new video abuse of video %s.', videoAbuse.Video.url, { err })) |
68 | } | 78 | } |
69 | 79 | ||
70 | notifyOnVideoAutoBlacklist (video: VideoModel): void { | 80 | notifyOnVideoAutoBlacklist (video: MVideo): void { |
71 | this.notifyModeratorsOfVideoAutoBlacklist(video) | 81 | this.notifyModeratorsOfVideoAutoBlacklist(video) |
72 | .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', video.url, { err })) | 82 | .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', video.url, { err })) |
73 | } | 83 | } |
74 | 84 | ||
75 | notifyOnVideoBlacklist (videoBlacklist: VideoBlacklistModel): void { | 85 | notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void { |
76 | this.notifyVideoOwnerOfBlacklist(videoBlacklist) | 86 | this.notifyVideoOwnerOfBlacklist(videoBlacklist) |
77 | .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err })) | 87 | .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err })) |
78 | } | 88 | } |
79 | 89 | ||
80 | notifyOnVideoUnblacklist (video: VideoModel): void { | 90 | notifyOnVideoUnblacklist (video: MVideo): void { |
81 | this.notifyVideoOwnerOfUnblacklist(video) | 91 | this.notifyVideoOwnerOfUnblacklist(video) |
82 | .catch(err => logger.error('Cannot notify video owner of unblacklist of %s.', video.url, { err })) | 92 | .catch(err => logger.error('Cannot notify video owner of unblacklist of %s.', video.url, { err })) |
83 | } | 93 | } |
84 | 94 | ||
85 | notifyOnFinishedVideoImport (videoImport: VideoImportModel, success: boolean): void { | 95 | notifyOnFinishedVideoImport (videoImport: MVideoImportVideo, success: boolean): void { |
86 | this.notifyOwnerVideoImportIsFinished(videoImport, success) | 96 | this.notifyOwnerVideoImportIsFinished(videoImport, success) |
87 | .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err })) | 97 | .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err })) |
88 | } | 98 | } |
89 | 99 | ||
90 | notifyOnNewUserRegistration (user: UserModel): void { | 100 | notifyOnNewUserRegistration (user: MUserAccount): void { |
91 | this.notifyModeratorsOfNewUserRegistration(user) | 101 | this.notifyModeratorsOfNewUserRegistration(user) |
92 | .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) | 102 | .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) |
93 | } | 103 | } |
94 | 104 | ||
95 | notifyOfNewUserFollow (actorFollow: ActorFollowModel): void { | 105 | notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { |
96 | this.notifyUserOfNewActorFollow(actorFollow) | 106 | this.notifyUserOfNewActorFollow(actorFollow) |
97 | .catch(err => { | 107 | .catch(err => { |
98 | logger.error( | 108 | logger.error( |
@@ -104,14 +114,14 @@ class Notifier { | |||
104 | }) | 114 | }) |
105 | } | 115 | } |
106 | 116 | ||
107 | notifyOfNewInstanceFollow (actorFollow: ActorFollowModel): void { | 117 | notifyOfNewInstanceFollow (actorFollow: MActorFollowActors): void { |
108 | this.notifyAdminsOfNewInstanceFollow(actorFollow) | 118 | this.notifyAdminsOfNewInstanceFollow(actorFollow) |
109 | .catch(err => { | 119 | .catch(err => { |
110 | logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err }) | 120 | logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err }) |
111 | }) | 121 | }) |
112 | } | 122 | } |
113 | 123 | ||
114 | private async notifySubscribersOfNewVideo (video: VideoModel) { | 124 | private async notifySubscribersOfNewVideo (video: MVideoAccountLight) { |
115 | // List all followers that are users | 125 | // List all followers that are users |
116 | const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId) | 126 | const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId) |
117 | 127 | ||
@@ -127,7 +137,7 @@ class Notifier { | |||
127 | userId: user.id, | 137 | userId: user.id, |
128 | videoId: video.id | 138 | videoId: video.id |
129 | }) | 139 | }) |
130 | notification.Video = video | 140 | notification.Video = video as VideoModel |
131 | 141 | ||
132 | return notification | 142 | return notification |
133 | } | 143 | } |
@@ -139,7 +149,7 @@ class Notifier { | |||
139 | return this.notify({ users, settingGetter, notificationCreator, emailSender }) | 149 | return this.notify({ users, settingGetter, notificationCreator, emailSender }) |
140 | } | 150 | } |
141 | 151 | ||
142 | private async notifyVideoOwnerOfNewComment (comment: VideoCommentModel) { | 152 | private async notifyVideoOwnerOfNewComment (comment: MCommentOwnerVideo) { |
143 | if (comment.Video.isOwned() === false) return | 153 | if (comment.Video.isOwned() === false) return |
144 | 154 | ||
145 | const user = await UserModel.loadByVideoId(comment.videoId) | 155 | const user = await UserModel.loadByVideoId(comment.videoId) |
@@ -162,7 +172,7 @@ class Notifier { | |||
162 | userId: user.id, | 172 | userId: user.id, |
163 | commentId: comment.id | 173 | commentId: comment.id |
164 | }) | 174 | }) |
165 | notification.Comment = comment | 175 | notification.Comment = comment as VideoCommentModel |
166 | 176 | ||
167 | return notification | 177 | return notification |
168 | } | 178 | } |
@@ -174,7 +184,7 @@ class Notifier { | |||
174 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 184 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
175 | } | 185 | } |
176 | 186 | ||
177 | private async notifyOfCommentMention (comment: VideoCommentModel) { | 187 | private async notifyOfCommentMention (comment: MCommentOwnerVideo) { |
178 | const extractedUsernames = comment.extractMentions() | 188 | const extractedUsernames = comment.extractMentions() |
179 | logger.debug( | 189 | logger.debug( |
180 | 'Extracted %d username from comment %s.', extractedUsernames.length, comment.url, | 190 | 'Extracted %d username from comment %s.', extractedUsernames.length, comment.url, |
@@ -209,7 +219,7 @@ class Notifier { | |||
209 | userId: user.id, | 219 | userId: user.id, |
210 | commentId: comment.id | 220 | commentId: comment.id |
211 | }) | 221 | }) |
212 | notification.Comment = comment | 222 | notification.Comment = comment as VideoCommentModel |
213 | 223 | ||
214 | return notification | 224 | return notification |
215 | } | 225 | } |
@@ -221,7 +231,7 @@ class Notifier { | |||
221 | return this.notify({ users, settingGetter, notificationCreator, emailSender }) | 231 | return this.notify({ users, settingGetter, notificationCreator, emailSender }) |
222 | } | 232 | } |
223 | 233 | ||
224 | private async notifyUserOfNewActorFollow (actorFollow: ActorFollowModel) { | 234 | private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) { |
225 | if (actorFollow.ActorFollowing.isOwned() === false) return | 235 | if (actorFollow.ActorFollowing.isOwned() === false) return |
226 | 236 | ||
227 | // Account follows one of our account? | 237 | // Account follows one of our account? |
@@ -236,9 +246,6 @@ class Notifier { | |||
236 | 246 | ||
237 | if (!user) return | 247 | if (!user) return |
238 | 248 | ||
239 | if (!actorFollow.ActorFollower.Account || !actorFollow.ActorFollower.Account.name) { | ||
240 | actorFollow.ActorFollower.Account = await actorFollow.ActorFollower.$get('Account') as AccountModel | ||
241 | } | ||
242 | const followerAccount = actorFollow.ActorFollower.Account | 249 | const followerAccount = actorFollow.ActorFollower.Account |
243 | 250 | ||
244 | const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, followerAccount.id) | 251 | const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, followerAccount.id) |
@@ -256,7 +263,7 @@ class Notifier { | |||
256 | userId: user.id, | 263 | userId: user.id, |
257 | actorFollowId: actorFollow.id | 264 | actorFollowId: actorFollow.id |
258 | }) | 265 | }) |
259 | notification.ActorFollow = actorFollow | 266 | notification.ActorFollow = actorFollow as ActorFollowModel |
260 | 267 | ||
261 | return notification | 268 | return notification |
262 | } | 269 | } |
@@ -268,7 +275,7 @@ class Notifier { | |||
268 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 275 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
269 | } | 276 | } |
270 | 277 | ||
271 | private async notifyAdminsOfNewInstanceFollow (actorFollow: ActorFollowModel) { | 278 | private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowActors) { |
272 | const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW) | 279 | const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW) |
273 | 280 | ||
274 | logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url) | 281 | logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url) |
@@ -283,7 +290,7 @@ class Notifier { | |||
283 | userId: user.id, | 290 | userId: user.id, |
284 | actorFollowId: actorFollow.id | 291 | actorFollowId: actorFollow.id |
285 | }) | 292 | }) |
286 | notification.ActorFollow = actorFollow | 293 | notification.ActorFollow = actorFollow as ActorFollowModel |
287 | 294 | ||
288 | return notification | 295 | return notification |
289 | } | 296 | } |
@@ -295,7 +302,7 @@ class Notifier { | |||
295 | return this.notify({ users: admins, settingGetter, notificationCreator, emailSender }) | 302 | return this.notify({ users: admins, settingGetter, notificationCreator, emailSender }) |
296 | } | 303 | } |
297 | 304 | ||
298 | private async notifyModeratorsOfNewVideoAbuse (videoAbuse: VideoAbuseModel) { | 305 | private async notifyModeratorsOfNewVideoAbuse (videoAbuse: MVideoAbuseVideo) { |
299 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES) | 306 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES) |
300 | if (moderators.length === 0) return | 307 | if (moderators.length === 0) return |
301 | 308 | ||
@@ -306,7 +313,7 @@ class Notifier { | |||
306 | } | 313 | } |
307 | 314 | ||
308 | async function notificationCreator (user: UserModel) { | 315 | async function notificationCreator (user: UserModel) { |
309 | const notification = await UserNotificationModel.create({ | 316 | const notification: UserNotificationModelForApi = await UserNotificationModel.create({ |
310 | type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS, | 317 | type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS, |
311 | userId: user.id, | 318 | userId: user.id, |
312 | videoAbuseId: videoAbuse.id | 319 | videoAbuseId: videoAbuse.id |
@@ -323,7 +330,7 @@ class Notifier { | |||
323 | return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) | 330 | return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) |
324 | } | 331 | } |
325 | 332 | ||
326 | private async notifyModeratorsOfVideoAutoBlacklist (video: VideoModel) { | 333 | private async notifyModeratorsOfVideoAutoBlacklist (video: MVideo) { |
327 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST) | 334 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST) |
328 | if (moderators.length === 0) return | 335 | if (moderators.length === 0) return |
329 | 336 | ||
@@ -339,7 +346,7 @@ class Notifier { | |||
339 | userId: user.id, | 346 | userId: user.id, |
340 | videoId: video.id | 347 | videoId: video.id |
341 | }) | 348 | }) |
342 | notification.Video = video | 349 | notification.Video = video as VideoModel |
343 | 350 | ||
344 | return notification | 351 | return notification |
345 | } | 352 | } |
@@ -351,7 +358,7 @@ class Notifier { | |||
351 | return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) | 358 | return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) |
352 | } | 359 | } |
353 | 360 | ||
354 | private async notifyVideoOwnerOfBlacklist (videoBlacklist: VideoBlacklistModel) { | 361 | private async notifyVideoOwnerOfBlacklist (videoBlacklist: MVideoBlacklistVideo) { |
355 | const user = await UserModel.loadByVideoId(videoBlacklist.videoId) | 362 | const user = await UserModel.loadByVideoId(videoBlacklist.videoId) |
356 | if (!user) return | 363 | if (!user) return |
357 | 364 | ||
@@ -367,7 +374,7 @@ class Notifier { | |||
367 | userId: user.id, | 374 | userId: user.id, |
368 | videoBlacklistId: videoBlacklist.id | 375 | videoBlacklistId: videoBlacklist.id |
369 | }) | 376 | }) |
370 | notification.VideoBlacklist = videoBlacklist | 377 | notification.VideoBlacklist = videoBlacklist as VideoBlacklistModel |
371 | 378 | ||
372 | return notification | 379 | return notification |
373 | } | 380 | } |
@@ -379,7 +386,7 @@ class Notifier { | |||
379 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 386 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
380 | } | 387 | } |
381 | 388 | ||
382 | private async notifyVideoOwnerOfUnblacklist (video: VideoModel) { | 389 | private async notifyVideoOwnerOfUnblacklist (video: MVideo) { |
383 | const user = await UserModel.loadByVideoId(video.id) | 390 | const user = await UserModel.loadByVideoId(video.id) |
384 | if (!user) return | 391 | if (!user) return |
385 | 392 | ||
@@ -395,7 +402,7 @@ class Notifier { | |||
395 | userId: user.id, | 402 | userId: user.id, |
396 | videoId: video.id | 403 | videoId: video.id |
397 | }) | 404 | }) |
398 | notification.Video = video | 405 | notification.Video = video as VideoModel |
399 | 406 | ||
400 | return notification | 407 | return notification |
401 | } | 408 | } |
@@ -407,7 +414,7 @@ class Notifier { | |||
407 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 414 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
408 | } | 415 | } |
409 | 416 | ||
410 | private async notifyOwnedVideoHasBeenPublished (video: VideoModel) { | 417 | private async notifyOwnedVideoHasBeenPublished (video: MVideoFullLight) { |
411 | const user = await UserModel.loadByVideoId(video.id) | 418 | const user = await UserModel.loadByVideoId(video.id) |
412 | if (!user) return | 419 | if (!user) return |
413 | 420 | ||
@@ -423,7 +430,7 @@ class Notifier { | |||
423 | userId: user.id, | 430 | userId: user.id, |
424 | videoId: video.id | 431 | videoId: video.id |
425 | }) | 432 | }) |
426 | notification.Video = video | 433 | notification.Video = video as VideoModel |
427 | 434 | ||
428 | return notification | 435 | return notification |
429 | } | 436 | } |
@@ -435,7 +442,7 @@ class Notifier { | |||
435 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 442 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
436 | } | 443 | } |
437 | 444 | ||
438 | private async notifyOwnerVideoImportIsFinished (videoImport: VideoImportModel, success: boolean) { | 445 | private async notifyOwnerVideoImportIsFinished (videoImport: MVideoImportVideo, success: boolean) { |
439 | const user = await UserModel.loadByVideoImportId(videoImport.id) | 446 | const user = await UserModel.loadByVideoImportId(videoImport.id) |
440 | if (!user) return | 447 | if (!user) return |
441 | 448 | ||
@@ -451,7 +458,7 @@ class Notifier { | |||
451 | userId: user.id, | 458 | userId: user.id, |
452 | videoImportId: videoImport.id | 459 | videoImportId: videoImport.id |
453 | }) | 460 | }) |
454 | notification.VideoImport = videoImport | 461 | notification.VideoImport = videoImport as VideoImportModel |
455 | 462 | ||
456 | return notification | 463 | return notification |
457 | } | 464 | } |
@@ -465,13 +472,13 @@ class Notifier { | |||
465 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) | 472 | return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) |
466 | } | 473 | } |
467 | 474 | ||
468 | private async notifyModeratorsOfNewUserRegistration (registeredUser: UserModel) { | 475 | private async notifyModeratorsOfNewUserRegistration (registeredUser: MUserAccount) { |
469 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS) | 476 | const moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS) |
470 | if (moderators.length === 0) return | 477 | if (moderators.length === 0) return |
471 | 478 | ||
472 | logger.info( | 479 | logger.info( |
473 | 'Notifying %s moderators of new user registration of %s.', | 480 | 'Notifying %s moderators of new user registration of %s.', |
474 | moderators.length, registeredUser.Account.Actor.preferredUsername | 481 | moderators.length, registeredUser.username |
475 | ) | 482 | ) |
476 | 483 | ||
477 | function settingGetter (user: UserModel) { | 484 | function settingGetter (user: UserModel) { |
@@ -484,7 +491,7 @@ class Notifier { | |||
484 | userId: user.id, | 491 | userId: user.id, |
485 | accountId: registeredUser.Account.id | 492 | accountId: registeredUser.Account.id |
486 | }) | 493 | }) |
487 | notification.Account = registeredUser.Account | 494 | notification.Account = registeredUser.Account as AccountModel |
488 | 495 | ||
489 | return notification | 496 | return notification |
490 | } | 497 | } |
@@ -497,10 +504,10 @@ class Notifier { | |||
497 | } | 504 | } |
498 | 505 | ||
499 | private async notify (options: { | 506 | private async notify (options: { |
500 | users: UserModel[], | 507 | users: MUserWithNotificationSetting[], |
501 | notificationCreator: (user: UserModel) => Promise<UserNotificationModel>, | 508 | notificationCreator: (user: MUserWithNotificationSetting) => Promise<UserNotificationModelForApi>, |
502 | emailSender: (emails: string[]) => Promise<any> | Bluebird<any>, | 509 | emailSender: (emails: string[]) => Promise<any> | Bluebird<any>, |
503 | settingGetter: (user: UserModel) => UserNotificationSettingValue | 510 | settingGetter: (user: MUserWithNotificationSetting) => UserNotificationSettingValue |
504 | }) { | 511 | }) { |
505 | const emails: string[] = [] | 512 | const emails: string[] = [] |
506 | 513 | ||
@@ -521,7 +528,7 @@ class Notifier { | |||
521 | } | 528 | } |
522 | } | 529 | } |
523 | 530 | ||
524 | private isEmailEnabled (user: UserModel, value: UserNotificationSettingValue) { | 531 | private isEmailEnabled (user: MUser, value: UserNotificationSettingValue) { |
525 | if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION === true && user.emailVerified === false) return false | 532 | if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION === true && user.emailVerified === false) return false |
526 | 533 | ||
527 | return value & UserNotificationSettingValue.EMAIL | 534 | return value & UserNotificationSettingValue.EMAIL |