]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-channel.ts
Misc cleanup
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
index 2241799737b8c80d97be7d44e4a0f2df4e9c8b07..beb01da9b7d7847789bb632935851acc445e6835 100644 (file)
@@ -1,38 +1,29 @@
 import * as Sequelize from 'sequelize'
-
-import { addVideoChannelToFriends } from './friends'
-import { database as db } from '../initializers'
-import { AuthorInstance } from '../models'
 import { VideoChannelCreate } from '../../shared/models'
+import { database as db } from '../initializers'
+import { AccountInstance } from '../models'
+import { getVideoChannelActivityPubUrl } from './activitypub/url'
 
-function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) {
-  let videoChannelUUID = ''
-
+async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
   const videoChannelData = {
     name: videoChannelInfo.name,
     description: videoChannelInfo.description,
     remote: false,
-    authorId: author.id
+    accountId: account.id
   }
 
   const videoChannel = db.VideoChannel.build(videoChannelData)
+  videoChannel.set('url', getVideoChannelActivityPubUrl(videoChannel))
+
   const options = { transaction: t }
 
-  return videoChannel.save(options)
-    .then(videoChannelCreated => {
-      // Do not forget to add Author information to the created video channel
-      videoChannelCreated.Author = author
-      videoChannelUUID = videoChannelCreated.uuid
-
-      return videoChannelCreated
-    })
-    .then(videoChannel => {
-      const remoteVideoChannel = videoChannel.toAddRemoteJSON()
-
-      // Now we'll add the video channel's meta data to our friends
-      return addVideoChannelToFriends(remoteVideoChannel, t)
-    })
-    .then(() => videoChannelUUID) // Return video channel UUID
+  const videoChannelCreated = await videoChannel.save(options)
+
+  // Do not forget to add Account information to the created video channel
+  videoChannelCreated.Account = account
+
+  // No need to seed this empty video channel to followers
+  return videoChannelCreated
 }
 
 // ---------------------------------------------------------------------------