PeerTube/server/lib/activitypub/send/send-update.ts

57 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-11-20 08:43:39 +00:00
import { Transaction } from 'sequelize'
2017-12-12 16:53:50 +00:00
import { ActivityUpdate } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { VideoModel } from '../../../models/video/video'
import { VideoChannelModel } from '../../../models/video/video-channel'
import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
import { VideoShareModel } from '../../../models/video/video-share'
import { getUpdateActivityPubUrl } from '../url'
2017-11-20 08:43:39 +00:00
import { broadcastToFollowers, getAudience } from './misc'
2017-12-12 16:53:50 +00:00
async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
2017-11-20 08:43:39 +00:00
const byAccount = videoChannel.Account
const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
const videoChannelObject = videoChannel.toActivityPubObject()
const data = await updateActivityData(url, byAccount, videoChannelObject, t)
2017-11-20 08:43:39 +00:00
2017-12-12 16:53:50 +00:00
const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
2017-11-20 08:43:39 +00:00
accountsInvolved.push(byAccount)
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
}
2017-12-12 16:53:50 +00:00
async function sendUpdateVideo (video: VideoModel, t: Transaction) {
2017-11-20 08:43:39 +00:00
const byAccount = video.VideoChannel.Account
const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
const videoObject = video.toActivityPubObject()
const data = await updateActivityData(url, byAccount, videoObject, t)
2017-11-20 08:43:39 +00:00
2017-12-12 16:53:50 +00:00
const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t)
2017-11-20 08:43:39 +00:00
accountsInvolved.push(byAccount)
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
}
// ---------------------------------------------------------------------------
export {
sendUpdateVideoChannel,
sendUpdateVideo
}
// ---------------------------------------------------------------------------
2017-12-12 16:53:50 +00:00
async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise<ActivityUpdate> {
const { to, cc } = await getAudience(byAccount, t)
2017-12-12 16:53:50 +00:00
return {
2017-11-20 08:43:39 +00:00
type: 'Update',
id: url,
actor: byAccount.url,
to,
cc,
object
}
}