From e590b4a512617bbf63595b684386f68abea7d8b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 May 2019 10:46:32 +0200 Subject: Add ability to specify channel on registration --- server/lib/user.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'server/lib') diff --git a/server/lib/user.ts b/server/lib/user.ts index 7badb3e72..d9fd89e15 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -13,7 +13,8 @@ import { UserNotificationSetting, UserNotificationSettingValue } from '../../sha import { createWatchLaterPlaylist } from './video-playlist' import { sequelizeTypescript } from '../initializers/database' -async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, validateUser = true) { +type ChannelNames = { name: string, displayName: string } +async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, channelNames?: ChannelNames, validateUser = true) { const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { const userOptions = { transaction: t, @@ -26,18 +27,8 @@ async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, const accountCreated = await createLocalAccountWithoutKeys(userCreated.username, userCreated.id, null, t) userCreated.Account = accountCreated - let channelName = userCreated.username + '_channel' - - // Conflict, generate uuid instead - const actor = await ActorModel.loadLocalByName(channelName) - if (actor) channelName = uuidv4() - - const videoChannelDisplayName = `Main ${userCreated.username} channel` - const videoChannelInfo = { - name: channelName, - displayName: videoChannelDisplayName - } - const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) + const channelAttributes = await buildChannelAttributes(userCreated, channelNames) + const videoChannel = await createVideoChannel(channelAttributes, accountCreated, t) const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) @@ -116,3 +107,20 @@ function createDefaultUserNotificationSettings (user: UserModel, t: Sequelize.Tr return UserNotificationSettingModel.create(values, { transaction: t }) } + +async function buildChannelAttributes (user: UserModel, channelNames?: ChannelNames) { + if (channelNames) return channelNames + + let channelName = user.username + '_channel' + + // Conflict, generate uuid instead + const actor = await ActorModel.loadLocalByName(channelName) + if (actor) channelName = uuidv4() + + const videoChannelDisplayName = `Main ${user.username} channel` + + return { + name: channelName, + displayName: videoChannelDisplayName + } +} -- cgit v1.2.3