aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 15:25:20 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch)
treeac197f3ed0768529456225ad76c912f22bc55e29 /server/lib/job-queue
parent4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff)
downloadPeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index 393c6936c..282dde268 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -1,7 +1,7 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { getServerActor } from '../../../helpers/utils' 3import { getServerActor } from '../../../helpers/utils'
4import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' 4import { REMOTE_SCHEME, sequelizeTypescript } from '../../../initializers'
5import { sendFollow } from '../../activitypub/send' 5import { sendFollow } from '../../activitypub/send'
6import { sanitizeHost } from '../../../helpers/core-utils' 6import { sanitizeHost } from '../../../helpers/core-utils'
7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' 7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
@@ -11,6 +11,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
11import { ActorModel } from '../../../models/activitypub/actor' 11import { ActorModel } from '../../../models/activitypub/actor'
12 12
13export type ActivitypubFollowPayload = { 13export type ActivitypubFollowPayload = {
14 followerActorId: number
15 name: string
14 host: string 16 host: string
15} 17}
16 18
@@ -22,10 +24,10 @@ async function processActivityPubFollow (job: Bull.Job) {
22 24
23 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) 25 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP)
24 26
25 const actorUrl = await loadActorUrlOrGetFromWebfinger(SERVER_ACTOR_NAME, sanitizedHost) 27 const actorUrl = await loadActorUrlOrGetFromWebfinger(payload.name + '@' + sanitizedHost)
26 const targetActor = await getOrCreateActorAndServerAndModel(actorUrl) 28 const targetActor = await getOrCreateActorAndServerAndModel(actorUrl)
27 29
28 const fromActor = await getServerActor() 30 const fromActor = await ActorModel.load(payload.followerActorId)
29 31
30 return retryTransactionWrapper(follow, fromActor, targetActor) 32 return retryTransactionWrapper(follow, fromActor, targetActor)
31} 33}
@@ -42,6 +44,9 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) {
42 throw new Error('Follower is the same than target actor.') 44 throw new Error('Follower is the same than target actor.')
43 } 45 }
44 46
47 // Same server, direct accept
48 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
49
45 return sequelizeTypescript.transaction(async t => { 50 return sequelizeTypescript.transaction(async t => {
46 const [ actorFollow ] = await ActorFollowModel.findOrCreate({ 51 const [ actorFollow ] = await ActorFollowModel.findOrCreate({
47 where: { 52 where: {
@@ -49,7 +54,7 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) {
49 targetActorId: targetActor.id 54 targetActorId: targetActor.id
50 }, 55 },
51 defaults: { 56 defaults: {
52 state: 'pending', 57 state,
53 actorId: fromActor.id, 58 actorId: fromActor.id,
54 targetActorId: targetActor.id 59 targetActorId: targetActor.id
55 }, 60 },