aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/account.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/account.ts')
-rw-r--r--server/lib/activitypub/account.ts28
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as url from 'url'
3import { ActivityPubActor } from '../../../shared/models/activitypub/activitypub-actor'
4import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub/account'
5import { retryTransactionWrapper } from '../../helpers/database-utils'
6import { logger } from '../../helpers/logger'
7import { doRequest } from '../../helpers/requests'
8import { ACTIVITY_PUB } from '../../initializers/constants'
9import { database as db } from '../../initializers/database'
10import { AccountInstance } from '../../models/account/account-interface'
11import { Transaction } from 'sequelize' 2import { Transaction } from 'sequelize'
3import * as url from 'url'
4import { ActivityPubActor } from '../../../shared/models/activitypub'
5import { doRequest, logger, retryTransactionWrapper } from '../../helpers'
6import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub'
7import { ACTIVITY_PUB, sequelizeTypescript } from '../../initializers'
8import { AccountModel } from '../../models/account/account'
9import { ServerModel } from '../../models/server/server'
12 10
13async function getOrCreateAccountAndServer (accountUrl: string) { 11async 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
31function saveAccountAndServerIfNotExist (account: AccountInstance, t?: Transaction): Bluebird<AccountInstance> | Promise<AccountInstance> { 29function 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
108export { 104export {