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

59 lines
1.9 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { Transaction } from 'sequelize'
import { ActivityAnnounce, ActivityAudience } from '@shared/models'
2018-07-30 10:02:40 -05:00
import { logger } from '../../../helpers/logger'
2020-06-18 03:45:25 -05:00
import { MActorLight, MVideo } from '../../../types/models'
import { MVideoShare } from '../../../types/models/video'
import { audiencify, getAudience } from '../audience'
import { getActorsInvolvedInVideo, getAudienceFromFollowersOf } from './shared'
import { broadcastToFollowers } from './shared/send-utils'
async function buildAnnounceWithVideoAudience (
2019-08-15 04:53:26 -05:00
byActor: MActorLight,
videoShare: MVideoShare,
video: MVideo,
t: Transaction
) {
2018-01-26 05:02:18 -06:00
const announcedObject = video.url
2017-11-20 02:43:39 -06:00
2018-09-11 09:27:07 -05:00
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
2018-09-14 09:51:35 -05:00
const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
2018-09-11 09:27:07 -05:00
const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
return { activity, actorsInvolvedInVideo }
}
2022-03-23 10:14:33 -05:00
async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, transaction: Transaction) {
const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction)
2018-07-30 10:02:40 -05:00
logger.info('Creating job to send announce %s.', videoShare.url)
2022-03-23 10:14:33 -05:00
return broadcastToFollowers({
data: activity,
byActor,
toFollowersOf: actorsInvolvedInVideo,
transaction,
actorsException: [ byActor ],
contextType: 'Announce'
})
2017-11-20 02:43:39 -06:00
}
2019-08-15 04:53:26 -05:00
function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
if (!audience) audience = getAudience(byActor)
2018-09-11 09:27:07 -05:00
return audiencify({
type: 'Announce' as 'Announce',
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
2018-09-11 09:27:07 -05:00
}, audience)
2017-11-20 02:43:39 -06:00
}
2017-11-21 11:23:10 -06:00
// ---------------------------------------------------------------------------
export {
sendVideoAnnounce,
2018-09-11 09:27:07 -05:00
buildAnnounceActivity,
buildAnnounceWithVideoAudience
2017-11-21 11:23:10 -06:00
}