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

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { Transaction } from 'sequelize'
2018-01-26 05:02:18 -06:00
import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
2017-12-14 10:38:41 -06:00
import { ActorModel } from '../../../models/activitypub/actor'
2017-12-12 10:53:50 -06:00
import { VideoModel } from '../../../models/video/video'
import { VideoShareModel } from '../../../models/video/video-share'
import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc'
2017-11-20 02:43:39 -06:00
async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
2018-01-26 05:02:18 -06:00
const announcedObject = video.url
2017-11-20 02:43:39 -06:00
2017-12-14 10:38:41 -06:00
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
const audience = getObjectFollowersAudience(accountsToForwardView)
return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
}
async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t)
2017-12-14 10:38:41 -06:00
return broadcastToFollowers(data, byActor, [ byActor ], t)
2017-11-20 02:43:39 -06:00
}
async function announceActivityData (
url: string,
2017-12-14 10:38:41 -06:00
byActor: ActorModel,
2018-01-26 05:02:18 -06:00
object: string,
t: Transaction,
audience?: ActivityAudience
2017-12-12 10:53:50 -06:00
): Promise<ActivityAnnounce> {
if (!audience) {
2017-12-14 10:38:41 -06:00
audience = await getAudience(byActor, t)
}
2017-12-12 10:53:50 -06:00
return {
2017-11-20 02:43:39 -06:00
type: 'Announce',
to: audience.to,
cc: audience.cc,
2017-11-20 02:43:39 -06:00
id: url,
2017-12-14 10:38:41 -06:00
actor: byActor.url,
2017-11-20 02:43:39 -06:00
object
}
}
2017-11-21 11:23:10 -06:00
// ---------------------------------------------------------------------------
export {
sendVideoAnnounceToFollowers,
announceActivityData,
2017-12-14 10:38:41 -06:00
buildVideoAnnounceToFollowers
2017-11-21 11:23:10 -06:00
}