import { Transaction } from 'sequelize'
-import { ActivityUpdate } from '../../../../shared/models/activitypub'
-import { AccountModel } from '../../../models/account/account'
+import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
+import { VideoPrivacy } from '../../../../shared/models/videos'
+import { UserModel } from '../../../models/account/user'
+import { ActorModel } from '../../../models/activitypub/actor'
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'
-import { broadcastToFollowers, getAudience } from './misc'
+import { audiencify, broadcastToFollowers, getAudience } from './misc'
-async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
- const byAccount = videoChannel.Account
+async function sendUpdateVideo (video: VideoModel, t: Transaction) {
+ const byActor = video.VideoChannel.Account.Actor
- const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
- const videoChannelObject = videoChannel.toActivityPubObject()
- const data = await updateActivityData(url, byAccount, videoChannelObject, t)
+ const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
+ const videoObject = video.toActivityPubObject()
+ const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
- const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
- accountsInvolved.push(byAccount)
+ const data = await updateActivityData(url, byActor, videoObject, t, audience)
- return broadcastToFollowers(data, byAccount, accountsInvolved, t)
+ const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
+ actorsInvolved.push(byActor)
+
+ return broadcastToFollowers(data, byActor, actorsInvolved, t)
}
-async function sendUpdateVideo (video: VideoModel, t: Transaction) {
- const byAccount = video.VideoChannel.Account
+async function sendUpdateUser (user: UserModel, t: Transaction) {
+ const byActor = user.Account.Actor
- const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
- const videoObject = video.toActivityPubObject()
- const data = await updateActivityData(url, byAccount, videoObject, t)
+ const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
+ const accountObject = user.Account.toActivityPubObject()
+ const audience = await getAudience(byActor, t)
+ const data = await updateActivityData(url, byActor, accountObject, t, audience)
- const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t)
- accountsInvolved.push(byAccount)
+ const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
+ actorsInvolved.push(byActor)
- return broadcastToFollowers(data, byAccount, accountsInvolved, t)
+ return broadcastToFollowers(data, byActor, actorsInvolved, t)
}
// ---------------------------------------------------------------------------
export {
- sendUpdateVideoChannel,
+ sendUpdateUser,
sendUpdateVideo
}
// ---------------------------------------------------------------------------
-async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise<ActivityUpdate> {
- const { to, cc } = await getAudience(byAccount, t)
- return {
+async function updateActivityData (
+ url: string,
+ byActor: ActorModel,
+ object: any,
+ t: Transaction,
+ audience?: ActivityAudience
+): Promise<ActivityUpdate> {
+ if (!audience) {
+ audience = await getAudience(byActor, t)
+ }
+
+ return audiencify({
type: 'Update',
id: url,
- actor: byAccount.url,
- to,
- cc,
- object
- }
+ actor: byActor.url,
+ object: audiencify(object, audience)
+ }, audience)
}