PeerTube/server/lib/activitypub/send/send-flag.ts

39 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-07-01 16:05:30 +02:00
import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
2020-07-01 16:05:30 +02:00
import { logger } from '../../../helpers/logger'
import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
import { audiencify, getAudience } from '../audience'
2020-11-20 11:21:08 +01:00
import { getLocalAbuseActivityPubUrl } from '../url'
2020-07-01 16:05:30 +02:00
import { unicastTo } from './utils'
2020-07-01 16:05:30 +02:00
function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
if (!flaggedAccount.Actor.serverId) return // Local user
2020-11-20 11:21:08 +01:00
const url = getLocalAbuseActivityPubUrl(abuse)
2020-07-01 16:05:30 +02:00
logger.info('Creating job to send abuse %s.', url)
// Custom audience, we only send the abuse to the origin instance
2020-07-01 16:05:30 +02:00
const audience = { to: [ flaggedAccount.Actor.url ], cc: [] }
const flagActivity = buildFlagActivity(url, byActor, abuse, audience)
2020-07-01 16:05:30 +02:00
t.afterCommit(() => unicastTo(flagActivity, byActor, flaggedAccount.Actor.getSharedInbox()))
}
2020-07-01 16:05:30 +02:00
function buildFlagActivity (url: string, byActor: MActor, abuse: MAbuseAP, audience: ActivityAudience): ActivityFlag {
if (!audience) audience = getAudience(byActor)
const activity = Object.assign(
{ id: url, actor: byActor.url },
2020-07-01 16:05:30 +02:00
abuse.toActivityPubObject()
)
return audiencify(activity, audience)
}
// ---------------------------------------------------------------------------
export {
2020-07-01 16:05:30 +02:00
sendAbuse
}