From 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 17:27:49 +0100 Subject: Make it compile at least --- server/lib/user.ts | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'server/lib/user.ts') diff --git a/server/lib/user.ts b/server/lib/user.ts index 57c653e55..1094c2401 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -1,6 +1,9 @@ +import * as Sequelize from 'sequelize' +import { getActivityPubUrl } from '../helpers/activitypub' +import { createPrivateAndPublicKeys } from '../helpers/peertube-crypto' import { database as db } from '../initializers' +import { CONFIG } from '../initializers/constants' import { UserInstance } from '../models' -import { addVideoAccountToFriends } from './friends' import { createVideoChannel } from './video-channel' async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { @@ -11,32 +14,46 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t } const userCreated = await user.save(userOptions) - const accountInstance = db.Account.build({ - name: userCreated.username, - podId: null, // It is our pod - userId: userCreated.id - }) - - const accountCreated = await accountInstance.save({ transaction: t }) - - const remoteVideoAccount = accountCreated.toAddRemoteJSON() - - // Now we'll add the video channel's meta data to our friends - const account = await addVideoAccountToFriends(remoteVideoAccount, t) + const accountCreated = await createLocalAccount(user.username, user.id, null, t) const videoChannelInfo = { name: `Default ${userCreated.username} channel` } const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) - return { account, videoChannel } + return { account: accountCreated, videoChannel } }) return res } +async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { + const { publicKey, privateKey } = await createPrivateAndPublicKeys() + const url = getActivityPubUrl('account', name) + + const accountInstance = db.Account.build({ + name, + url, + publicKey, + privateKey, + followersCount: 0, + followingCount: 0, + inboxUrl: url + '/inbox', + outboxUrl: url + '/outbox', + sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox', + followersUrl: url + '/followers', + followingUrl: url + '/following', + userId, + applicationId, + podId: null // It is our pod + }) + + return accountInstance.save({ transaction: t }) +} + // --------------------------------------------------------------------------- export { - createUserAccountAndChannel + createUserAccountAndChannel, + createLocalAccount } -- cgit v1.2.3