1 import { Transaction } from 'sequelize'
2 import { logger } from '../../../helpers/logger'
3 import { ACTIVITY_PUB, database as db } from '../../../initializers'
4 import { AccountInstance } from '../../../models/account/account-interface'
5 import { activitypubHttpJobScheduler } from '../../jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler'
7 async function broadcastToFollowers (
9 byAccount: AccountInstance,
10 toAccountFollowers: AccountInstance[],
12 followersException: AccountInstance[] = []
14 const toAccountFollowerIds = toAccountFollowers.map(a => a.id)
16 const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
17 if (result.data.length === 0) {
18 logger.info('Not broadcast because of 0 followers for %s.', toAccountFollowerIds.join(', '))
22 const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl)
23 const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1)
27 signatureAccountId: byAccount.id,
31 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload)
34 async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: string, t: Transaction) {
36 uris: [ toAccountUrl ],
37 signatureAccountId: byAccount.id,
41 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload)
44 async function getAudience (accountSender: AccountInstance, isPublic = true) {
45 const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls()
47 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
52 to = [ ACTIVITY_PUB.PUBLIC ]
53 cc = followerInboxUrls
55 to = followerInboxUrls
56 cc = [ ACTIVITY_PUB.PUBLIC ]
62 // ---------------------------------------------------------------------------