2017-11-20 03:43:39 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityCreate } from '../../../../shared/models/activitypub/activity'
|
2017-11-23 08:19:55 -05:00
|
|
|
import { getServerAccount } from '../../../helpers/utils'
|
2017-11-20 03:43:39 -05:00
|
|
|
import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
|
|
|
|
import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface'
|
2017-11-23 08:19:55 -05:00
|
|
|
import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
|
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
|
|
|
getAccountsToForwardVideoAction,
|
|
|
|
getAudience,
|
|
|
|
getOriginVideoAudience,
|
|
|
|
getVideoFollowersAudience,
|
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
2017-11-20 03:43:39 -05:00
|
|
|
|
|
|
|
async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
|
|
|
const byAccount = videoChannel.Account
|
|
|
|
|
|
|
|
const videoChannelObject = videoChannel.toActivityPubObject()
|
|
|
|
const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject)
|
|
|
|
|
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoAbuseActivityPubUrl(videoAbuse)
|
2017-11-22 10:25:03 -05:00
|
|
|
|
|
|
|
const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
|
|
|
|
const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience)
|
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoViewActivityPubUrl(byAccount, video)
|
|
|
|
const viewActivity = createViewActivityData(byAccount, video)
|
|
|
|
|
2017-11-23 08:19:55 -05:00
|
|
|
const audience = getOriginVideoAudience(video)
|
2017-11-22 10:25:03 -05:00
|
|
|
const data = await createActivityData(url, byAccount, viewActivity, audience)
|
2017-11-20 03:43:39 -05:00
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:25:03 -05:00
|
|
|
async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoViewActivityPubUrl(byAccount, video)
|
|
|
|
const viewActivity = createViewActivityData(byAccount, video)
|
|
|
|
|
2017-11-23 08:19:55 -05:00
|
|
|
const audience = getVideoFollowersAudience(video)
|
2017-11-22 10:25:03 -05:00
|
|
|
const data = await createActivityData(url, byAccount, viewActivity, audience)
|
|
|
|
|
|
|
|
const serverAccount = await getServerAccount()
|
2017-11-23 08:19:55 -05:00
|
|
|
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
|
|
|
|
|
|
|
|
const followersException = [ byAccount ]
|
|
|
|
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
|
|
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
|
|
|
|
|
|
|
const audience = getOriginVideoAudience(video)
|
|
|
|
const data = await createActivityData(url, byAccount, dislikeActivity, audience)
|
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
2017-11-22 10:25:03 -05:00
|
|
|
|
2017-11-23 08:19:55 -05:00
|
|
|
async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
|
|
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
|
|
|
|
|
|
|
const audience = getVideoFollowersAudience(video)
|
|
|
|
const data = await createActivityData(url, byAccount, dislikeActivity, audience)
|
|
|
|
|
|
|
|
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
|
|
|
|
const serverAccount = await getServerAccount()
|
2017-11-22 10:25:03 -05:00
|
|
|
|
|
|
|
const followersException = [ byAccount ]
|
|
|
|
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: { to: string[], cc: string[] }) {
|
|
|
|
if (!audience) {
|
|
|
|
audience = await getAudience(byAccount)
|
|
|
|
}
|
2017-11-22 04:29:55 -05:00
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
const activity: ActivityCreate = {
|
|
|
|
type: 'Create',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
2017-11-22 10:25:03 -05:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
2017-11-20 03:43:39 -05:00
|
|
|
object
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
2017-11-23 08:19:55 -05:00
|
|
|
function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) {
|
|
|
|
const obj = {
|
|
|
|
type: 'Dislike',
|
|
|
|
actor: byAccount.url,
|
|
|
|
object: video.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendCreateVideoChannel,
|
|
|
|
sendVideoAbuse,
|
2017-11-22 10:25:03 -05:00
|
|
|
createActivityData,
|
|
|
|
sendCreateViewToOrigin,
|
2017-11-23 08:19:55 -05:00
|
|
|
sendCreateViewToVideoFollowers,
|
|
|
|
sendCreateDislikeToOrigin,
|
|
|
|
sendCreateDislikeToVideoFollowers,
|
|
|
|
createDislikeActivityData
|
2017-11-22 10:25:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) {
|
|
|
|
const obj = {
|
|
|
|
type: 'View',
|
|
|
|
actor: byAccount.url,
|
|
|
|
object: video.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|