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