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