2017-11-23 07:19:55 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-11-23 07:19:55 -06:00
|
|
|
import { getVideoLikeActivityPubUrl } from '../url'
|
|
|
|
import {
|
2017-12-19 03:34:56 -06:00
|
|
|
audiencify,
|
2017-11-23 07:19:55 -06:00
|
|
|
broadcastToFollowers,
|
2017-12-14 10:38:41 -06:00
|
|
|
getActorsInvolvedInVideo,
|
2017-11-23 07:19:55 -06:00
|
|
|
getAudience,
|
2017-11-27 07:44:51 -06:00
|
|
|
getObjectFollowersAudience,
|
2017-12-14 10:38:41 -06:00
|
|
|
getOriginVideoAudience,
|
2017-11-23 07:19:55 -06:00
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
2017-11-24 06:41:10 -06:00
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
2017-12-14 10:38:41 -06:00
|
|
|
const data = await likeActivityData(url, byActor, video, t, audience)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2018-01-25 08:05:18 -06:00
|
|
|
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
2017-11-27 07:44:51 -06:00
|
|
|
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
2017-12-14 10:38:41 -06:00
|
|
|
const data = await likeActivityData(url, byActor, video, t, audience)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
const followersException = [ byActor ]
|
|
|
|
return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
2017-11-30 04:31:15 -06:00
|
|
|
async function likeActivityData (
|
|
|
|
url: string,
|
2017-12-14 10:38:41 -06:00
|
|
|
byActor: ActorModel,
|
2017-12-12 10:53:50 -06:00
|
|
|
video: VideoModel,
|
2017-11-30 04:31:15 -06:00
|
|
|
t: Transaction,
|
|
|
|
audience?: ActivityAudience
|
2017-12-12 10:53:50 -06:00
|
|
|
): Promise<ActivityLike> {
|
2017-11-23 07:19:55 -06:00
|
|
|
if (!audience) {
|
2017-12-14 10:38:41 -06:00
|
|
|
audience = await getAudience(byActor, t)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
2017-12-19 03:34:56 -06:00
|
|
|
return audiencify({
|
2018-03-27 03:26:52 -05:00
|
|
|
type: 'Like' as 'Like',
|
2017-11-23 07:19:55 -06:00
|
|
|
id: url,
|
2017-12-14 10:38:41 -06:00
|
|
|
actor: byActor.url,
|
2017-11-23 07:19:55 -06:00
|
|
|
object: video.url
|
2017-12-19 03:34:56 -06:00
|
|
|
}, audience)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendLikeToOrigin,
|
|
|
|
sendLikeToVideoFollowers,
|
|
|
|
likeActivityData
|
|
|
|
}
|