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 --- .../lib/job-queue/handlers/activitypub-follow.ts | 24 ++++++++++++---------- server/lib/job-queue/handlers/video-import.ts | 5 ++++- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'server/lib/job-queue/handlers') diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 5cb55cad6..af7c8a838 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts @@ -10,12 +10,13 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { ActorModel } from '../../../models/activitypub/actor' import { Notifier } from '../../notifier' import { sequelizeTypescript } from '../../../initializers/database' -import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models' +import { MActor, MActorFollowActors, MActorFull } from '../../../typings/models' export type ActivitypubFollowPayload = { followerActorId: number name: string host: string + isAutoFollow?: boolean } async function processActivityPubFollow (job: Bull.Job) { @@ -35,7 +36,7 @@ async function processActivityPubFollow (job: Bull.Job) { const fromActor = await ActorModel.load(payload.followerActorId) - return retryTransactionWrapper(follow, fromActor, targetActor) + return retryTransactionWrapper(follow, fromActor, targetActor, payload.isAutoFollow) } // --------------------------------------------------------------------------- @@ -45,7 +46,7 @@ export { // --------------------------------------------------------------------------- -async function follow (fromActor: MActor, targetActor: MActorFull) { +async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow = false) { if (fromActor.id === targetActor.id) { throw new Error('Follower is the same than target actor.') } @@ -75,14 +76,15 @@ async function follow (fromActor: MActor, targetActor: MActorFull) { return actorFollow }) - if (actorFollow.state === 'accepted') { - const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount }) + const followerFull = await ActorModel.loadFull(fromActor.id) - const actorFollowFull = Object.assign(actorFollow, { - ActorFollowing: targetActor, - ActorFollower: followerFull - }) + const actorFollowFull = Object.assign(actorFollow, { + ActorFollowing: targetActor, + ActorFollower: followerFull + }) - Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) - } + if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) + if (isAutoFollow === true) Notifier.Instance.notifyOfAutoInstanceFollowing(actorFollowFull) + + return actorFollow } diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index ff8c93328..93a3e9d90 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -21,6 +21,7 @@ import { createVideoMiniatureFromUrl, generateVideoMiniature } from '../../thumb import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { MThumbnail } from '../../../typings/models/video/thumbnail' import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import' +import { MVideoBlacklistVideo, MVideoBlacklist } from '@server/typings/models' type VideoImportYoutubeDLPayload = { type: 'youtube-dl' @@ -204,7 +205,9 @@ async function processFile (downloader: () => Promise, videoImport: MVid Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true) if (video.isBlacklisted()) { - Notifier.Instance.notifyOnVideoAutoBlacklist(video) + const videoBlacklist = Object.assign(video.VideoBlacklist, { Video: video }) + + Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist) } else { Notifier.Instance.notifyOnNewVideoIfNeeded(video) } -- cgit v1.2.3