From 8424c4026afd7304880a4ce8138a04ffb3d8c938 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Aug 2019 16:50:12 +0200 Subject: Add auto follow back support for instances --- shared/extra-utils/server/config.ts | 17 +++++++-- shared/extra-utils/users/user-notifications.ts | 41 +++++++++++++++++++--- shared/models/server/custom-config.model.ts | 12 +++++++ .../users/user-notification-setting.model.ts | 1 + shared/models/users/user-notification.model.ts | 8 +++-- 5 files changed, 71 insertions(+), 8 deletions(-) (limited to 'shared') 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 @@ import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' import { CustomConfig } from '../../models/server/custom-config.model' +import { DeepPartial } from '@server/typings/utils' +import { merge } from 'lodash' function getConfig (url: string) { const path = '/api/v1/config' @@ -44,7 +46,7 @@ function updateCustomConfig (url: string, token: string, newCustomConfig: Custom }) } -function updateCustomSubConfig (url: string, token: string, newConfig: any) { +function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial) { const updateParams: CustomConfig = { instance: { name: 'PeerTube updated', @@ -130,10 +132,21 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { enabled: true, manualApproval: false } + }, + followings: { + instance: { + autoFollowBack: { + enabled: false + }, + autoFollowIndex: { + indexUrl: 'https://instances.joinpeertube.org', + enabled: false + } + } } } - Object.assign(updateParams, newConfig) + merge(updateParams, newConfig) return updateCustomConfig(url, token, updateParams) } 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 ( expect(notification.actorFollow.follower.name).to.equal(followerName) expect(notification.actorFollow.follower.host).to.not.be.undefined - expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName) - expect(notification.actorFollow.following.type).to.equal(followType) + const following = notification.actorFollow.following + expect(following.displayName).to.equal(followingDisplayName) + expect(following.type).to.equal(followType) } else { expect(notification).to.satisfy(n => { return n.type !== notificationType || @@ -327,6 +328,37 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: await checkNotification(base, notificationChecker, emailFinder, type) } +async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) { + const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + const following = notification.actorFollow.following + checkActor(following) + expect(following.name).to.equal('peertube') + expect(following.host).to.equal(followingHost) + + expect(notification.actorFollow.follower.name).to.equal('peertube') + expect(notification.actorFollow.follower.host).to.equal(followerHost) + } else { + expect(notification).to.satisfy(n => { + return n.type !== notificationType || n.actorFollow.following.host !== followingHost + }) + } + } + + function emailFinder (email: object) { + const text: string = email[ 'text' ] + + return text.includes(' automatically followed a new instance') && text.includes(followingHost) + } + + await checkNotification(base, notificationChecker, emailFinder, type) +} + async function checkCommentMention ( base: CheckerBaseParams, uuid: string, @@ -427,8 +459,8 @@ async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, vi expect(notification).to.not.be.undefined expect(notification.type).to.equal(notificationType) - expect(notification.video.id).to.be.a('number') - checkVideo(notification.video, videoName, videoUUID) + expect(notification.videoBlacklist.video.id).to.be.a('number') + checkVideo(notification.videoBlacklist.video, videoName, videoUUID) } else { expect(notification).to.satisfy((n: UserNotification) => { return n === undefined || n.video === undefined || n.video.uuid !== videoUUID @@ -480,6 +512,7 @@ export { markAsReadAllNotifications, checkMyVideoImportIsFinished, checkUserRegistered, + checkAutoInstanceFollowing, checkVideoIsPublished, checkNewVideoFromSubscription, 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 { } } + followings: { + instance: { + autoFollowBack: { + enabled: boolean + } + + autoFollowIndex: { + enabled: boolean + indexUrl: string + } + } + } } 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 { newFollow: UserNotificationSettingValue commentMention: UserNotificationSettingValue newInstanceFollower: UserNotificationSettingValue + autoInstanceFollowing: UserNotificationSettingValue } 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 { VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12, - NEW_INSTANCE_FOLLOWER = 13 + NEW_INSTANCE_FOLLOWER = 13, + + AUTO_INSTANCE_FOLLOWING = 14 } export interface VideoInfo { @@ -78,10 +80,12 @@ export interface UserNotification { id: number follower: ActorInfo state: FollowState + following: { - type: 'account' | 'channel' + type: 'account' | 'channel' | 'instance' name: string displayName: string + host: string } } -- cgit v1.2.3