2017-11-23 08:19:55 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-11-23 08:19:55 -05:00
|
|
|
import { getVideoLikeActivityPubUrl } from '../url'
|
2018-05-25 05:32:36 -04:00
|
|
|
import { broadcastToFollowers, unicastTo } from './utils'
|
|
|
|
import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
|
2018-07-30 11:02:40 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
2018-07-30 11:02:40 -04:00
|
|
|
logger.info('Creating job to like %s.', video.url)
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
// Send to origin
|
|
|
|
if (video.isOwned() === false) {
|
2018-05-25 05:32:36 -04:00
|
|
|
const audience = getVideoAudience(video, accountsInvolvedInVideo)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = likeActivityData(url, byActor, video, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
|
|
|
}
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
// Send to followers
|
2017-11-27 08:44:51 -05:00
|
|
|
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = likeActivityData(url, byActor, video, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const followersException = [ byActor ]
|
|
|
|
return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
2018-06-12 14:04:58 -04:00
|
|
|
function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
|
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
type: 'Like' as 'Like',
|
|
|
|
id: url,
|
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-03-27 07:33:56 -04:00
|
|
|
sendLike,
|
2017-11-23 08:19:55 -05:00
|
|
|
likeActivityData
|
|
|
|
}
|