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