video-channel.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import * as Sequelize from 'sequelize'
  2. import * as uuidv4 from 'uuid/v4'
  3. import { VideoChannelCreate } from '../../shared/models'
  4. import { AccountModel } from '../models/account/account'
  5. import { VideoChannelModel } from '../models/video/video-channel'
  6. import { buildActorInstance, getVideoChannelActivityPubUrl } from './activitypub'
  7. async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
  8. const uuid = uuidv4()
  9. const url = getVideoChannelActivityPubUrl(videoChannelInfo.name)
  10. const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
  11. const actorInstanceCreated = await actorInstance.save({ transaction: t })
  12. const videoChannelData = {
  13. name: videoChannelInfo.displayName,
  14. description: videoChannelInfo.description,
  15. support: videoChannelInfo.support,
  16. accountId: account.id,
  17. actorId: actorInstanceCreated.id
  18. }
  19. const videoChannel = VideoChannelModel.build(videoChannelData)
  20. const options = { transaction: t }
  21. const videoChannelCreated = await videoChannel.save(options)
  22. // Do not forget to add Account/Actor information to the created video channel
  23. videoChannelCreated.Account = account
  24. videoChannelCreated.Actor = actorInstanceCreated
  25. // No need to seed this empty video channel to followers
  26. return videoChannelCreated
  27. }
  28. // ---------------------------------------------------------------------------
  29. export {
  30. createVideoChannel
  31. }