]>
Commit | Line | Data |
---|---|---|
1 | import { Transaction } from 'sequelize' | |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | |
3 | import { database as db } from '../../../initializers' | |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | |
5 | import { getUpdateActivityPubUrl } from '../url' | |
6 | import { broadcastToFollowers, getAudience } from './misc' | |
7 | ||
8 | async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | |
9 | const byAccount = videoChannel.Account | |
10 | ||
11 | const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString()) | |
12 | const videoChannelObject = videoChannel.toActivityPubObject() | |
13 | const data = await updateActivityData(url, byAccount, videoChannelObject, t) | |
14 | ||
15 | const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) | |
16 | accountsInvolved.push(byAccount) | |
17 | ||
18 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | |
19 | } | |
20 | ||
21 | async function sendUpdateVideo (video: VideoInstance, t: Transaction) { | |
22 | const byAccount = video.VideoChannel.Account | |
23 | ||
24 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | |
25 | const videoObject = video.toActivityPubObject() | |
26 | const data = await updateActivityData(url, byAccount, videoObject, t) | |
27 | ||
28 | const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t) | |
29 | accountsInvolved.push(byAccount) | |
30 | ||
31 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | |
32 | } | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | ||
36 | export { | |
37 | sendUpdateVideoChannel, | |
38 | sendUpdateVideo | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | async function updateActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction) { | |
44 | const { to, cc } = await getAudience(byAccount, t) | |
45 | const activity: ActivityUpdate = { | |
46 | type: 'Update', | |
47 | id: url, | |
48 | actor: byAccount.url, | |
49 | to, | |
50 | cc, | |
51 | object | |
52 | } | |
53 | ||
54 | return activity | |
55 | } |