2019-01-15 05:14:12 -05:00
|
|
|
import { ActivityCreate, ActivityFlag, VideoAbuseState } from '../../../../shared'
|
|
|
|
import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects'
|
|
|
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { sequelizeTypescript } from '../../../initializers'
|
|
|
|
import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
|
|
|
import { getOrCreateVideoAndAccountAndChannel } from '../videos'
|
|
|
|
import { Notifier } from '../../notifier'
|
|
|
|
import { getAPId } from '../../../helpers/activitypub'
|
2019-08-02 04:53:36 -04:00
|
|
|
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
|
2019-08-09 02:17:16 -04:00
|
|
|
import { SignatureActorModel } from '../../../typings/models'
|
2019-01-15 05:14:12 -05:00
|
|
|
|
2019-08-02 04:53:36 -04:00
|
|
|
async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) {
|
|
|
|
const { activity, byActor } = options
|
2019-01-15 05:14:12 -05:00
|
|
|
return retryTransactionWrapper(processCreateVideoAbuse, activity, byActor)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processFlagActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-08-09 02:17:16 -04:00
|
|
|
async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: SignatureActorModel) {
|
2019-01-15 05:14:12 -05:00
|
|
|
const flag = activity.type === 'Flag' ? activity : (activity.object as VideoAbuseObject)
|
|
|
|
|
|
|
|
logger.debug('Reporting remote abuse for video %s.', getAPId(flag.object))
|
|
|
|
|
|
|
|
const account = byActor.Account
|
2019-07-02 05:21:14 -04:00
|
|
|
if (!account) throw new Error('Cannot create video abuse with the non account actor ' + byActor.url)
|
2019-01-15 05:14:12 -05:00
|
|
|
|
|
|
|
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: flag.object })
|
|
|
|
|
2019-07-29 05:59:29 -04:00
|
|
|
const videoAbuse = await sequelizeTypescript.transaction(async t => {
|
2019-01-15 05:14:12 -05:00
|
|
|
const videoAbuseData = {
|
|
|
|
reporterAccountId: account.id,
|
|
|
|
reason: flag.content,
|
|
|
|
videoId: video.id,
|
|
|
|
state: VideoAbuseState.PENDING
|
|
|
|
}
|
|
|
|
|
|
|
|
const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t })
|
|
|
|
videoAbuseInstance.Video = video
|
|
|
|
|
|
|
|
logger.info('Remote abuse for video uuid %s created', flag.object)
|
2019-07-29 05:59:29 -04:00
|
|
|
|
|
|
|
return videoAbuseInstance
|
2019-01-15 05:14:12 -05:00
|
|
|
})
|
2019-07-29 05:59:29 -04:00
|
|
|
|
|
|
|
Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse)
|
2019-01-15 05:14:12 -05:00
|
|
|
}
|