1 import * as Sequelize from 'sequelize'
3 import { database as db } from '../../initializers'
9 import { httpRequestJobScheduler } from '../jobs'
10 import { signObject, activityPubContextify } from '../../helpers'
11 import { Activity } from '../../../shared'
13 function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
14 const videoChannelObject = videoChannel.toActivityPubObject()
15 const data = createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
17 return broadcastToFollowers(data, videoChannel.Account, t)
20 function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
21 const videoChannelObject = videoChannel.toActivityPubObject()
22 const data = updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
24 return broadcastToFollowers(data, videoChannel.Account, t)
27 function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
28 const videoChannelObject = videoChannel.toActivityPubObject()
29 const data = deleteActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
31 return broadcastToFollowers(data, videoChannel.Account, t)
34 function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
35 const videoObject = video.toActivityPubObject()
36 const data = addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject)
38 return broadcastToFollowers(data, video.VideoChannel.Account, t)
41 function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) {
42 const videoObject = video.toActivityPubObject()
43 const data = updateActivityData(video.url, video.VideoChannel.Account, videoObject)
45 return broadcastToFollowers(data, video.VideoChannel.Account, t)
48 function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
49 const videoObject = video.toActivityPubObject()
50 const data = deleteActivityData(video.url, video.VideoChannel.Account, videoObject)
52 return broadcastToFollowers(data, video.VideoChannel.Account, t)
55 // ---------------------------------------------------------------------------
58 sendCreateVideoChannel,
59 sendUpdateVideoChannel,
60 sendDeleteVideoChannel,
66 // ---------------------------------------------------------------------------
68 async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) {
69 const result = await db.Account.listFollowerUrlsForApi(fromAccount.name, 0)
76 return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload)
79 function buildSignedActivity (byAccount: AccountInstance, data: Object) {
80 const activity = activityPubContextify(data)
82 return signObject(byAccount, activity) as Promise<Activity>
85 async function getPublicActivityTo (account: AccountInstance) {
86 const inboxUrls = await account.getFollowerSharedInboxUrls()
88 return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public')
91 async function createActivityData (url: string, byAccount: AccountInstance, object: any) {
92 const to = await getPublicActivityTo(byAccount)
101 return buildSignedActivity(byAccount, base)
104 async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
105 const to = await getPublicActivityTo(byAccount)
109 actor: byAccount.url,
114 return buildSignedActivity(byAccount, base)
117 async function deleteActivityData (url: string, byAccount: AccountInstance, object: any) {
118 const to = await getPublicActivityTo(byAccount)
122 actor: byAccount.url,
127 return buildSignedActivity(byAccount, base)
130 async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any) {
131 const to = await getPublicActivityTo(byAccount)
135 actor: byAccount.url,
141 return buildSignedActivity(byAccount, base)