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-14 11:38:41 -05:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2018-01-26 09:49:57 -05:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2018-05-25 05:32:36 -04:00
|
|
|
import { broadcastToFollowers } from './utils'
|
|
|
|
import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
|
2018-07-30 11:02:40 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
2018-01-26 06:02:18 -05:00
|
|
|
const announcedObject = video.url
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
|
2017-11-27 08:44:51 -05:00
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
2018-06-12 14:04:58 -04:00
|
|
|
return announceActivityData(videoShare.url, byActor, announcedObject, audience)
|
2017-11-27 08:44:51 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
|
|
|
const data = await buildVideoAnnounce(byActor, videoShare, video, t)
|
2017-11-27 08:44:51 -05:00
|
|
|
|
2018-07-30 11:02:40 -04:00
|
|
|
logger.info('Creating job to send announce %s.', videoShare.url)
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
return broadcastToFollowers(data, byActor, [ byActor ], t)
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|
|
|
|
|
2018-06-12 14:04:58 -04:00
|
|
|
function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
|
|
|
|
if (!audience) audience = getAudience(byActor)
|
2017-11-27 08:44:51 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
return {
|
2017-11-20 03:43:39 -05:00
|
|
|
type: 'Announce',
|
2017-11-27 08:44:51 -05:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
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
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 12:23:10 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-03-27 07:33:56 -04:00
|
|
|
sendVideoAnnounce,
|
2017-11-27 08:44:51 -05:00
|
|
|
announceActivityData,
|
2018-03-27 07:33:56 -04:00
|
|
|
buildVideoAnnounce
|
2017-11-21 12:23:10 -05:00
|
|
|
}
|