diff options
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 944244893..acee4fe16 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -1,9 +1,20 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import * as request from 'request' | 2 | import * as request from 'request' |
3 | import { Transaction } from 'sequelize' | ||
3 | import { ActivityIconObject } from '../../../shared/index' | 4 | import { ActivityIconObject } from '../../../shared/index' |
4 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 5 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' |
5 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers/constants' | 6 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers/constants' |
7 | import { AccountInstance } from '../../models/account/account-interface' | ||
6 | import { VideoInstance } from '../../models/video/video-interface' | 8 | import { VideoInstance } from '../../models/video/video-interface' |
9 | import { sendLikeToOrigin } from './index' | ||
10 | import { sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers } from './send/send-create' | ||
11 | import { sendLikeToVideoFollowers } from './send/send-like' | ||
12 | import { | ||
13 | sendUndoDislikeToOrigin, | ||
14 | sendUndoDislikeToVideoFollowers, | ||
15 | sendUndoLikeToOrigin, | ||
16 | sendUndoLikeToVideoFollowers | ||
17 | } from './send/send-undo' | ||
7 | 18 | ||
8 | function fetchRemoteVideoPreview (video: VideoInstance) { | 19 | function fetchRemoteVideoPreview (video: VideoInstance) { |
9 | // FIXME: use url | 20 | // FIXME: use url |
@@ -37,8 +48,42 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec | |||
37 | return doRequestAndSaveToFile(options, thumbnailPath) | 48 | return doRequestAndSaveToFile(options, thumbnailPath) |
38 | } | 49 | } |
39 | 50 | ||
51 | function sendVideoRateChangeToFollowers (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) { | ||
52 | const tasks: Promise<any>[] = [] | ||
53 | |||
54 | // Undo Like | ||
55 | if (likes < 0) tasks.push(sendUndoLikeToVideoFollowers(account, video, t)) | ||
56 | // Like | ||
57 | if (likes > 0) tasks.push(sendLikeToVideoFollowers(account, video, t)) | ||
58 | |||
59 | // Undo Dislike | ||
60 | if (dislikes < 0) tasks.push(sendUndoDislikeToVideoFollowers(account, video, t)) | ||
61 | // Dislike | ||
62 | if (dislikes > 0) tasks.push(sendCreateDislikeToVideoFollowers(account, video, t)) | ||
63 | |||
64 | return Promise.all(tasks) | ||
65 | } | ||
66 | |||
67 | function sendVideoRateChangeToOrigin (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) { | ||
68 | const tasks: Promise<any>[] = [] | ||
69 | |||
70 | // Undo Like | ||
71 | if (likes < 0) tasks.push(sendUndoLikeToOrigin(account, video, t)) | ||
72 | // Like | ||
73 | if (likes > 0) tasks.push(sendLikeToOrigin(account, video, t)) | ||
74 | |||
75 | // Undo Dislike | ||
76 | if (dislikes < 0) tasks.push(sendUndoDislikeToOrigin(account, video, t)) | ||
77 | // Dislike | ||
78 | if (dislikes > 0) tasks.push(sendCreateDislikeToOrigin(account, video, t)) | ||
79 | |||
80 | return Promise.all(tasks) | ||
81 | } | ||
82 | |||
40 | export { | 83 | export { |
41 | fetchRemoteVideoPreview, | 84 | fetchRemoteVideoPreview, |
42 | fetchRemoteVideoDescription, | 85 | fetchRemoteVideoDescription, |
43 | generateThumbnailFromUrl | 86 | generateThumbnailFromUrl, |
87 | sendVideoRateChangeToFollowers, | ||
88 | sendVideoRateChangeToOrigin | ||
44 | } | 89 | } |