diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 09:43:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 54141398354e6e7b94aa3065a705a1251390111c (patch) | |
tree | 8d30d1b9ea8acbe04f6d404125b04fc0c9897b70 /server/lib/activitypub/send/send-update.ts | |
parent | eb8b27c93e61a896a08923dc1ca3c87ba8cf4948 (diff) | |
download | PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.gz PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.zst PeerTube-54141398354e6e7b94aa3065a705a1251390111c.zip |
Refractor activity pub lib/helpers
Diffstat (limited to 'server/lib/activitypub/send/send-update.ts')
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts new file mode 100644 index 000000000..42738f973 --- /dev/null +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -0,0 +1,55 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | ||
3 | import { getUpdateActivityPubUrl } from '../../../helpers/activitypub' | ||
4 | import { database as db } from '../../../initializers' | ||
5 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | ||
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) | ||
14 | |||
15 | const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id) | ||
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) | ||
27 | |||
28 | const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id) | ||
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) { | ||
44 | const { to, cc } = await getAudience(byAccount) | ||
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 | } | ||