aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/user.ts22
-rw-r--r--server/lib/video-channel.ts4
2 files changed, 15 insertions, 11 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 9884e566f..2d7b36b4f 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -5,16 +5,17 @@ import { database as db } from '../initializers'
5import { CONFIG } from '../initializers/constants' 5import { CONFIG } from '../initializers/constants'
6import { UserInstance } from '../models' 6import { UserInstance } from '../models'
7import { createVideoChannel } from './video-channel' 7import { createVideoChannel } from './video-channel'
8import { logger } from '../helpers/logger'
8 9
9async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { 10async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
10 const res = await db.sequelize.transaction(async t => { 11 const { account, videoChannel } = await db.sequelize.transaction(async t => {
11 const userOptions = { 12 const userOptions = {
12 transaction: t, 13 transaction: t,
13 validate: validateUser 14 validate: validateUser
14 } 15 }
15 16
16 const userCreated = await user.save(userOptions) 17 const userCreated = await user.save(userOptions)
17 const accountCreated = await createLocalAccount(user.username, user.id, null, t) 18 const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t)
18 19
19 const videoChannelName = `Default ${userCreated.username} channel` 20 const videoChannelName = `Default ${userCreated.username} channel`
20 const videoChannelInfo = { 21 const videoChannelInfo = {
@@ -25,18 +26,23 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t
25 return { account: accountCreated, videoChannel } 26 return { account: accountCreated, videoChannel }
26 }) 27 })
27 28
28 return res 29 // Set account keys, this could be long so process after the account creation and do not block the client
30 const { publicKey, privateKey } = await createPrivateAndPublicKeys()
31 account.set('publicKey', publicKey)
32 account.set('privateKey', privateKey)
33 account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err))
34
35 return { account, videoChannel }
29} 36}
30 37
31async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { 38async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) {
32 const { publicKey, privateKey } = await createPrivateAndPublicKeys()
33 const url = getActivityPubUrl('account', name) 39 const url = getActivityPubUrl('account', name)
34 40
35 const accountInstance = db.Account.build({ 41 const accountInstance = db.Account.build({
36 name, 42 name,
37 url, 43 url,
38 publicKey, 44 publicKey: null,
39 privateKey, 45 privateKey: null,
40 followersCount: 0, 46 followersCount: 0,
41 followingCount: 0, 47 followingCount: 0,
42 inboxUrl: url + '/inbox', 48 inboxUrl: url + '/inbox',
@@ -56,5 +62,5 @@ async function createLocalAccount (name: string, userId: number, applicationId:
56 62
57export { 63export {
58 createUserAccountAndChannel, 64 createUserAccountAndChannel,
59 createLocalAccount 65 createLocalAccountWithoutKeys
60} 66}
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index e69ec062f..6f9ae2d95 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -25,9 +25,7 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account
25 // Do not forget to add Account information to the created video channel 25 // Do not forget to add Account information to the created video channel
26 videoChannelCreated.Account = account 26 videoChannelCreated.Account = account
27 27
28 await sendCreateVideoChannel(videoChannelCreated, t) 28 // No need to seed this empty video channel to followers
29 await shareVideoChannelByServer(videoChannelCreated, t)
30
31 return videoChannelCreated 29 return videoChannelCreated
32} 30}
33 31