From e1b49ee534108ba8ac98dcb209d2efcbf1ecd678 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Sep 2019 14:30:34 +0200 Subject: Implement auto follow in client --- .../edit-custom-config.component.html | 35 +++++++++++++++++++ .../edit-custom-config.component.ts | 11 ++++++ ...y-account-notification-preferences.component.ts | 6 ++-- .../custom-config-validators.service.ts | 9 +++++ .../app/shared/users/user-notification.model.ts | 7 +++- .../shared/users/user-notifications.component.html | 10 +++++- server/initializers/constants.ts | 2 +- .../0430-auto-follow-notification-setting.ts | 40 ++++++++++++++++++++++ 8 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 server/initializers/migrations/0430-auto-follow-notification-setting.ts diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html index fe9d856d0..ec6f879d7 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html @@ -221,6 +221,41 @@ +
Instance followings
+ + + + + +
+ +
+
+ + +
+ +
+ +
+ + +
{{ formErrors.followings.instance.autoFollowIndex.indexUrl }}
+
+ +
+
+
+
Administrator
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 8bd7f7cf6..d51104569 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -158,6 +158,17 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { enabled: null, manualApproval: null } + }, + followings: { + instance: { + autoFollowBack: { + enabled: null + }, + autoFollowIndex: { + enabled: null, + indexUrl: this.customConfigValidatorsService.INDEX_URL + } + } } } diff --git a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts index 34febc457..76fabb19d 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts @@ -43,7 +43,8 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { newUserRegistration: this.i18n('A new user registered on your instance'), newFollow: this.i18n('You or your channel(s) has a new follower'), commentMention: this.i18n('Someone mentioned you in video comments'), - newInstanceFollower: this.i18n('Your instance has a new follower') + newInstanceFollower: this.i18n('Your instance has a new follower'), + autoInstanceFollowing: this.i18n('Your instance auto followed another instance') } this.notificationSettingKeys = Object.keys(this.labelNotifications) as (keyof UserNotificationSetting)[] @@ -51,7 +52,8 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { videoAbuseAsModerator: UserRight.MANAGE_VIDEO_ABUSES, videoAutoBlacklistAsModerator: UserRight.MANAGE_VIDEO_BLACKLIST, newUserRegistration: UserRight.MANAGE_USERS, - newInstanceFollower: UserRight.MANAGE_SERVER_FOLLOW + newInstanceFollower: UserRight.MANAGE_SERVER_FOLLOW, + autoInstanceFollowing: UserRight.MANAGE_CONFIGURATION } this.emailEnabled = this.serverService.getConfig().email.enabled diff --git a/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts b/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts index 882e39453..767e3f026 100644 --- a/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts @@ -13,6 +13,7 @@ export class CustomConfigValidatorsService { readonly SIGNUP_LIMIT: BuildFormValidator readonly ADMIN_EMAIL: BuildFormValidator readonly TRANSCODING_THREADS: BuildFormValidator + readonly INDEX_URL: BuildFormValidator constructor (private i18n: I18n) { this.INSTANCE_NAME = { @@ -78,5 +79,13 @@ export class CustomConfigValidatorsService { 'min': this.i18n('Transcoding threads must be greater or equal to 0.') } } + + this.INDEX_URL = { + VALIDATORS: [ Validators.required, Validators.pattern(/^https:\/\//) ], + MESSAGES: { + 'required': this.i18n('Index URL is required.'), + 'pattern': this.i18n('Index URL should be a URL') + } + } } } diff --git a/client/src/app/shared/users/user-notification.model.ts b/client/src/app/shared/users/user-notification.model.ts index 37fa29ee8..b4ac075c5 100644 --- a/client/src/app/shared/users/user-notification.model.ts +++ b/client/src/app/shared/users/user-notification.model.ts @@ -42,9 +42,10 @@ export class UserNotification implements UserNotificationServer { state: FollowState follower: ActorInfo & { avatarUrl?: string } following: { - type: 'account' | 'channel' + type: 'account' | 'channel' | 'instance' name: string displayName: string + host: string } } @@ -146,6 +147,10 @@ export class UserNotification implements UserNotificationServer { case UserNotificationType.NEW_INSTANCE_FOLLOWER: this.instanceFollowUrl = '/admin/follows/followers-list' break + + case UserNotificationType.AUTO_INSTANCE_FOLLOWING: + this.instanceFollowUrl = '/admin/follows/following-list' + break } } catch (err) { this.type = null diff --git a/client/src/app/shared/users/user-notifications.component.html b/client/src/app/shared/users/user-notifications.component.html index 292813426..0702d3b5e 100644 --- a/client/src/app/shared/users/user-notifications.component.html +++ b/client/src/app/shared/users/user-notifications.component.html @@ -40,7 +40,7 @@
- The recently added video {{ notification.video.name }} has been auto-blacklisted + The recently added video {{ notification.videoBlacklist.video.name }} has been auto-blacklisted
@@ -111,6 +111,14 @@ awaiting your approval + + + + +
+ Your instance automatically followed {{ notification.actorFollow.following.host }} +
+
{{ notification.createdAt | myFromNow }}
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 7c0c5a87c..01d4f1d74 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 425 +const LAST_MIGRATION_VERSION = 430 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0430-auto-follow-notification-setting.ts b/server/initializers/migrations/0430-auto-follow-notification-setting.ts new file mode 100644 index 000000000..034bdd46d --- /dev/null +++ b/server/initializers/migrations/0430-auto-follow-notification-setting.ts @@ -0,0 +1,40 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + { + const data = { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: true + } + await utils.queryInterface.addColumn('userNotificationSetting', 'autoInstanceFollowing', data) + } + + { + const query = 'UPDATE "userNotificationSetting" SET "autoInstanceFollowing" = 1' + await utils.sequelize.query(query) + } + + { + const data = { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: false + } + await utils.queryInterface.changeColumn('userNotificationSetting', 'autoInstanceFollowing', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3