diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-20 19:05:31 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-20 19:23:10 +0200 |
commit | 1ca9f7c3f7afac2af4c4c25b98426731f7e789c6 (patch) | |
tree | 27fe65c4ea5e9250d2523033d5c65b315bfca23d /server/lib/user.ts | |
parent | 0283eaac2a8e73006c66df3cf5bb9012e37450e5 (diff) | |
download | PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.gz PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.zst PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.zip |
Type toFormattedJSON
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index 266974cac..d84aff464 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -2,9 +2,8 @@ import * as uuidv4 from 'uuid/v4' | |||
2 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 2 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
3 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' | 3 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' |
4 | import { AccountModel } from '../models/account/account' | 4 | import { AccountModel } from '../models/account/account' |
5 | import { UserModel } from '../models/account/user' | ||
6 | import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' | 5 | import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' |
7 | import { createVideoChannel } from './video-channel' | 6 | import { createLocalVideoChannel } from './video-channel' |
8 | import { ActorModel } from '../models/activitypub/actor' | 7 | import { ActorModel } from '../models/activitypub/actor' |
9 | import { UserNotificationSettingModel } from '../models/account/user-notification-setting' | 8 | import { UserNotificationSettingModel } from '../models/account/user-notification-setting' |
10 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' | 9 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' |
@@ -13,17 +12,17 @@ import { sequelizeTypescript } from '../initializers/database' | |||
13 | import { Transaction } from 'sequelize/types' | 12 | import { Transaction } from 'sequelize/types' |
14 | import { Redis } from './redis' | 13 | import { Redis } from './redis' |
15 | import { Emailer } from './emailer' | 14 | import { Emailer } from './emailer' |
16 | import { MAccountActor, MActor, MChannelActor } from '../typings/models' | 15 | import { MAccountDefault, MActorDefault, MChannelActor } from '../typings/models' |
17 | import { MUser, MUserId, MUserNotifSettingAccount } from '../typings/models/user' | 16 | import { MUser, MUserDefault, MUserId } from '../typings/models/user' |
18 | 17 | ||
19 | type ChannelNames = { name: string, displayName: string } | 18 | type ChannelNames = { name: string, displayName: string } |
20 | 19 | ||
21 | async function createUserAccountAndChannelAndPlaylist (parameters: { | 20 | async function createUserAccountAndChannelAndPlaylist (parameters: { |
22 | userToCreate: UserModel, | 21 | userToCreate: MUser, |
23 | userDisplayName?: string, | 22 | userDisplayName?: string, |
24 | channelNames?: ChannelNames, | 23 | channelNames?: ChannelNames, |
25 | validateUser?: boolean | 24 | validateUser?: boolean |
26 | }): Promise<{ user: MUserNotifSettingAccount, account: MAccountActor, videoChannel: MChannelActor }> { | 25 | }): Promise<{ user: MUserDefault, account: MAccountDefault, videoChannel: MChannelActor }> { |
27 | const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters | 26 | const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters |
28 | 27 | ||
29 | const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { | 28 | const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { |
@@ -32,7 +31,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: { | |||
32 | validate: validateUser | 31 | validate: validateUser |
33 | } | 32 | } |
34 | 33 | ||
35 | const userCreated: MUserNotifSettingAccount = await userToCreate.save(userOptions) | 34 | const userCreated: MUserDefault = await userToCreate.save(userOptions) |
36 | userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t) | 35 | userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t) |
37 | 36 | ||
38 | const accountCreated = await createLocalAccountWithoutKeys({ | 37 | const accountCreated = await createLocalAccountWithoutKeys({ |
@@ -45,7 +44,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: { | |||
45 | userCreated.Account = accountCreated | 44 | userCreated.Account = accountCreated |
46 | 45 | ||
47 | const channelAttributes = await buildChannelAttributes(userCreated, channelNames) | 46 | const channelAttributes = await buildChannelAttributes(userCreated, channelNames) |
48 | const videoChannel = await createVideoChannel(channelAttributes, accountCreated, t) | 47 | const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t) |
49 | 48 | ||
50 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) | 49 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) |
51 | 50 | ||
@@ -75,7 +74,7 @@ async function createLocalAccountWithoutKeys (parameters: { | |||
75 | const url = getAccountActivityPubUrl(name) | 74 | const url = getAccountActivityPubUrl(name) |
76 | 75 | ||
77 | const actorInstance = buildActorInstance(type, url, name) | 76 | const actorInstance = buildActorInstance(type, url, name) |
78 | const actorInstanceCreated: MActor = await actorInstance.save({ transaction: t }) | 77 | const actorInstanceCreated: MActorDefault = await actorInstance.save({ transaction: t }) |
79 | 78 | ||
80 | const accountInstance = new AccountModel({ | 79 | const accountInstance = new AccountModel({ |
81 | name: displayName || name, | 80 | name: displayName || name, |
@@ -84,7 +83,7 @@ async function createLocalAccountWithoutKeys (parameters: { | |||
84 | actorId: actorInstanceCreated.id | 83 | actorId: actorInstanceCreated.id |
85 | }) | 84 | }) |
86 | 85 | ||
87 | const accountInstanceCreated: MAccountActor = await accountInstance.save({ transaction: t }) | 86 | const accountInstanceCreated: MAccountDefault = await accountInstance.save({ transaction: t }) |
88 | accountInstanceCreated.Actor = actorInstanceCreated | 87 | accountInstanceCreated.Actor = actorInstanceCreated |
89 | 88 | ||
90 | return accountInstanceCreated | 89 | return accountInstanceCreated |