aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/notifier.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-22 17:06:26 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-29 09:32:20 +0200
commit696d83fd1377486dd03cc1bd02a21d9b6ddd9fcd (patch)
treee1b88451c4357add80721f530993e2b48d197feb /server/lib/notifier.ts
parent72c33e716fecd1826dcf645957f8669821f91ff3 (diff)
downloadPeerTube-696d83fd1377486dd03cc1bd02a21d9b6ddd9fcd.tar.gz
PeerTube-696d83fd1377486dd03cc1bd02a21d9b6ddd9fcd.tar.zst
PeerTube-696d83fd1377486dd03cc1bd02a21d9b6ddd9fcd.zip
Block comments from muted accounts/servers
Add better control for users of comments displayed on their videos: * Do not forward comments from muted remote accounts/servers (muted by the current server or by the video owner) * Do not list threads and hide replies (with their children) of accounts/servers muted by the video owner * Hide from RSS comments of muted accounts/servers by video owners Use case: * Try to limit spam propagation in the federation * Add ability for users to automatically hide comments on their videos from undesirable accounts/servers (the comment section belongs to videomakers, so they choose what's posted there)
Diffstat (limited to 'server/lib/notifier.ts')
-rw-r--r--server/lib/notifier.ts55
1 files changed, 25 insertions, 30 deletions
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 017739523..89f91e031 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -1,12 +1,22 @@
1import { getServerActor } from '@server/models/application/application'
2import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
3import {
4 MUser,
5 MUserAccount,
6 MUserDefault,
7 MUserNotifSettingAccount,
8 MUserWithNotificationSetting,
9 UserNotificationModelForApi
10} from '@server/typings/models/user'
11import { MVideoImportVideo } from '@server/typings/models/video/video-import'
1import { UserNotificationSettingValue, UserNotificationType, UserRight } from '../../shared/models/users' 12import { UserNotificationSettingValue, UserNotificationType, UserRight } from '../../shared/models/users'
13import { VideoAbuse, VideoPrivacy, VideoState } from '../../shared/models/videos'
2import { logger } from '../helpers/logger' 14import { logger } from '../helpers/logger'
3import { Emailer } from './emailer'
4import { UserNotificationModel } from '../models/account/user-notification'
5import { UserModel } from '../models/account/user'
6import { PeerTubeSocket } from './peertube-socket'
7import { CONFIG } from '../initializers/config' 15import { CONFIG } from '../initializers/config'
8import { VideoPrivacy, VideoState, VideoAbuse } from '../../shared/models/videos'
9import { AccountBlocklistModel } from '../models/account/account-blocklist' 16import { AccountBlocklistModel } from '../models/account/account-blocklist'
17import { UserModel } from '../models/account/user'
18import { UserNotificationModel } from '../models/account/user-notification'
19import { MAccountServer, MActorFollowFull } from '../typings/models'
10import { 20import {
11 MCommentOwnerVideo, 21 MCommentOwnerVideo,
12 MVideoAbuseVideo, 22 MVideoAbuseVideo,
@@ -15,18 +25,9 @@ import {
15 MVideoBlacklistVideo, 25 MVideoBlacklistVideo,
16 MVideoFullLight 26 MVideoFullLight
17} from '../typings/models/video' 27} from '../typings/models/video'
18import { 28import { isBlockedByServerOrAccount } from './blocklist'
19 MUser, 29import { Emailer } from './emailer'
20 MUserAccount, 30import { PeerTubeSocket } from './peertube-socket'
21 MUserDefault,
22 MUserNotifSettingAccount,
23 MUserWithNotificationSetting,
24 UserNotificationModelForApi
25} from '@server/typings/models/user'
26import { MAccountDefault, MActorFollowFull } from '../typings/models'
27import { MVideoImportVideo } from '@server/typings/models/video/video-import'
28import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
29import { getServerActor } from '@server/models/application/application'
30 31
31class Notifier { 32class Notifier {
32 33
@@ -169,7 +170,7 @@ class Notifier {
169 // Not our user or user comments its own video 170 // Not our user or user comments its own video
170 if (!user || comment.Account.userId === user.id) return 171 if (!user || comment.Account.userId === user.id) return
171 172
172 if (await this.isBlockedByServerOrAccount(user, comment.Account)) return 173 if (await this.isBlockedByServerOrUser(comment.Account, user)) return
173 174
174 logger.info('Notifying user %s of new comment %s.', user.username, comment.url) 175 logger.info('Notifying user %s of new comment %s.', user.username, comment.url)
175 176
@@ -270,7 +271,7 @@ class Notifier {
270 const followerAccount = actorFollow.ActorFollower.Account 271 const followerAccount = actorFollow.ActorFollower.Account
271 const followerAccountWithActor = Object.assign(followerAccount, { Actor: actorFollow.ActorFollower }) 272 const followerAccountWithActor = Object.assign(followerAccount, { Actor: actorFollow.ActorFollower })
272 273
273 if (await this.isBlockedByServerOrAccount(user, followerAccountWithActor)) return 274 if (await this.isBlockedByServerOrUser(followerAccountWithActor, user)) return
274 275
275 logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName()) 276 logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName())
276 277
@@ -299,6 +300,9 @@ class Notifier {
299 private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowFull) { 300 private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowFull) {
300 const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW) 301 const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
301 302
303 const follower = Object.assign(actorFollow.ActorFollower.Account, { Actor: actorFollow.ActorFollower })
304 if (await this.isBlockedByServerOrUser(follower)) return
305
302 logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url) 306 logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url)
303 307
304 function settingGetter (user: MUserWithNotificationSetting) { 308 function settingGetter (user: MUserWithNotificationSetting) {
@@ -590,17 +594,8 @@ class Notifier {
590 return value & UserNotificationSettingValue.WEB 594 return value & UserNotificationSettingValue.WEB
591 } 595 }
592 596
593 private async isBlockedByServerOrAccount (user: MUserAccount, targetAccount: MAccountDefault) { 597 private isBlockedByServerOrUser (targetAccount: MAccountServer, user?: MUserAccount) {
594 const serverAccountId = (await getServerActor()).Account.id 598 return isBlockedByServerOrAccount(targetAccount, user?.Account)
595 const sourceAccounts = [ serverAccountId, user.Account.id ]
596
597 const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, targetAccount.id)
598 if (accountMutedHash[serverAccountId] || accountMutedHash[user.Account.id]) return true
599
600 const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, targetAccount.Actor.serverId)
601 if (instanceMutedHash[serverAccountId] || instanceMutedHash[user.Account.id]) return true
602
603 return false
604 } 599 }
605 600
606 static get Instance () { 601 static get Instance () {