2020-07-01 10:05:30 -04:00
|
|
|
import { Transaction } from 'sequelize'
|
2022-03-18 06:17:35 -04:00
|
|
|
import { ActivityAudience, ActivityFlag } from '@shared/models'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
|
2019-01-15 08:52:33 -05:00
|
|
|
import { audiencify, getAudience } from '../audience'
|
2020-11-20 05:21:08 -05:00
|
|
|
import { getLocalAbuseActivityPubUrl } from '../url'
|
2022-03-18 06:17:35 -04:00
|
|
|
import { unicastTo } from './shared/send-utils'
|
2019-01-15 08:52:33 -05:00
|
|
|
|
2020-07-01 10:05:30 -04:00
|
|
|
function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
|
|
|
|
if (!flaggedAccount.Actor.serverId) return // Local user
|
2019-01-15 08:52:33 -05:00
|
|
|
|
2020-11-20 05:21:08 -05:00
|
|
|
const url = getLocalAbuseActivityPubUrl(abuse)
|
2019-01-15 08:52:33 -05:00
|
|
|
|
2020-07-01 10:05:30 -04:00
|
|
|
logger.info('Creating job to send abuse %s.', url)
|
2019-01-15 08:52:33 -05:00
|
|
|
|
|
|
|
// Custom audience, we only send the abuse to the origin instance
|
2020-07-01 10:05:30 -04:00
|
|
|
const audience = { to: [ flaggedAccount.Actor.url ], cc: [] }
|
|
|
|
const flagActivity = buildFlagActivity(url, byActor, abuse, audience)
|
2019-01-15 08:52:33 -05:00
|
|
|
|
2022-03-23 11:14:33 -04:00
|
|
|
return t.afterCommit(() => {
|
|
|
|
return unicastTo({
|
|
|
|
data: flagActivity,
|
|
|
|
byActor,
|
|
|
|
toActorUrl: flaggedAccount.Actor.getSharedInbox(),
|
|
|
|
contextType: 'Flag'
|
|
|
|
})
|
|
|
|
})
|
2019-01-15 08:52:33 -05:00
|
|
|
}
|
|
|
|
|
2020-07-01 10:05:30 -04:00
|
|
|
function buildFlagActivity (url: string, byActor: MActor, abuse: MAbuseAP, audience: ActivityAudience): ActivityFlag {
|
2019-01-15 08:52:33 -05:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
2022-03-23 11:14:33 -04:00
|
|
|
const activity = { id: url, actor: byActor.url, ...abuse.toActivityPubObject() }
|
2019-01-15 08:52:33 -05:00
|
|
|
|
|
|
|
return audiencify(activity, audience)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2020-07-01 10:05:30 -04:00
|
|
|
sendAbuse
|
2019-01-15 08:52:33 -05:00
|
|
|
}
|