From 0b5c385b4529f3bef8f9523de3f9470ffa58f5f5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Aug 2019 09:40:21 +0200 Subject: Handle reports from mastodon --- server/lib/activitypub/process/process-flag.ts | 40 +++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'server/lib/activitypub/process/process-flag.ts') diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts index 422386540..e6e9084de 100644 --- a/server/lib/activitypub/process/process-flag.ts +++ b/server/lib/activitypub/process/process-flag.ts @@ -26,28 +26,36 @@ export { async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: MActorSignature) { 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 if (!account) throw new Error('Cannot create video abuse with the non account actor ' + byActor.url) - const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: flag.object }) + const objects = Array.isArray(flag.object) ? flag.object : [ flag.object ] - const videoAbuse = await sequelizeTypescript.transaction(async t => { - const videoAbuseData = { - reporterAccountId: account.id, - reason: flag.content, - videoId: video.id, - state: VideoAbuseState.PENDING - } + for (const object of objects) { + try { + logger.debug('Reporting remote abuse for video %s.', getAPId(object)) + + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: object }) - const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) as MVideoAbuseVideo - videoAbuseInstance.Video = video + const videoAbuse = await sequelizeTypescript.transaction(async t => { + const videoAbuseData = { + reporterAccountId: account.id, + reason: flag.content, + videoId: video.id, + state: VideoAbuseState.PENDING + } - logger.info('Remote abuse for video uuid %s created', flag.object) + const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) as MVideoAbuseVideo + videoAbuseInstance.Video = video - return videoAbuseInstance - }) + logger.info('Remote abuse for video uuid %s created', flag.object) - Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse) + return videoAbuseInstance + }) + + Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse) + } catch (err) { + logger.debug('Cannot process report of %s. (Maybe not a video abuse).', getAPId(object), { err }) + } + } } -- cgit v1.2.3