+import {
+ activitypubHttpJobScheduler,
+ ActivityPubHttpPayload
+} from '../../jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler'
+
+async function forwardActivity (
+ activity: Activity,
+ t: Transaction,
+ followersException: AccountInstance[] = []
+) {
+ const to = activity.to || []
+ const cc = activity.cc || []
+
+ const followersUrls: string[] = []
+ for (const dest of to.concat(cc)) {
+ if (dest.endsWith('/followers')) {
+ followersUrls.push(dest)
+ }
+ }
+
+ const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls, t)
+ const uris = await computeFollowerUris(toAccountFollowers, followersException, t)
+
+ if (uris.length === 0) {
+ logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', '))
+ return undefined
+ }
+
+ logger.debug('Creating forwarding job.', { uris })
+
+ const jobPayload: ActivityPubHttpPayload = {
+ uris,
+ body: activity
+ }
+
+ return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload)
+}