diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/lib/activitypub/send/send-create.ts | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index a34d3776c..9fbaa8196 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
3 | import { getServerAccount } from '../../../helpers/utils' | 3 | import { getServerAccount } from '../../../helpers' |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | ||
7 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
7 | import { | 9 | import { |
8 | broadcastToFollowers, | 10 | broadcastToFollowers, |
@@ -13,7 +15,7 @@ import { | |||
13 | unicastTo | 15 | unicastTo |
14 | } from './misc' | 16 | } from './misc' |
15 | 17 | ||
16 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 18 | async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
17 | const byAccount = videoChannel.Account | 19 | const byAccount = videoChannel.Account |
18 | 20 | ||
19 | const videoChannelObject = videoChannel.toActivityPubObject() | 21 | const videoChannelObject = videoChannel.toActivityPubObject() |
@@ -22,7 +24,7 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Tr | |||
22 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 24 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
23 | } | 25 | } |
24 | 26 | ||
25 | async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { | 27 | async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
26 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 28 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
27 | 29 | ||
28 | const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } | 30 | const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } |
@@ -31,7 +33,7 @@ async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbus | |||
31 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 33 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
32 | } | 34 | } |
33 | 35 | ||
34 | async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 36 | async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
35 | const url = getVideoViewActivityPubUrl(byAccount, video) | 37 | const url = getVideoViewActivityPubUrl(byAccount, video) |
36 | const viewActivity = createViewActivityData(byAccount, video) | 38 | const viewActivity = createViewActivityData(byAccount, video) |
37 | 39 | ||
@@ -42,7 +44,7 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI | |||
42 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 44 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
43 | } | 45 | } |
44 | 46 | ||
45 | async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 47 | async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
46 | const url = getVideoViewActivityPubUrl(byAccount, video) | 48 | const url = getVideoViewActivityPubUrl(byAccount, video) |
47 | const viewActivity = createViewActivityData(byAccount, video) | 49 | const viewActivity = createViewActivityData(byAccount, video) |
48 | 50 | ||
@@ -56,7 +58,7 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video | |||
56 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 58 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) |
57 | } | 59 | } |
58 | 60 | ||
59 | async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 61 | async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
60 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 62 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
61 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 63 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
62 | 64 | ||
@@ -67,7 +69,7 @@ async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: Vid | |||
67 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 69 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
68 | } | 70 | } |
69 | 71 | ||
70 | async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 72 | async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
71 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 73 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
72 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 74 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
73 | 75 | ||
@@ -79,12 +81,18 @@ async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, vi | |||
79 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) | 81 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) |
80 | } | 82 | } |
81 | 83 | ||
82 | async function createActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction, audience?: ActivityAudience) { | 84 | async function createActivityData ( |
85 | url: string, | ||
86 | byAccount: AccountModel, | ||
87 | object: any, | ||
88 | t: Transaction, | ||
89 | audience?: ActivityAudience | ||
90 | ): Promise<ActivityCreate> { | ||
83 | if (!audience) { | 91 | if (!audience) { |
84 | audience = await getAudience(byAccount, t) | 92 | audience = await getAudience(byAccount, t) |
85 | } | 93 | } |
86 | 94 | ||
87 | const activity: ActivityCreate = { | 95 | return { |
88 | type: 'Create', | 96 | type: 'Create', |
89 | id: url, | 97 | id: url, |
90 | actor: byAccount.url, | 98 | actor: byAccount.url, |
@@ -92,18 +100,14 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje | |||
92 | cc: audience.cc, | 100 | cc: audience.cc, |
93 | object | 101 | object |
94 | } | 102 | } |
95 | |||
96 | return activity | ||
97 | } | 103 | } |
98 | 104 | ||
99 | function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) { | 105 | function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) { |
100 | const obj = { | 106 | return { |
101 | type: 'Dislike', | 107 | type: 'Dislike', |
102 | actor: byAccount.url, | 108 | actor: byAccount.url, |
103 | object: video.url | 109 | object: video.url |
104 | } | 110 | } |
105 | |||
106 | return obj | ||
107 | } | 111 | } |
108 | 112 | ||
109 | // --------------------------------------------------------------------------- | 113 | // --------------------------------------------------------------------------- |
@@ -121,12 +125,10 @@ export { | |||
121 | 125 | ||
122 | // --------------------------------------------------------------------------- | 126 | // --------------------------------------------------------------------------- |
123 | 127 | ||
124 | function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) { | 128 | function createViewActivityData (byAccount: AccountModel, video: VideoModel) { |
125 | const obj = { | 129 | return { |
126 | type: 'View', | 130 | type: 'View', |
127 | actor: byAccount.url, | 131 | actor: byAccount.url, |
128 | object: video.url | 132 | object: video.url |
129 | } | 133 | } |
130 | |||
131 | return obj | ||
132 | } | 134 | } |