From fadf619ad61a016c1c7fc53de5a8f398a4f77519 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Dec 2017 11:18:49 +0100 Subject: Save --- server/lib/user.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'server/lib') diff --git a/server/lib/user.ts b/server/lib/user.ts index c4722fae2..6aeb198b9 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -3,6 +3,7 @@ import { createPrivateAndPublicKeys, logger } from '../helpers' import { CONFIG, sequelizeTypescript } from '../initializers' import { AccountModel } from '../models/account/account' import { UserModel } from '../models/account/user' +import { ActorModel } from '../models/activitypub/actor' import { getAccountActivityPubUrl } from './activitypub' import { createVideoChannel } from './video-channel' @@ -27,9 +28,10 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true // Set account keys, this could be long so process after the account creation and do not block the client const { publicKey, privateKey } = await createPrivateAndPublicKeys() - account.set('publicKey', publicKey) - account.set('privateKey', privateKey) - account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err)) + const actor = account.Actor + actor.set('publicKey', publicKey) + actor.set('privateKey', privateKey) + actor.save().catch(err => logger.error('Cannot set public/private keys of actor %d.', actor.uuid, err)) return { account, videoChannel } } @@ -37,8 +39,7 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { const url = getAccountActivityPubUrl(name) - const accountInstance = new AccountModel({ - name, + const actorInstance = new ActorModel({ url, publicKey: null, privateKey: null, @@ -48,13 +49,22 @@ async function createLocalAccountWithoutKeys (name: string, userId: number, appl outboxUrl: url + '/outbox', sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox', followersUrl: url + '/followers', - followingUrl: url + '/following', + followingUrl: url + '/following' + }) + const actorInstanceCreated = await actorInstance.save({ transaction: t }) + + const accountInstance = new AccountModel({ + name, userId, applicationId, + actorId: actorInstanceCreated.id, serverId: null // It is our server }) - return accountInstance.save({ transaction: t }) + const accountInstanceCreated = await accountInstance.save({ transaction: t }) + accountInstanceCreated.Actor = actorInstanceCreated + + return accountInstanceCreated } // --------------------------------------------------------------------------- -- cgit v1.2.3