diff options
Diffstat (limited to 'server/lib/activitypub/account.ts')
-rw-r--r-- | server/lib/activitypub/account.ts | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/server/lib/activitypub/account.ts b/server/lib/activitypub/account.ts index 906c8ff29..45690b88d 100644 --- a/server/lib/activitypub/account.ts +++ b/server/lib/activitypub/account.ts | |||
@@ -1,17 +1,15 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as url from 'url' | ||
3 | import { ActivityPubActor } from '../../../shared/models/activitypub/activitypub-actor' | ||
4 | import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub/account' | ||
5 | import { retryTransactionWrapper } from '../../helpers/database-utils' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | import { doRequest } from '../../helpers/requests' | ||
8 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
9 | import { database as db } from '../../initializers/database' | ||
10 | import { AccountInstance } from '../../models/account/account-interface' | ||
11 | import { Transaction } from 'sequelize' | 2 | import { Transaction } from 'sequelize' |
3 | import * as url from 'url' | ||
4 | import { ActivityPubActor } from '../../../shared/models/activitypub' | ||
5 | import { doRequest, logger, retryTransactionWrapper } from '../../helpers' | ||
6 | import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub' | ||
7 | import { ACTIVITY_PUB, sequelizeTypescript } from '../../initializers' | ||
8 | import { AccountModel } from '../../models/account/account' | ||
9 | import { ServerModel } from '../../models/server/server' | ||
12 | 10 | ||
13 | async function getOrCreateAccountAndServer (accountUrl: string) { | 11 | async function getOrCreateAccountAndServer (accountUrl: string) { |
14 | let account = await db.Account.loadByUrl(accountUrl) | 12 | let account = await AccountModel.loadByUrl(accountUrl) |
15 | 13 | ||
16 | // We don't have this account in our database, fetch it on remote | 14 | // We don't have this account in our database, fetch it on remote |
17 | if (!account) { | 15 | if (!account) { |
@@ -28,11 +26,11 @@ async function getOrCreateAccountAndServer (accountUrl: string) { | |||
28 | return account | 26 | return account |
29 | } | 27 | } |
30 | 28 | ||
31 | function saveAccountAndServerIfNotExist (account: AccountInstance, t?: Transaction): Bluebird<AccountInstance> | Promise<AccountInstance> { | 29 | function saveAccountAndServerIfNotExist (account: AccountModel, t?: Transaction): Bluebird<AccountModel> | Promise<AccountModel> { |
32 | if (t !== undefined) { | 30 | if (t !== undefined) { |
33 | return save(t) | 31 | return save(t) |
34 | } else { | 32 | } else { |
35 | return db.sequelize.transaction(t => { | 33 | return sequelizeTypescript.transaction(t => { |
36 | return save(t) | 34 | return save(t) |
37 | }) | 35 | }) |
38 | } | 36 | } |
@@ -49,7 +47,7 @@ function saveAccountAndServerIfNotExist (account: AccountInstance, t?: Transacti | |||
49 | }, | 47 | }, |
50 | transaction: t | 48 | transaction: t |
51 | } | 49 | } |
52 | const [ server ] = await db.Server.findOrCreate(serverOptions) | 50 | const [ server ] = await ServerModel.findOrCreate(serverOptions) |
53 | 51 | ||
54 | // Save our new account in database | 52 | // Save our new account in database |
55 | account.set('serverId', server.id) | 53 | account.set('serverId', server.id) |
@@ -87,7 +85,7 @@ async function fetchRemoteAccount (accountUrl: string) { | |||
87 | const followersCount = await fetchAccountCount(accountJSON.followers) | 85 | const followersCount = await fetchAccountCount(accountJSON.followers) |
88 | const followingCount = await fetchAccountCount(accountJSON.following) | 86 | const followingCount = await fetchAccountCount(accountJSON.following) |
89 | 87 | ||
90 | const account = db.Account.build({ | 88 | return new AccountModel({ |
91 | uuid: accountJSON.uuid, | 89 | uuid: accountJSON.uuid, |
92 | name: accountJSON.preferredUsername, | 90 | name: accountJSON.preferredUsername, |
93 | url: accountJSON.url, | 91 | url: accountJSON.url, |
@@ -101,8 +99,6 @@ async function fetchRemoteAccount (accountUrl: string) { | |||
101 | followersUrl: accountJSON.followers, | 99 | followersUrl: accountJSON.followers, |
102 | followingUrl: accountJSON.following | 100 | followingUrl: accountJSON.following |
103 | }) | 101 | }) |
104 | |||
105 | return account | ||
106 | } | 102 | } |
107 | 103 | ||
108 | export { | 104 | export { |