]>
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 { | |
e12a0092 | 7 | audiencify, |
0032ebe9 | 8 | broadcastToFollowers, |
50d6de9c | 9 | getActorsInvolvedInVideo, |
0032ebe9 | 10 | getAudience, |
4e50b6a1 | 11 | getObjectFollowersAudience, |
50d6de9c | 12 | getOriginVideoAudience, |
0032ebe9 C |
13 | unicastTo |
14 | } from './misc' | |
15 | ||
07197db4 | 16 | async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
50d6de9c | 17 | const url = getVideoLikeActivityPubUrl(byActor, video) |
0032ebe9 | 18 | |
50d6de9c | 19 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
0032ebe9 | 20 | |
07197db4 C |
21 | // Send to origin |
22 | if (video.isOwned() === false) { | |
23 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
24 | const data = await likeActivityData(url, byActor, video, t, audience) | |
0032ebe9 | 25 | |
07197db4 C |
26 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
27 | } | |
0032ebe9 | 28 | |
07197db4 | 29 | // Send to followers |
4e50b6a1 | 30 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
50d6de9c | 31 | const data = await likeActivityData(url, byActor, video, t, audience) |
0032ebe9 | 32 | |
50d6de9c C |
33 | const followersException = [ byActor ] |
34 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) | |
0032ebe9 C |
35 | } |
36 | ||
25ed141c C |
37 | async function likeActivityData ( |
38 | url: string, | |
50d6de9c | 39 | byActor: ActorModel, |
3fd3ab2d | 40 | video: VideoModel, |
25ed141c C |
41 | t: Transaction, |
42 | audience?: ActivityAudience | |
3fd3ab2d | 43 | ): Promise<ActivityLike> { |
0032ebe9 | 44 | if (!audience) { |
50d6de9c | 45 | audience = await getAudience(byActor, t) |
0032ebe9 C |
46 | } |
47 | ||
e12a0092 | 48 | return audiencify({ |
73c08093 | 49 | type: 'Like' as 'Like', |
0032ebe9 | 50 | id: url, |
50d6de9c | 51 | actor: byActor.url, |
0032ebe9 | 52 | object: video.url |
e12a0092 | 53 | }, audience) |
0032ebe9 C |
54 | } |
55 | ||
56 | // --------------------------------------------------------------------------- | |
57 | ||
58 | export { | |
07197db4 | 59 | sendLike, |
0032ebe9 C |
60 | likeActivityData |
61 | } |