2017-11-23 07:19:55 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityLike } from '../../../../shared/models/activitypub/activity'
|
|
|
|
import { AccountInstance, VideoInstance } from '../../../models'
|
|
|
|
import { getVideoLikeActivityPubUrl } from '../url'
|
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
2017-11-24 06:41:10 -06:00
|
|
|
getAccountsInvolvedInVideo,
|
2017-11-23 07:19:55 -06:00
|
|
|
getAudience,
|
|
|
|
getOriginVideoAudience,
|
2017-11-27 07:44:51 -06:00
|
|
|
getObjectFollowersAudience,
|
2017-11-23 07:19:55 -06:00
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
|
|
|
|
|
|
|
async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
|
|
|
|
2017-11-24 06:41:10 -06:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
2017-11-23 07:19:55 -06:00
|
|
|
const data = await likeActivityData(url, byAccount, video, audience)
|
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
|
|
|
|
2017-11-24 06:41:10 -06:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
2017-11-27 07:44:51 -06:00
|
|
|
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
2017-11-23 07:19:55 -06:00
|
|
|
const data = await likeActivityData(url, byAccount, video, audience)
|
|
|
|
|
2017-11-24 06:41:10 -06:00
|
|
|
const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
|
|
|
const followersException = [ byAccount ]
|
2017-11-24 06:41:10 -06:00
|
|
|
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function likeActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, audience?: { to: string[], cc: string[] }) {
|
|
|
|
if (!audience) {
|
|
|
|
audience = await getAudience(byAccount)
|
|
|
|
}
|
|
|
|
|
|
|
|
const activity: ActivityLike = {
|
|
|
|
type: 'Like',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
|
|
|
object: video.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendLikeToOrigin,
|
|
|
|
sendLikeToVideoFollowers,
|
|
|
|
likeActivityData
|
|
|
|
}
|