aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/server/config.ts17
-rw-r--r--shared/extra-utils/users/user-notifications.ts41
-rw-r--r--shared/models/server/custom-config.model.ts12
-rw-r--r--shared/models/users/user-notification-setting.model.ts1
-rw-r--r--shared/models/users/user-notification.model.ts8
5 files changed, 71 insertions, 8 deletions
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts
index 8736f083f..d784af9a9 100644
--- a/shared/extra-utils/server/config.ts
+++ b/shared/extra-utils/server/config.ts
@@ -1,5 +1,7 @@
1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2import { CustomConfig } from '../../models/server/custom-config.model' 2import { CustomConfig } from '../../models/server/custom-config.model'
3import { DeepPartial } from '@server/typings/utils'
4import { merge } from 'lodash'
3 5
4function getConfig (url: string) { 6function getConfig (url: string) {
5 const path = '/api/v1/config' 7 const path = '/api/v1/config'
@@ -44,7 +46,7 @@ function updateCustomConfig (url: string, token: string, newCustomConfig: Custom
44 }) 46 })
45} 47}
46 48
47function updateCustomSubConfig (url: string, token: string, newConfig: any) { 49function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
48 const updateParams: CustomConfig = { 50 const updateParams: CustomConfig = {
49 instance: { 51 instance: {
50 name: 'PeerTube updated', 52 name: 'PeerTube updated',
@@ -130,10 +132,21 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) {
130 enabled: true, 132 enabled: true,
131 manualApproval: false 133 manualApproval: false
132 } 134 }
135 },
136 followings: {
137 instance: {
138 autoFollowBack: {
139 enabled: false
140 },
141 autoFollowIndex: {
142 indexUrl: 'https://instances.joinpeertube.org',
143 enabled: false
144 }
145 }
133 } 146 }
134 } 147 }
135 148
136 Object.assign(updateParams, newConfig) 149 merge(updateParams, newConfig)
137 150
138 return updateCustomConfig(url, token, updateParams) 151 return updateCustomConfig(url, token, updateParams)
139} 152}
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index f7de542bf..9a5fd7e86 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -279,8 +279,9 @@ async function checkNewActorFollow (
279 expect(notification.actorFollow.follower.name).to.equal(followerName) 279 expect(notification.actorFollow.follower.name).to.equal(followerName)
280 expect(notification.actorFollow.follower.host).to.not.be.undefined 280 expect(notification.actorFollow.follower.host).to.not.be.undefined
281 281
282 expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName) 282 const following = notification.actorFollow.following
283 expect(notification.actorFollow.following.type).to.equal(followType) 283 expect(following.displayName).to.equal(followingDisplayName)
284 expect(following.type).to.equal(followType)
284 } else { 285 } else {
285 expect(notification).to.satisfy(n => { 286 expect(notification).to.satisfy(n => {
286 return n.type !== notificationType || 287 return n.type !== notificationType ||
@@ -327,6 +328,37 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost:
327 await checkNotification(base, notificationChecker, emailFinder, type) 328 await checkNotification(base, notificationChecker, emailFinder, type)
328} 329}
329 330
331async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
332 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
333
334 function notificationChecker (notification: UserNotification, type: CheckerType) {
335 if (type === 'presence') {
336 expect(notification).to.not.be.undefined
337 expect(notification.type).to.equal(notificationType)
338
339 const following = notification.actorFollow.following
340 checkActor(following)
341 expect(following.name).to.equal('peertube')
342 expect(following.host).to.equal(followingHost)
343
344 expect(notification.actorFollow.follower.name).to.equal('peertube')
345 expect(notification.actorFollow.follower.host).to.equal(followerHost)
346 } else {
347 expect(notification).to.satisfy(n => {
348 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
349 })
350 }
351 }
352
353 function emailFinder (email: object) {
354 const text: string = email[ 'text' ]
355
356 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
357 }
358
359 await checkNotification(base, notificationChecker, emailFinder, type)
360}
361
330async function checkCommentMention ( 362async function checkCommentMention (
331 base: CheckerBaseParams, 363 base: CheckerBaseParams,
332 uuid: string, 364 uuid: string,
@@ -427,8 +459,8 @@ async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, vi
427 expect(notification).to.not.be.undefined 459 expect(notification).to.not.be.undefined
428 expect(notification.type).to.equal(notificationType) 460 expect(notification.type).to.equal(notificationType)
429 461
430 expect(notification.video.id).to.be.a('number') 462 expect(notification.videoBlacklist.video.id).to.be.a('number')
431 checkVideo(notification.video, videoName, videoUUID) 463 checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
432 } else { 464 } else {
433 expect(notification).to.satisfy((n: UserNotification) => { 465 expect(notification).to.satisfy((n: UserNotification) => {
434 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID 466 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
@@ -480,6 +512,7 @@ export {
480 markAsReadAllNotifications, 512 markAsReadAllNotifications,
481 checkMyVideoImportIsFinished, 513 checkMyVideoImportIsFinished,
482 checkUserRegistered, 514 checkUserRegistered,
515 checkAutoInstanceFollowing,
483 checkVideoIsPublished, 516 checkVideoIsPublished,
484 checkNewVideoFromSubscription, 517 checkNewVideoFromSubscription,
485 checkNewActorFollow, 518 checkNewActorFollow,
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts
index a0541f5b6..1073ba32c 100644
--- a/shared/models/server/custom-config.model.ts
+++ b/shared/models/server/custom-config.model.ts
@@ -99,4 +99,16 @@ export interface CustomConfig {
99 } 99 }
100 } 100 }
101 101
102 followings: {
103 instance: {
104 autoFollowBack: {
105 enabled: boolean
106 }
107
108 autoFollowIndex: {
109 enabled: boolean
110 indexUrl: string
111 }
112 }
113 }
102} 114}
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts
index e2a882b69..451f40d58 100644
--- a/shared/models/users/user-notification-setting.model.ts
+++ b/shared/models/users/user-notification-setting.model.ts
@@ -16,4 +16,5 @@ export interface UserNotificationSetting {
16 newFollow: UserNotificationSettingValue 16 newFollow: UserNotificationSettingValue
17 commentMention: UserNotificationSettingValue 17 commentMention: UserNotificationSettingValue
18 newInstanceFollower: UserNotificationSettingValue 18 newInstanceFollower: UserNotificationSettingValue
19 autoInstanceFollowing: UserNotificationSettingValue
19} 20}
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts
index fafc2b7d7..e9be1ca7f 100644
--- a/shared/models/users/user-notification.model.ts
+++ b/shared/models/users/user-notification.model.ts
@@ -19,7 +19,9 @@ export enum UserNotificationType {
19 19
20 VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12, 20 VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12,
21 21
22 NEW_INSTANCE_FOLLOWER = 13 22 NEW_INSTANCE_FOLLOWER = 13,
23
24 AUTO_INSTANCE_FOLLOWING = 14
23} 25}
24 26
25export interface VideoInfo { 27export interface VideoInfo {
@@ -78,10 +80,12 @@ export interface UserNotification {
78 id: number 80 id: number
79 follower: ActorInfo 81 follower: ActorInfo
80 state: FollowState 82 state: FollowState
83
81 following: { 84 following: {
82 type: 'account' | 'channel' 85 type: 'account' | 'channel' | 'instance'
83 name: string 86 name: string
84 displayName: string 87 displayName: string
88 host: string
85 } 89 }
86 } 90 }
87 91