aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/actor.ts4
-rw-r--r--server/lib/user.ts19
-rw-r--r--server/lib/video-channel.ts10
3 files changed, 16 insertions, 17 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 5201bdeef..13b73077e 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -38,7 +38,7 @@ import {
38} from '../../typings/models' 38} from '../../typings/models'
39 39
40// Set account keys, this could be long so process after the account creation and do not block the client 40// Set account keys, this could be long so process after the account creation and do not block the client
41function setAsyncActorKeys (actor: MActor) { 41function setAsyncActorKeys <T extends MActor> (actor: T) {
42 return createPrivateAndPublicKeys() 42 return createPrivateAndPublicKeys()
43 .then(({ publicKey, privateKey }) => { 43 .then(({ publicKey, privateKey }) => {
44 actor.publicKey = publicKey 44 actor.publicKey = publicKey
@@ -148,7 +148,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU
148 sharedInboxUrl: WEBSERVER.URL + '/inbox', 148 sharedInboxUrl: WEBSERVER.URL + '/inbox',
149 followersUrl: url + '/followers', 149 followersUrl: url + '/followers',
150 followingUrl: url + '/following' 150 followingUrl: url + '/following'
151 }) 151 }) as MActor
152} 152}
153 153
154async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) { 154async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) {
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'
2import { ActivityPubActorType } from '../../shared/models/activitypub' 2import { ActivityPubActorType } from '../../shared/models/activitypub'
3import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' 3import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants'
4import { AccountModel } from '../models/account/account' 4import { AccountModel } from '../models/account/account'
5import { UserModel } from '../models/account/user'
6import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' 5import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
7import { createVideoChannel } from './video-channel' 6import { createLocalVideoChannel } from './video-channel'
8import { ActorModel } from '../models/activitypub/actor' 7import { ActorModel } from '../models/activitypub/actor'
9import { UserNotificationSettingModel } from '../models/account/user-notification-setting' 8import { UserNotificationSettingModel } from '../models/account/user-notification-setting'
10import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' 9import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users'
@@ -13,17 +12,17 @@ import { sequelizeTypescript } from '../initializers/database'
13import { Transaction } from 'sequelize/types' 12import { Transaction } from 'sequelize/types'
14import { Redis } from './redis' 13import { Redis } from './redis'
15import { Emailer } from './emailer' 14import { Emailer } from './emailer'
16import { MAccountActor, MActor, MChannelActor } from '../typings/models' 15import { MAccountDefault, MActorDefault, MChannelActor } from '../typings/models'
17import { MUser, MUserId, MUserNotifSettingAccount } from '../typings/models/user' 16import { MUser, MUserDefault, MUserId } from '../typings/models/user'
18 17
19type ChannelNames = { name: string, displayName: string } 18type ChannelNames = { name: string, displayName: string }
20 19
21async function createUserAccountAndChannelAndPlaylist (parameters: { 20async 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
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index ee8eb6568..41eab456b 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -4,12 +4,12 @@ import { VideoChannelCreate } from '../../shared/models'
4import { VideoChannelModel } from '../models/video/video-channel' 4import { VideoChannelModel } from '../models/video/video-channel'
5import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub' 5import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
7import { MAccountId, MChannelActor, MChannelId } from '../typings/models' 7import { MAccountId, MChannelDefault, MChannelId } from '../typings/models'
8 8
9type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelActor & 9type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault &
10 { Account?: T } 10 { Account?: T }
11 11
12async function createVideoChannel <T extends MAccountId> ( 12async function createLocalVideoChannel <T extends MAccountId> (
13 videoChannelInfo: VideoChannelCreate, 13 videoChannelInfo: VideoChannelCreate,
14 account: T, 14 account: T,
15 t: Sequelize.Transaction 15 t: Sequelize.Transaction
@@ -31,7 +31,7 @@ async function createVideoChannel <T extends MAccountId> (
31 const videoChannel = new VideoChannelModel(videoChannelData) 31 const videoChannel = new VideoChannelModel(videoChannelData)
32 32
33 const options = { transaction: t } 33 const options = { transaction: t }
34 const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelActor 34 const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelDefault
35 35
36 // Do not forget to add Account/Actor information to the created video channel 36 // Do not forget to add Account/Actor information to the created video channel
37 videoChannelCreated.Account = account 37 videoChannelCreated.Account = account
@@ -54,6 +54,6 @@ async function federateAllVideosOfChannel (videoChannel: MChannelId) {
54// --------------------------------------------------------------------------- 54// ---------------------------------------------------------------------------
55 55
56export { 56export {
57 createVideoChannel, 57 createLocalVideoChannel,
58 federateAllVideosOfChannel 58 federateAllVideosOfChannel
59} 59}