- return user.save(userOptions)
- .then(user => {
- const author = db.Author.build({
- name: user.username,
- podId: null, // It is our pod
- userId: user.id
- })
-
- return author.save({ transaction: t })
- .then(author => ({ author, user }))
- })
- .then(({ author, user }) => {
- const remoteVideoAuthor = author.toAddRemoteJSON()
-
- // Now we'll add the video channel's meta data to our friends
- return addVideoAuthorToFriends(remoteVideoAuthor, t)
- .then(() => ({ author, user }))
- })
- .then(({ author, user }) => {
- const videoChannelInfo = {
- name: `Default ${user.username} channel`
- }
-
- return createVideoChannel(videoChannelInfo, author, t)
- .then(videoChannel => ({ author, user, videoChannel }))
- })
+ const userCreated: MUserDefault = await userToCreate.save(userOptions)
+ userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t)
+
+ const accountCreated = await createLocalAccountWithoutKeys({
+ name: userCreated.username,
+ displayName: userDisplayName,
+ userId: userCreated.id,
+ applicationId: null,
+ t: t
+ })
+ userCreated.Account = accountCreated
+
+ const channelAttributes = await buildChannelAttributes(userCreated, channelNames)
+ const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t)
+
+ const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t)
+
+ return { user: userCreated, account: accountCreated, videoChannel, videoPlaylist }
+ })
+
+ const [ accountActorWithKeys, channelActorWithKeys ] = await Promise.all([
+ generateAndSaveActorKeys(account.Actor),
+ generateAndSaveActorKeys(videoChannel.Actor)
+ ])
+
+ account.Actor = accountActorWithKeys
+ videoChannel.Actor = channelActorWithKeys
+
+ return { user, account, videoChannel }
+}
+
+async function createLocalAccountWithoutKeys (parameters: {
+ name: string
+ displayName?: string
+ userId: number | null
+ applicationId: number | null
+ t: Transaction | undefined
+ type?: ActivityPubActorType
+}) {
+ const { name, displayName, userId, applicationId, t, type = 'Person' } = parameters
+ const url = getLocalAccountActivityPubUrl(name)
+
+ const actorInstance = buildActorInstance(type, url, name)
+ const actorInstanceCreated: MActorDefault = await actorInstance.save({ transaction: t })
+
+ const accountInstance = new AccountModel({
+ name: displayName || name,
+ userId,
+ applicationId,
+ actorId: actorInstanceCreated.id
+ })
+
+ const accountInstanceCreated: MAccountDefault = await accountInstance.save({ transaction: t })
+ accountInstanceCreated.Actor = actorInstanceCreated
+
+ return accountInstanceCreated
+}
+
+async function createApplicationActor (applicationId: number) {
+ const accountCreated = await createLocalAccountWithoutKeys({
+ name: SERVER_ACTOR_NAME,
+ userId: null,
+ applicationId: applicationId,
+ t: undefined,
+ type: 'Application'
+ })
+
+ accountCreated.Actor = await generateAndSaveActorKeys(accountCreated.Actor)
+
+ return accountCreated
+}
+
+async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) {
+ const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id)
+ let url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString
+
+ if (isPendingEmail) url += '&isPendingEmail=true'
+
+ const email = isPendingEmail ? user.pendingEmail : user.email
+ const username = user.username
+
+ await Emailer.Instance.addVerifyEmailJob(username, email, url)
+}
+
+async function getOriginalVideoFileTotalFromUser (user: MUserId) {
+ // Don't use sequelize because we need to use a sub query
+ const query = UserModel.generateUserQuotaBaseSQL({
+ withSelect: true,
+ whereUserId: '$userId'
+ })
+
+ const base = await UserModel.getTotalRawQuery(query, user.id)
+
+ return base + LiveManager.Instance.getLiveQuotaUsedByUser(user.id)
+}
+
+// Returns cumulative size of all video files uploaded in the last 24 hours.
+async function getOriginalVideoFileTotalDailyFromUser (user: MUserId) {
+ // Don't use sequelize because we need to use a sub query
+ const query = UserModel.generateUserQuotaBaseSQL({
+ withSelect: true,
+ whereUserId: '$userId',
+ where: '"video"."createdAt" > now() - interval \'24 hours\''