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 --- server/models/account/account.ts | 2 +- server/models/account/user-notification-setting.ts | 12 +++++++++++- server/models/account/user-notification.ts | 19 +++++++++++++++---- server/models/activitypub/actor.ts | 12 ++---------- server/models/server/server.ts | 10 ++++++++++ server/models/video/video-channel.ts | 2 +- 6 files changed, 40 insertions(+), 17 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 394a55f5e..ba1094536 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -381,7 +381,7 @@ export class AccountModel extends Model { } toActivityPubObject (this: MAccountAP) { - const obj = this.Actor.toActivityPubObject(this.name, 'Account') + const obj = this.Actor.toActivityPubObject(this.name) return Object.assign(obj, { summary: this.description diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts index 1506295cf..dc69a17fd 100644 --- a/server/models/account/user-notification-setting.ts +++ b/server/models/account/user-notification-setting.ts @@ -111,6 +111,15 @@ export class UserNotificationSettingModel extends Model throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing') + ) + @Column + autoInstanceFollowing: UserNotificationSettingValue + @AllowNull(false) @Default(null) @Is( @@ -165,7 +174,8 @@ export class UserNotificationSettingModel extends Model { const account = this.Account ? this.formatActor(this.Account) : undefined + const actorFollowingType = { + Application: 'instance' as 'instance', + Group: 'channel' as 'channel', + Person: 'account' as 'account' + } const actorFollow = this.ActorFollow ? { id: this.ActorFollow.id, state: this.ActorFollow.state, @@ -415,9 +425,10 @@ export class UserNotificationModel extends Model { host: this.ActorFollow.ActorFollower.getHost() }, following: { - type: this.ActorFollow.ActorFollowing.VideoChannel ? 'channel' as 'channel' : 'account' as 'account', + type: actorFollowingType[this.ActorFollow.ActorFollowing.type], displayName: (this.ActorFollow.ActorFollowing.VideoChannel || this.ActorFollow.ActorFollowing.Account).getDisplayName(), - name: this.ActorFollow.ActorFollowing.preferredUsername + name: this.ActorFollow.ActorFollowing.preferredUsername, + host: this.ActorFollow.ActorFollowing.getHost() } } : undefined diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 67a1b5bc1..05de1905d 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -43,7 +43,6 @@ import { MActorFormattable, MActorFull, MActorHost, - MActorRedundancyAllowedOpt, MActorServer, MActorSummaryFormattable } from '../../typings/models' @@ -430,15 +429,8 @@ export class ActorModel extends Model { }) } - toActivityPubObject (this: MActorAP, name: string, type: 'Account' | 'Application' | 'VideoChannel') { + toActivityPubObject (this: MActorAP, name: string) { let activityPubType - if (type === 'Account') { - activityPubType = 'Person' as 'Person' - } else if (type === 'Application') { - activityPubType = 'Application' as 'Application' - } else { // VideoChannel - activityPubType = 'Group' as 'Group' - } let icon = undefined if (this.avatarId) { @@ -451,7 +443,7 @@ export class ActorModel extends Model { } const json = { - type: activityPubType, + type: this.type, id: this.url, following: this.getFollowingUrl(), followers: this.getFollowersUrl(), diff --git a/server/models/server/server.ts b/server/models/server/server.ts index 3b6759b5c..8b07115f1 100644 --- a/server/models/server/server.ts +++ b/server/models/server/server.ts @@ -51,6 +51,16 @@ export class ServerModel extends Model { }) BlockedByAccounts: ServerBlocklistModel[] + static load (id: number): Bluebird { + const query = { + where: { + id + } + } + + return ServerModel.findOne(query) + } + static loadByHost (host: string): Bluebird { const query = { where: { diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 7178631b4..05545bd9d 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -517,7 +517,7 @@ export class VideoChannelModel extends Model { } toActivityPubObject (this: MChannelAP): ActivityPubActor { - const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel') + const obj = this.Actor.toActivityPubObject(this.name) return Object.assign(obj, { summary: this.description, -- cgit v1.2.3