aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
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 /server/lib/job-queue
parentf69ec5f340638ef577e8f5b9b1fb844778656a1f (diff)
downloadPeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.gz
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.zst
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.zip
Add auto follow back support for instances
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts24
-rw-r--r--server/lib/job-queue/handlers/video-import.ts5
2 files changed, 17 insertions, 12 deletions
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'
10import { ActorModel } from '../../../models/activitypub/actor' 10import { ActorModel } from '../../../models/activitypub/actor'
11import { Notifier } from '../../notifier' 11import { Notifier } from '../../notifier'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models' 13import { MActor, MActorFollowActors, MActorFull } from '../../../typings/models'
14 14
15export type ActivitypubFollowPayload = { 15export type ActivitypubFollowPayload = {
16 followerActorId: number 16 followerActorId: number
17 name: string 17 name: string
18 host: string 18 host: string
19 isAutoFollow?: boolean
19} 20}
20 21
21async function processActivityPubFollow (job: Bull.Job) { 22async function processActivityPubFollow (job: Bull.Job) {
@@ -35,7 +36,7 @@ async function processActivityPubFollow (job: Bull.Job) {
35 36
36 const fromActor = await ActorModel.load(payload.followerActorId) 37 const fromActor = await ActorModel.load(payload.followerActorId)
37 38
38 return retryTransactionWrapper(follow, fromActor, targetActor) 39 return retryTransactionWrapper(follow, fromActor, targetActor, payload.isAutoFollow)
39} 40}
40// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
41 42
@@ -45,7 +46,7 @@ export {
45 46
46// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
47 48
48async function follow (fromActor: MActor, targetActor: MActorFull) { 49async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow = false) {
49 if (fromActor.id === targetActor.id) { 50 if (fromActor.id === targetActor.id) {
50 throw new Error('Follower is the same than target actor.') 51 throw new Error('Follower is the same than target actor.')
51 } 52 }
@@ -75,14 +76,15 @@ async function follow (fromActor: MActor, targetActor: MActorFull) {
75 return actorFollow 76 return actorFollow
76 }) 77 })
77 78
78 if (actorFollow.state === 'accepted') { 79 const followerFull = await ActorModel.loadFull(fromActor.id)
79 const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount })
80 80
81 const actorFollowFull = Object.assign(actorFollow, { 81 const actorFollowFull = Object.assign(actorFollow, {
82 ActorFollowing: targetActor, 82 ActorFollowing: targetActor,
83 ActorFollower: followerFull 83 ActorFollower: followerFull
84 }) 84 })
85 85
86 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) 86 if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
87 } 87 if (isAutoFollow === true) Notifier.Instance.notifyOfAutoInstanceFollowing(actorFollowFull)
88
89 return actorFollow
88} 90}
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
21import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 21import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
22import { MThumbnail } from '../../../typings/models/video/thumbnail' 22import { MThumbnail } from '../../../typings/models/video/thumbnail'
23import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import' 23import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import'
24import { MVideoBlacklistVideo, MVideoBlacklist } from '@server/typings/models'
24 25
25type VideoImportYoutubeDLPayload = { 26type VideoImportYoutubeDLPayload = {
26 type: 'youtube-dl' 27 type: 'youtube-dl'
@@ -204,7 +205,9 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
204 Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true) 205 Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true)
205 206
206 if (video.isBlacklisted()) { 207 if (video.isBlacklisted()) {
207 Notifier.Instance.notifyOnVideoAutoBlacklist(video) 208 const videoBlacklist = Object.assign(video.VideoBlacklist, { Video: video })
209
210 Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
208 } else { 211 } else {
209 Notifier.Instance.notifyOnNewVideoIfNeeded(video) 212 Notifier.Instance.notifyOnNewVideoIfNeeded(video)
210 } 213 }