aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-30 16:50:12 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-09-04 16:24:58 +0200
commit8424c4026afd7304880a4ce8138a04ffb3d8c938 (patch)
tree5b42625a59307b03333aa7d293b40b4c90da8f73 /shared/extra-utils
parentf69ec5f340638ef577e8f5b9b1fb844778656a1f (diff)
downloadPeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.gz
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.zst
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.zip
Add auto follow back support for instances
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/server/config.ts17
-rw-r--r--shared/extra-utils/users/user-notifications.ts41
2 files changed, 52 insertions, 6 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,