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'
|
2018-01-26 08:49:57 -06:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { broadcastToFollowers } from './utils'
|
2018-09-14 09:51:35 -05:00
|
|
|
import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
|
2018-07-30 10:02:40 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
async function buildAnnounceWithVideoAudience (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
|
|
|
|
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 }
|
2017-11-27 07:44:51 -06:00
|
|
|
}
|
|
|
|
|
2018-03-27 06:33:56 -05:00
|
|
|
async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
2018-09-11 09:27:07 -05:00
|
|
|
const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
|
2017-11-27 07:44:51 -06:00
|
|
|
|
2018-07-30 10:02:40 -05:00
|
|
|
logger.info('Creating job to send announce %s.', videoShare.url)
|
|
|
|
|
2018-09-04 03:22:10 -05:00
|
|
|
const followersException = [ byActor ]
|
2018-09-11 09:27:07 -05:00
|
|
|
return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException)
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
function buildAnnounceActivity (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
|
2018-06-12 13:04:58 -05:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
2017-11-27 07:44:51 -06:00
|
|
|
|
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 {
|
2018-03-27 06:33:56 -05:00
|
|
|
sendVideoAnnounce,
|
2018-09-11 09:27:07 -05:00
|
|
|
buildAnnounceActivity,
|
|
|
|
buildAnnounceWithVideoAudience
|
2017-11-21 11:23:10 -06:00
|
|
|
}
|