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 (data: any, byAccount: AccountInstance, toAccountFollowers: AccountInstance[], t: Transaction) {
8 const toAccountFollowerIds = toAccountFollowers.map(a => a.id)
9 const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
10 if (result.data.length === 0) {
11 logger.info('Not broadcast because of 0 followers for %s.', toAccountFollowerIds.join(', '))
17 signatureAccountId: byAccount.id,
21 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload)
24 async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: string, t: Transaction) {
26 uris: [ toAccountUrl ],
27 signatureAccountId: byAccount.id,
31 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload)
34 async function getAudience (accountSender: AccountInstance, isPublic = true) {
35 const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls()
37 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
42 to = [ ACTIVITY_PUB.PUBLIC ]
43 cc = followerInboxUrls
45 to = followerInboxUrls
46 cc = [ ACTIVITY_PUB.PUBLIC ]
52 // ---------------------------------------------------------------------------