]>
Commit | Line | Data |
---|---|---|
0032ebe9 | 1 | import { Transaction } from 'sequelize' |
3fd3ab2d | 2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' |
50d6de9c | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
3fd3ab2d | 4 | import { VideoModel } from '../../../models/video/video' |
0032ebe9 C |
5 | import { getVideoLikeActivityPubUrl } from '../url' |
6 | import { | |
7 | broadcastToFollowers, | |
50d6de9c | 8 | getActorsInvolvedInVideo, |
0032ebe9 | 9 | getAudience, |
4e50b6a1 | 10 | getObjectFollowersAudience, |
50d6de9c | 11 | getOriginVideoAudience, |
0032ebe9 C |
12 | unicastTo |
13 | } from './misc' | |
14 | ||
50d6de9c C |
15 | async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
16 | const url = getVideoLikeActivityPubUrl(byActor, video) | |
0032ebe9 | 17 | |
50d6de9c | 18 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
63c93323 | 19 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) |
50d6de9c | 20 | const data = await likeActivityData(url, byActor, video, t, audience) |
0032ebe9 | 21 | |
50d6de9c | 22 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
0032ebe9 C |
23 | } |
24 | ||
50d6de9c C |
25 | async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
26 | const url = getVideoLikeActivityPubUrl(byActor, video) | |
0032ebe9 | 27 | |
50d6de9c | 28 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
4e50b6a1 | 29 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
50d6de9c | 30 | const data = await likeActivityData(url, byActor, video, t, audience) |
0032ebe9 | 31 | |
50d6de9c C |
32 | const followersException = [ byActor ] |
33 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) | |
0032ebe9 C |
34 | } |
35 | ||
25ed141c C |
36 | async function likeActivityData ( |
37 | url: string, | |
50d6de9c | 38 | byActor: ActorModel, |
3fd3ab2d | 39 | video: VideoModel, |
25ed141c C |
40 | t: Transaction, |
41 | audience?: ActivityAudience | |
3fd3ab2d | 42 | ): Promise<ActivityLike> { |
0032ebe9 | 43 | if (!audience) { |
50d6de9c | 44 | audience = await getAudience(byActor, t) |
0032ebe9 C |
45 | } |
46 | ||
3fd3ab2d | 47 | return { |
0032ebe9 C |
48 | type: 'Like', |
49 | id: url, | |
50d6de9c | 50 | actor: byActor.url, |
0032ebe9 C |
51 | to: audience.to, |
52 | cc: audience.cc, | |
53 | object: video.url | |
54 | } | |
0032ebe9 C |
55 | } |
56 | ||
57 | // --------------------------------------------------------------------------- | |
58 | ||
59 | export { | |
60 | sendLikeToOrigin, | |
61 | sendLikeToVideoFollowers, | |
62 | likeActivityData | |
63 | } |