1 import { Transaction } from 'sequelize'
2 import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
3 import { database as db } from '../../../initializers'
4 import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
5 import { getUpdateActivityPubUrl } from '../url'
6 import { broadcastToFollowers, getAudience } from './misc'
8 async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
9 const byAccount = videoChannel.Account
11 const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
12 const videoChannelObject = videoChannel.toActivityPubObject()
13 const data = await updateActivityData(url, byAccount, videoChannelObject, t)
15 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
16 accountsInvolved.push(byAccount)
18 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
21 async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
22 const byAccount = video.VideoChannel.Account
24 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
25 const videoObject = video.toActivityPubObject()
26 const data = await updateActivityData(url, byAccount, videoObject, t)
28 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t)
29 accountsInvolved.push(byAccount)
31 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
34 // ---------------------------------------------------------------------------
37 sendUpdateVideoChannel,
41 // ---------------------------------------------------------------------------
43 async function updateActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction) {
44 const { to, cc } = await getAudience(byAccount, t)
45 const activity: ActivityUpdate = {