2019-01-15 14:52:33 +01:00
|
|
|
import { getVideoAbuseActivityPubUrl } from '../url'
|
|
|
|
import { unicastTo } from './utils'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
|
|
|
|
import { audiencify, getAudience } from '../audience'
|
2019-07-29 11:59:29 +02:00
|
|
|
import { Transaction } from 'sequelize'
|
2019-08-15 11:53:26 +02:00
|
|
|
import { MActor, MVideoFullLight } from '../../../typings/models'
|
|
|
|
import { MVideoAbuseVideo } from '../../../typings/models/video'
|
2019-01-15 14:52:33 +01:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
function sendVideoAbuse (byActor: MActor, videoAbuse: MVideoAbuseVideo, video: MVideoFullLight, t: Transaction) {
|
2019-01-15 14:52:33 +01:00
|
|
|
if (!video.VideoChannel.Account.Actor.serverId) return // Local user
|
|
|
|
|
|
|
|
const url = getVideoAbuseActivityPubUrl(videoAbuse)
|
|
|
|
|
|
|
|
logger.info('Creating job to send video abuse %s.', url)
|
|
|
|
|
|
|
|
// Custom audience, we only send the abuse to the origin instance
|
|
|
|
const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
|
|
|
|
const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience)
|
|
|
|
|
2019-10-23 11:33:53 +02:00
|
|
|
t.afterCommit(() => unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.getSharedInbox()))
|
2019-01-15 14:52:33 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
function buildFlagActivity (url: string, byActor: MActor, videoAbuse: MVideoAbuseVideo, audience: ActivityAudience): ActivityFlag {
|
2019-01-15 14:52:33 +01:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
const activity = Object.assign(
|
|
|
|
{ id: url, actor: byActor.url },
|
|
|
|
videoAbuse.toActivityPubObject()
|
|
|
|
)
|
|
|
|
|
|
|
|
return audiencify(activity, audience)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendVideoAbuse
|
|
|
|
}
|