import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
-import { AccountModel } from '../../../models/account/account'
+import { ActorModel } from '../../../models/activitypub/actor'
import { VideoModel } from '../../../models/video/video'
import { getVideoLikeActivityPubUrl } from '../url'
import {
+ audiencify,
broadcastToFollowers,
- getAccountsInvolvedInVideo,
+ getActorsInvolvedInVideo,
getAudience,
- getOriginVideoAudience,
getObjectFollowersAudience,
+ getOriginVideoAudience,
unicastTo
} from './misc'
-async function sendLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
- const url = getVideoLikeActivityPubUrl(byAccount, video)
+async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
+ const url = getVideoLikeActivityPubUrl(byActor, video)
- const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
- const data = await likeActivityData(url, byAccount, video, t, audience)
+ const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
-}
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
+ const data = await likeActivityData(url, byActor, video, t, audience)
-async function sendLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
- const url = getVideoLikeActivityPubUrl(byAccount, video)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
- const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
+ // Send to followers
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
- const data = await likeActivityData(url, byAccount, video, t, audience)
+ const data = await likeActivityData(url, byActor, video, t, audience)
- const followersException = [ byAccount ]
- return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException)
+ const followersException = [ byActor ]
+ return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
}
async function likeActivityData (
url: string,
- byAccount: AccountModel,
+ byActor: ActorModel,
video: VideoModel,
t: Transaction,
audience?: ActivityAudience
): Promise<ActivityLike> {
if (!audience) {
- audience = await getAudience(byAccount, t)
+ audience = await getAudience(byActor, t)
}
- return {
- type: 'Like',
+ return audiencify({
+ type: 'Like' as 'Like',
id: url,
- actor: byAccount.url,
- to: audience.to,
- cc: audience.cc,
+ actor: byActor.url,
object: video.url
- }
+ }, audience)
}
// ---------------------------------------------------------------------------
export {
- sendLikeToOrigin,
- sendLikeToVideoFollowers,
+ sendLike,
likeActivityData
}