aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-flag.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-05-05 20:22:22 +0200
committerRigel Kent <par@rigelk.eu>2020-05-08 15:31:51 +0200
commitdf4c603dea022146476812cbbc2b9f8f1e5e4870 (patch)
treec0d27576fb6711b4b64d2186e8dca3f04b9b1dfe /server/lib/activitypub/process/process-flag.ts
parent91b8e675e26dd65e1ebb23706cb16b3a3f8bcf73 (diff)
downloadPeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.tar.gz
PeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.tar.zst
PeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.zip
Switch emails to pug templates and provide richer html/text-only versions
Diffstat (limited to 'server/lib/activitypub/process/process-flag.ts')
-rw-r--r--server/lib/activitypub/process/process-flag.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts
index 9a488a473..7337f337c 100644
--- a/server/lib/activitypub/process/process-flag.ts
+++ b/server/lib/activitypub/process/process-flag.ts
@@ -8,7 +8,8 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos'
8import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
9import { getAPId } from '../../../helpers/activitypub' 9import { getAPId } from '../../../helpers/activitypub'
10import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 10import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
11import { MActorSignature, MVideoAbuseVideo } from '../../../typings/models' 11import { MActorSignature, MVideoAbuseAccountVideo } from '../../../typings/models'
12import { AccountModel } from '@server/models/account/account'
12 13
13async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) { 14async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) {
14 const { activity, byActor } = options 15 const { activity, byActor } = options
@@ -36,8 +37,9 @@ async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag,
36 logger.debug('Reporting remote abuse for video %s.', getAPId(object)) 37 logger.debug('Reporting remote abuse for video %s.', getAPId(object))
37 38
38 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: object }) 39 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: object })
40 const reporterAccount = await sequelizeTypescript.transaction(async t => AccountModel.load(account.id, t))
39 41
40 const videoAbuse = await sequelizeTypescript.transaction(async t => { 42 const videoAbuseInstance = await sequelizeTypescript.transaction(async t => {
41 const videoAbuseData = { 43 const videoAbuseData = {
42 reporterAccountId: account.id, 44 reporterAccountId: account.id,
43 reason: flag.content, 45 reason: flag.content,
@@ -45,15 +47,22 @@ async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag,
45 state: VideoAbuseState.PENDING 47 state: VideoAbuseState.PENDING
46 } 48 }
47 49
48 const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) as MVideoAbuseVideo 50 const videoAbuseInstance: MVideoAbuseAccountVideo = await VideoAbuseModel.create(videoAbuseData, { transaction: t })
49 videoAbuseInstance.Video = video 51 videoAbuseInstance.Video = video
52 videoAbuseInstance.Account = reporterAccount
50 53
51 logger.info('Remote abuse for video uuid %s created', flag.object) 54 logger.info('Remote abuse for video uuid %s created', flag.object)
52 55
53 return videoAbuseInstance 56 return videoAbuseInstance
54 }) 57 })
55 58
56 Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse) 59 const videoAbuseJSON = videoAbuseInstance.toFormattedJSON()
60
61 Notifier.Instance.notifyOnNewVideoAbuse({
62 videoAbuse: videoAbuseJSON,
63 videoAbuseInstance,
64 reporter: reporterAccount.Actor.getIdentifier()
65 })
57 } catch (err) { 66 } catch (err) {
58 logger.debug('Cannot process report of %s. (Maybe not a video abuse).', getAPId(object), { err }) 67 logger.debug('Cannot process report of %s. (Maybe not a video abuse).', getAPId(object), { err })
59 } 68 }