1
0
Fork 0
peertube/server/lib/activitypub/send/send-announce.ts

53 lines
1.9 KiB
TypeScript
Raw Normal View History

2017-11-20 03:43:39 -05:00
import { Transaction } from 'sequelize'
2018-01-26 06:02:18 -05:00
import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
2017-12-12 11:53:50 -05:00
import { VideoModel } from '../../../models/video/video'
2018-05-25 05:32:36 -04:00
import { broadcastToFollowers } from './utils'
2018-09-14 10:51:35 -04:00
import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
2018-07-30 11:02:40 -04:00
import { logger } from '../../../helpers/logger'
import { ActorModelOnly } from '../../../typings/models'
import { VideoShareModelOnly } from '../../../typings/models/video-share'
async function buildAnnounceWithVideoAudience (
byActor: ActorModelOnly,
videoShare: VideoShareModelOnly,
video: VideoModel,
t: Transaction
) {
2018-01-26 06:02:18 -05:00
const announcedObject = video.url
2017-11-20 03:43:39 -05:00
2018-09-11 10:27:07 -04:00
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
2018-09-14 10:51:35 -04:00
const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
2018-09-11 10:27:07 -04:00
const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
return { activity, actorsInvolvedInVideo }
}
async function sendVideoAnnounce (byActor: ActorModelOnly, videoShare: VideoShareModelOnly, video: VideoModel, t: Transaction) {
2018-09-11 10:27:07 -04:00
const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
2018-07-30 11:02:40 -04:00
logger.info('Creating job to send announce %s.', videoShare.url)
2018-09-04 04:22:10 -04:00
const followersException = [ byActor ]
2018-09-11 10:27:07 -04:00
return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException)
2017-11-20 03:43:39 -05:00
}
function buildAnnounceActivity (url: string, byActor: ActorModelOnly, object: string, audience?: ActivityAudience): ActivityAnnounce {
if (!audience) audience = getAudience(byActor)
2018-09-11 10:27:07 -04:00
return audiencify({
type: 'Announce' as 'Announce',
2017-11-20 03:43:39 -05:00
id: url,
2017-12-14 11:38:41 -05:00
actor: byActor.url,
2017-11-20 03:43:39 -05:00
object
2018-09-11 10:27:07 -04:00
}, audience)
2017-11-20 03:43:39 -05:00
}
2017-11-21 12:23:10 -05:00
// ---------------------------------------------------------------------------
export {
sendVideoAnnounce,
2018-09-11 10:27:07 -04:00
buildAnnounceActivity,
buildAnnounceWithVideoAudience
2017-11-21 12:23:10 -05:00
}