import { Transaction } from 'sequelize' ; import { ActivityAudience , ActivityFlag } from '../../../../shared/models/activitypub' ; import { logger } from '../../../helpers/logger' ; import { MAbuseAP , MAccountLight , MActor } from '../../../types/models' ; import { audiencify , getAudience } from '../audience' ; import { getLocalAbuseActivityPubUrl } from '../url' ; import { unicastTo } from './utils' ; function sendAbuse ( byActor , abuse , flaggedAccount , t ) { if ( ! flaggedAccount . Actor . serverId ) return ; const url = getLocalAbuseActivityPubUrl ( abuse ) ; logger . info ( 'Creating job to send abuse %s.' , url ) ; 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 , byActor , abuse , audience ) { if ( ! audience ) audience = getAudience ( byActor ) ; const activity = Object . assign ( { id : url , actor : byActor . url } , abuse . toActivityPubObject ( ) ) ; return audiencify ( activity , audience ) ; } export { sendAbuse } ;