diff options
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 48 |
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 @@ | |||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountModel } from '../../../models/account/account' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { AccountFollowModel } from '../../../models/account/account-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
6 | import { getOrCreateAccountAndServer } from '../account' | 6 | import { getOrCreateActorAndServerAndModel } from '../actor' |
7 | import { sendAccept } from '../send' | 7 | import { sendAccept } from '../send' |
8 | 8 | ||
9 | async function processFollowActivity (activity: ActivityFollow) { | 9 | async 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 | ||
24 | function processFollow (account: AccountModel, targetAccountURL: string) { | 24 | function 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 | ||
33 | async function follow (account: AccountModel, targetAccountURL: string) { | 33 | async 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 | } |