aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-follow.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 17:38:41 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch)
treef1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/activitypub/process/process-follow.ts
parentfadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff)
downloadPeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip
Begin moving video channel to actor
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r--server/lib/activitypub/process/process-follow.ts48
1 files changed, 24 insertions, 24 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index ccaee43a6..ec7a331f3 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -1,16 +1,16 @@
1import { ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { logger, retryTransactionWrapper } from '../../../helpers'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { AccountModel } from '../../../models/account/account' 4import { ActorModel } from '../../../models/activitypub/actor'
5import { AccountFollowModel } from '../../../models/account/account-follow' 5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { getOrCreateAccountAndServer } from '../account' 6import { getOrCreateActorAndServerAndModel } from '../actor'
7import { sendAccept } from '../send' 7import { sendAccept } from '../send'
8 8
9async function processFollowActivity (activity: ActivityFollow) { 9async function processFollowActivity (activity: ActivityFollow) {
10 const activityObject = activity.object 10 const activityObject = activity.object
11 const account = await getOrCreateAccountAndServer(activity.actor) 11 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
12 12
13 return processFollow(account, activityObject) 13 return processFollow(actor, activityObject)
14} 14}
15 15
16// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
@@ -21,46 +21,46 @@ export {
21 21
22// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
23 23
24function processFollow (account: AccountModel, targetAccountURL: string) { 24function processFollow (actor: ActorModel, targetActorURL: string) {
25 const options = { 25 const options = {
26 arguments: [ account, targetAccountURL ], 26 arguments: [ actor, targetActorURL ],
27 errorMessage: 'Cannot follow with many retries.' 27 errorMessage: 'Cannot follow with many retries.'
28 } 28 }
29 29
30 return retryTransactionWrapper(follow, options) 30 return retryTransactionWrapper(follow, options)
31} 31}
32 32
33async function follow (account: AccountModel, targetAccountURL: string) { 33async function follow (actor: ActorModel, targetActorURL: string) {
34 await sequelizeTypescript.transaction(async t => { 34 await sequelizeTypescript.transaction(async t => {
35 const targetAccount = await AccountModel.loadByUrl(targetAccountURL, t) 35 const targetActor = await ActorModel.loadByUrl(targetActorURL, t)
36 36
37 if (!targetAccount) throw new Error('Unknown account') 37 if (!targetActor) throw new Error('Unknown actor')
38 if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') 38 if (targetActor.isOwned() === false) throw new Error('This is not a local actor.')
39 39
40 const [ accountFollow ] = await AccountFollowModel.findOrCreate({ 40 const [ actorFollow ] = await ActorFollowModel.findOrCreate({
41 where: { 41 where: {
42 accountId: account.id, 42 actorId: actor.id,
43 targetAccountId: targetAccount.id 43 targetActorId: targetActor.id
44 }, 44 },
45 defaults: { 45 defaults: {
46 accountId: account.id, 46 actorId: actor.id,
47 targetAccountId: targetAccount.id, 47 targetActorId: targetActor.id,
48 state: 'accepted' 48 state: 'accepted'
49 }, 49 },
50 transaction: t 50 transaction: t
51 }) 51 })
52 52
53 if (accountFollow.state !== 'accepted') { 53 if (actorFollow.state !== 'accepted') {
54 accountFollow.state = 'accepted' 54 actorFollow.state = 'accepted'
55 await accountFollow.save({ transaction: t }) 55 await actorFollow.save({ transaction: t })
56 } 56 }
57 57
58 accountFollow.AccountFollower = account 58 actorFollow.ActorFollower = actor
59 accountFollow.AccountFollowing = targetAccount 59 actorFollow.ActorFollowing = targetActor
60 60
61 // Target sends to account he accepted the follow request 61 // Target sends to actor he accepted the follow request
62 return sendAccept(accountFollow, t) 62 return sendAccept(actorFollow, t)
63 }) 63 })
64 64
65 logger.info('Account uuid %s is followed by account %s.', account.url, targetAccountURL) 65 logger.info('Actor uuid %s is followed by actor %s.', actor.url, targetActorURL)
66} 66}