1
0
Fork 0
peertube/server/lib/activitypub/send/send-flag.ts
Chocobozzz 57e4e1c1a9
Don't store remote rates of remote videos
In the future we'll stop to expose all available rates to improve users
privacy
2022-03-18 11:21:50 +01:00

38 lines
1.3 KiB
TypeScript

import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityFlag } from '@shared/models'
import { logger } from '../../../helpers/logger'
import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
import { audiencify, getAudience } from '../audience'
import { getLocalAbuseActivityPubUrl } from '../url'
import { unicastTo } from './shared/send-utils'
function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
if (!flaggedAccount.Actor.serverId) return // Local user
const url = getLocalAbuseActivityPubUrl(abuse)
logger.info('Creating job to send abuse %s.', url)
// Custom audience, we only send the abuse to the origin instance
const audience = { to: [ flaggedAccount.Actor.url ], cc: [] }
const flagActivity = buildFlagActivity(url, byActor, abuse, audience)
t.afterCommit(() => unicastTo(flagActivity, byActor, flaggedAccount.Actor.getSharedInbox()))
}
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 },
abuse.toActivityPubObject()
)
return audiencify(activity, audience)
}
// ---------------------------------------------------------------------------
export {
sendAbuse
}