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

52 lines
1.8 KiB
TypeScript
Raw Normal View History

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