mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Basic video redundancy implementation
This commit is contained in:
parent
a651038487
commit
c48e82b5e0
77 changed files with 1667 additions and 287 deletions
|
@ -3,7 +3,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
|||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
|
||||
import { unicastTo } from './utils'
|
||||
import { followActivityData } from './send-follow'
|
||||
import { buildFollowActivity } from './send-follow'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
|
||||
async function sendAccept (actorFollow: ActorFollowModel) {
|
||||
|
@ -18,10 +18,10 @@ async function sendAccept (actorFollow: ActorFollowModel) {
|
|||
logger.info('Creating job to accept follower %s.', follower.url)
|
||||
|
||||
const followUrl = getActorFollowActivityPubUrl(actorFollow)
|
||||
const followData = followActivityData(followUrl, follower, me)
|
||||
const followData = buildFollowActivity(followUrl, follower, me)
|
||||
|
||||
const url = getActorFollowAcceptActivityPubUrl(actorFollow)
|
||||
const data = acceptActivityData(url, me, followData)
|
||||
const data = buildAcceptActivity(url, me, followData)
|
||||
|
||||
return unicastTo(data, me, follower.inboxUrl)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
|
||||
function buildAcceptActivity (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
|
||||
return {
|
||||
type: 'Accept',
|
||||
id: url,
|
||||
|
|
|
@ -4,45 +4,44 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
|||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoShareModel } from '../../../models/video/video-share'
|
||||
import { broadcastToFollowers } from './utils'
|
||||
import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
|
||||
import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
|
||||
async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
||||
async function buildAnnounceWithVideoAudience (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
||||
const announcedObject = video.url
|
||||
|
||||
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
|
||||
const audience = getObjectFollowersAudience(accountsToForwardView)
|
||||
return announceActivityData(videoShare.url, byActor, announcedObject, audience)
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
|
||||
|
||||
const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
|
||||
|
||||
return { activity, actorsInvolvedInVideo }
|
||||
}
|
||||
|
||||
async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
||||
const data = await buildVideoAnnounce(byActor, videoShare, video, t)
|
||||
const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
|
||||
|
||||
logger.info('Creating job to send announce %s.', videoShare.url)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
const followersException = [ byActor ]
|
||||
|
||||
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
}
|
||||
|
||||
function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
|
||||
function buildAnnounceActivity (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
|
||||
if (!audience) audience = getAudience(byActor)
|
||||
|
||||
return {
|
||||
type: 'Announce',
|
||||
to: audience.to,
|
||||
cc: audience.cc,
|
||||
return audiencify({
|
||||
type: 'Announce' as 'Announce',
|
||||
id: url,
|
||||
actor: byActor.url,
|
||||
object
|
||||
}
|
||||
}, audience)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
sendVideoAnnounce,
|
||||
announceActivityData,
|
||||
buildVideoAnnounce
|
||||
buildAnnounceActivity,
|
||||
buildAnnounceWithVideoAudience
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
getVideoCommentAudience
|
||||
} from '../audience'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
||||
|
||||
async function sendCreateVideo (video: VideoModel, t: Transaction) {
|
||||
if (video.privacy === VideoPrivacy.PRIVATE) return undefined
|
||||
|
@ -27,12 +28,12 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) {
|
|||
const videoObject = video.toActivityPubObject()
|
||||
|
||||
const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
|
||||
const data = createActivityData(video.url, byActor, videoObject, audience)
|
||||
const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience)
|
||||
|
||||
return broadcastToFollowers(data, byActor, [ byActor ], t)
|
||||
return broadcastToFollowers(createActivity, byActor, [ byActor ], t)
|
||||
}
|
||||
|
||||
async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) {
|
||||
async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
|
||||
if (!video.VideoChannel.Account.Actor.serverId) return // Local
|
||||
|
||||
const url = getVideoAbuseActivityPubUrl(videoAbuse)
|
||||
|
@ -40,9 +41,23 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
|
|||
logger.info('Creating job to send video abuse %s.', url)
|
||||
|
||||
const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
|
||||
const data = createActivityData(url, byActor, videoAbuse.toActivityPubObject(), audience)
|
||||
const createActivity = buildCreateActivity(url, byActor, videoAbuse.toActivityPubObject(), audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
async function sendCreateCacheFile (byActor: ActorModel, fileRedundancy: VideoRedundancyModel) {
|
||||
logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
|
||||
|
||||
const redundancyObject = fileRedundancy.toActivityPubObject()
|
||||
|
||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(fileRedundancy.VideoFile.Video.id)
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, undefined)
|
||||
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const createActivity = buildCreateActivity(fileRedundancy.url, byActor, redundancyObject, audience)
|
||||
|
||||
return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
|
||||
|
@ -66,73 +81,73 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio
|
|||
audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
|
||||
}
|
||||
|
||||
const data = createActivityData(comment.url, byActor, commentObject, audience)
|
||||
const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
|
||||
|
||||
// This was a reply, send it to the parent actors
|
||||
const actorsException = [ byActor ]
|
||||
await broadcastToActors(data, byActor, parentsCommentActors, actorsException)
|
||||
await broadcastToActors(createActivity, byActor, parentsCommentActors, actorsException)
|
||||
|
||||
// Broadcast to our followers
|
||||
await broadcastToFollowers(data, byActor, [ byActor ], t)
|
||||
await broadcastToFollowers(createActivity, byActor, [ byActor ], t)
|
||||
|
||||
// Send to actors involved in the comment
|
||||
if (isOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
|
||||
if (isOrigin) return broadcastToFollowers(createActivity, byActor, actorsInvolvedInComment, t, actorsException)
|
||||
|
||||
// Send to origin
|
||||
return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
||||
logger.info('Creating job to send view of %s.', video.url)
|
||||
|
||||
const url = getVideoViewActivityPubUrl(byActor, video)
|
||||
const viewActivityData = createViewActivityData(byActor, video)
|
||||
const viewActivity = buildViewActivity(byActor, video)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
|
||||
// Send to origin
|
||||
if (video.isOwned() === false) {
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const data = createActivityData(url, byActor, viewActivityData, audience)
|
||||
const createActivity = buildCreateActivity(url, byActor, viewActivity, audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// Send to followers
|
||||
const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
|
||||
const data = createActivityData(url, byActor, viewActivityData, audience)
|
||||
const createActivity = buildCreateActivity(url, byActor, viewActivity, audience)
|
||||
|
||||
// Use the server actor to send the view
|
||||
const serverActor = await getServerActor()
|
||||
const actorsException = [ byActor ]
|
||||
return broadcastToFollowers(data, serverActor, actorsInvolvedInVideo, t, actorsException)
|
||||
return broadcastToFollowers(createActivity, serverActor, actorsInvolvedInVideo, t, actorsException)
|
||||
}
|
||||
|
||||
async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
||||
logger.info('Creating job to dislike %s.', video.url)
|
||||
|
||||
const url = getVideoDislikeActivityPubUrl(byActor, video)
|
||||
const dislikeActivityData = createDislikeActivityData(byActor, video)
|
||||
const dislikeActivity = buildDislikeActivity(byActor, video)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
|
||||
// Send to origin
|
||||
if (video.isOwned() === false) {
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const data = createActivityData(url, byActor, dislikeActivityData, audience)
|
||||
const createActivity = buildCreateActivity(url, byActor, dislikeActivity, audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// Send to followers
|
||||
const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
|
||||
const data = createActivityData(url, byActor, dislikeActivityData, audience)
|
||||
const createActivity = buildCreateActivity(url, byActor, dislikeActivity, audience)
|
||||
|
||||
const actorsException = [ byActor ]
|
||||
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException)
|
||||
return broadcastToFollowers(createActivity, byActor, actorsInvolvedInVideo, t, actorsException)
|
||||
}
|
||||
|
||||
function createActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate {
|
||||
function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate {
|
||||
if (!audience) audience = getAudience(byActor)
|
||||
|
||||
return audiencify(
|
||||
|
@ -146,7 +161,7 @@ function createActivityData (url: string, byActor: ActorModel, object: any, audi
|
|||
)
|
||||
}
|
||||
|
||||
function createDislikeActivityData (byActor: ActorModel, video: VideoModel) {
|
||||
function buildDislikeActivity (byActor: ActorModel, video: VideoModel) {
|
||||
return {
|
||||
type: 'Dislike',
|
||||
actor: byActor.url,
|
||||
|
@ -154,7 +169,7 @@ function createDislikeActivityData (byActor: ActorModel, video: VideoModel) {
|
|||
}
|
||||
}
|
||||
|
||||
function createViewActivityData (byActor: ActorModel, video: VideoModel) {
|
||||
function buildViewActivity (byActor: ActorModel, video: VideoModel) {
|
||||
return {
|
||||
type: 'View',
|
||||
actor: byActor.url,
|
||||
|
@ -167,9 +182,10 @@ function createViewActivityData (byActor: ActorModel, video: VideoModel) {
|
|||
export {
|
||||
sendCreateVideo,
|
||||
sendVideoAbuse,
|
||||
createActivityData,
|
||||
buildCreateActivity,
|
||||
sendCreateView,
|
||||
sendCreateDislike,
|
||||
createDislikeActivityData,
|
||||
sendCreateVideoComment
|
||||
buildDislikeActivity,
|
||||
sendCreateVideoComment,
|
||||
sendCreateCacheFile
|
||||
}
|
||||
|
|
|
@ -15,24 +15,23 @@ async function sendDeleteVideo (video: VideoModel, t: Transaction) {
|
|||
const url = getDeleteActivityPubUrl(video.url)
|
||||
const byActor = video.VideoChannel.Account.Actor
|
||||
|
||||
const data = deleteActivityData(url, video.url, byActor)
|
||||
const activity = buildDeleteActivity(url, video.url, byActor)
|
||||
|
||||
const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
|
||||
actorsInvolved.push(byActor)
|
||||
const actorsInvolved = await getActorsInvolvedInVideo(video, t)
|
||||
|
||||
return broadcastToFollowers(data, byActor, actorsInvolved, t)
|
||||
return broadcastToFollowers(activity, byActor, actorsInvolved, t)
|
||||
}
|
||||
|
||||
async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
|
||||
logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
|
||||
|
||||
const url = getDeleteActivityPubUrl(byActor.url)
|
||||
const data = deleteActivityData(url, byActor.url, byActor)
|
||||
const activity = buildDeleteActivity(url, byActor.url, byActor)
|
||||
|
||||
const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
|
||||
actorsInvolved.push(byActor)
|
||||
|
||||
return broadcastToFollowers(data, byActor, actorsInvolved, t)
|
||||
return broadcastToFollowers(activity, byActor, actorsInvolved, t)
|
||||
}
|
||||
|
||||
async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
|
||||
|
@ -45,23 +44,23 @@ async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Trans
|
|||
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
|
||||
|
||||
const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
|
||||
actorsInvolvedInComment.push(byActor)
|
||||
actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
|
||||
|
||||
const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
|
||||
const data = deleteActivityData(url, videoComment.url, byActor, audience)
|
||||
const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
|
||||
|
||||
// This was a reply, send it to the parent actors
|
||||
const actorsException = [ byActor ]
|
||||
await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
|
||||
await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
|
||||
|
||||
// Broadcast to our followers
|
||||
await broadcastToFollowers(data, byActor, [ byActor ], t)
|
||||
await broadcastToFollowers(activity, byActor, [ byActor ], t)
|
||||
|
||||
// Send to actors involved in the comment
|
||||
if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
|
||||
if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException)
|
||||
|
||||
// Send to origin
|
||||
return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -74,7 +73,7 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
|
||||
function buildDeleteActivity (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
|
||||
const activity = {
|
||||
type: 'Delete' as 'Delete',
|
||||
id: url,
|
||||
|
|
|
@ -15,12 +15,12 @@ function sendFollow (actorFollow: ActorFollowModel) {
|
|||
logger.info('Creating job to send follow request to %s.', following.url)
|
||||
|
||||
const url = getActorFollowActivityPubUrl(actorFollow)
|
||||
const data = followActivityData(url, me, following)
|
||||
const data = buildFollowActivity(url, me, following)
|
||||
|
||||
return unicastTo(data, me, following.inboxUrl)
|
||||
}
|
||||
|
||||
function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
|
||||
function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
|
||||
return {
|
||||
type: 'Follow',
|
||||
id: url,
|
||||
|
@ -33,5 +33,5 @@ function followActivityData (url: string, byActor: ActorModel, targetActor: Acto
|
|||
|
||||
export {
|
||||
sendFollow,
|
||||
followActivityData
|
||||
buildFollowActivity
|
||||
}
|
||||
|
|
|
@ -17,20 +17,20 @@ async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction)
|
|||
// Send to origin
|
||||
if (video.isOwned() === false) {
|
||||
const audience = getVideoAudience(video, accountsInvolvedInVideo)
|
||||
const data = likeActivityData(url, byActor, video, audience)
|
||||
const data = buildLikeActivity(url, byActor, video, audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// Send to followers
|
||||
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
||||
const data = likeActivityData(url, byActor, video, audience)
|
||||
const activity = buildLikeActivity(url, byActor, video, audience)
|
||||
|
||||
const followersException = [ byActor ]
|
||||
return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
|
||||
return broadcastToFollowers(activity, byActor, accountsInvolvedInVideo, t, followersException)
|
||||
}
|
||||
|
||||
function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
|
||||
function buildLikeActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
|
||||
if (!audience) audience = getAudience(byActor)
|
||||
|
||||
return audiencify(
|
||||
|
@ -48,5 +48,5 @@ function likeActivityData (url: string, byActor: ActorModel, video: VideoModel,
|
|||
|
||||
export {
|
||||
sendLike,
|
||||
likeActivityData
|
||||
buildLikeActivity
|
||||
}
|
||||
|
|
|
@ -13,12 +13,13 @@ import { VideoModel } from '../../../models/video/video'
|
|||
import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
||||
import { broadcastToFollowers, unicastTo } from './utils'
|
||||
import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
|
||||
import { createActivityData, createDislikeActivityData } from './send-create'
|
||||
import { followActivityData } from './send-follow'
|
||||
import { likeActivityData } from './send-like'
|
||||
import { buildCreateActivity, buildDislikeActivity } from './send-create'
|
||||
import { buildFollowActivity } from './send-follow'
|
||||
import { buildLikeActivity } from './send-like'
|
||||
import { VideoShareModel } from '../../../models/video/video-share'
|
||||
import { buildVideoAnnounce } from './send-announce'
|
||||
import { buildAnnounceWithVideoAudience } from './send-announce'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
||||
|
||||
async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
|
||||
const me = actorFollow.ActorFollower
|
||||
|
@ -32,10 +33,10 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
|
|||
const followUrl = getActorFollowActivityPubUrl(actorFollow)
|
||||
const undoUrl = getUndoActivityPubUrl(followUrl)
|
||||
|
||||
const object = followActivityData(followUrl, me, following)
|
||||
const data = undoActivityData(undoUrl, me, object)
|
||||
const followActivity = buildFollowActivity(followUrl, me, following)
|
||||
const undoActivity = undoActivityData(undoUrl, me, followActivity)
|
||||
|
||||
return unicastTo(data, me, following.inboxUrl)
|
||||
return unicastTo(undoActivity, me, following.inboxUrl)
|
||||
}
|
||||
|
||||
async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
||||
|
@ -45,21 +46,21 @@ async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transact
|
|||
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
const object = likeActivityData(likeUrl, byActor, video)
|
||||
const likeActivity = buildLikeActivity(likeUrl, byActor, video)
|
||||
|
||||
// Send to origin
|
||||
if (video.isOwned() === false) {
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const data = undoActivityData(undoUrl, byActor, object, audience)
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
|
||||
const data = undoActivityData(undoUrl, byActor, object, audience)
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience)
|
||||
|
||||
const followersException = [ byActor ]
|
||||
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
}
|
||||
|
||||
async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
||||
|
@ -69,20 +70,20 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans
|
|||
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
const dislikeActivity = createDislikeActivityData(byActor, video)
|
||||
const object = createActivityData(dislikeUrl, byActor, dislikeActivity)
|
||||
const dislikeActivity = buildDislikeActivity(byActor, video)
|
||||
const createDislikeActivity = buildCreateActivity(dislikeUrl, byActor, dislikeActivity)
|
||||
|
||||
if (video.isOwned() === false) {
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const data = undoActivityData(undoUrl, byActor, object, audience)
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity, audience)
|
||||
|
||||
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
const data = undoActivityData(undoUrl, byActor, object)
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity)
|
||||
|
||||
const followersException = [ byActor ]
|
||||
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
}
|
||||
|
||||
async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
||||
|
@ -90,12 +91,27 @@ async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareMode
|
|||
|
||||
const undoUrl = getUndoActivityPubUrl(videoShare.url)
|
||||
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
const object = await buildVideoAnnounce(byActor, videoShare, video, t)
|
||||
const data = undoActivityData(undoUrl, byActor, object)
|
||||
const { activity: announceActivity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, announceActivity)
|
||||
|
||||
const followersException = [ byActor ]
|
||||
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException)
|
||||
}
|
||||
|
||||
async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) {
|
||||
logger.info('Creating job to undo cache file %s.', redundancyModel.url)
|
||||
|
||||
const undoUrl = getUndoActivityPubUrl(redundancyModel.url)
|
||||
|
||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id)
|
||||
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
||||
|
||||
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
||||
const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject())
|
||||
|
||||
const undoActivity = undoActivityData(undoUrl, byActor, createActivity, audience)
|
||||
|
||||
return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -104,7 +120,8 @@ export {
|
|||
sendUndoFollow,
|
||||
sendUndoLike,
|
||||
sendUndoDislike,
|
||||
sendUndoAnnounce
|
||||
sendUndoAnnounce,
|
||||
sendUndoCacheFile
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -7,11 +7,11 @@ import { VideoModel } from '../../../models/video/video'
|
|||
import { VideoChannelModel } from '../../../models/video/video-channel'
|
||||
import { VideoShareModel } from '../../../models/video/video-share'
|
||||
import { getUpdateActivityPubUrl } from '../url'
|
||||
import { broadcastToFollowers } from './utils'
|
||||
import { audiencify, getAudience } from '../audience'
|
||||
import { broadcastToFollowers, unicastTo } from './utils'
|
||||
import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { videoFeedsValidator } from '../../../middlewares/validators'
|
||||
import { VideoCaptionModel } from '../../../models/video/video-caption'
|
||||
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
||||
|
||||
async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) {
|
||||
logger.info('Creating job to update video %s.', video.url)
|
||||
|
@ -26,12 +26,12 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByAct
|
|||
const videoObject = video.toActivityPubObject()
|
||||
const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
|
||||
|
||||
const data = updateActivityData(url, byActor, videoObject, audience)
|
||||
const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience)
|
||||
|
||||
const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
|
||||
actorsInvolved.push(byActor)
|
||||
const actorsInvolved = await getActorsInvolvedInVideo(video, t)
|
||||
if (overrodeByActor) actorsInvolved.push(overrodeByActor)
|
||||
|
||||
return broadcastToFollowers(data, byActor, actorsInvolved, t)
|
||||
return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t)
|
||||
}
|
||||
|
||||
async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
|
||||
|
@ -42,7 +42,7 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod
|
|||
const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
|
||||
const accountOrChannelObject = accountOrChannel.toActivityPubObject()
|
||||
const audience = getAudience(byActor)
|
||||
const data = updateActivityData(url, byActor, accountOrChannelObject, audience)
|
||||
const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience)
|
||||
|
||||
let actorsInvolved: ActorModel[]
|
||||
if (accountOrChannel instanceof AccountModel) {
|
||||
|
@ -55,19 +55,35 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod
|
|||
|
||||
actorsInvolved.push(byActor)
|
||||
|
||||
return broadcastToFollowers(data, byActor, actorsInvolved, t)
|
||||
return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t)
|
||||
}
|
||||
|
||||
async function sendUpdateCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel) {
|
||||
logger.info('Creating job to update cache file %s.', redundancyModel.url)
|
||||
|
||||
const url = getUpdateActivityPubUrl(redundancyModel.url, redundancyModel.updatedAt.toISOString())
|
||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id)
|
||||
|
||||
const redundancyObject = redundancyModel.toActivityPubObject()
|
||||
|
||||
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, undefined)
|
||||
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
||||
|
||||
const updateActivity = buildUpdateActivity(url, byActor, redundancyObject, audience)
|
||||
return unicastTo(updateActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
sendUpdateActor,
|
||||
sendUpdateVideo
|
||||
sendUpdateVideo,
|
||||
sendUpdateCacheFile
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate {
|
||||
function buildUpdateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate {
|
||||
if (!audience) audience = getAudience(byActor)
|
||||
|
||||
return audiencify(
|
||||
|
|
|
@ -59,11 +59,11 @@ async function forwardActivity (
|
|||
async function broadcastToFollowers (
|
||||
data: any,
|
||||
byActor: ActorModel,
|
||||
toActorFollowers: ActorModel[],
|
||||
toFollowersOf: ActorModel[],
|
||||
t: Transaction,
|
||||
actorsException: ActorModel[] = []
|
||||
) {
|
||||
const uris = await computeFollowerUris(toActorFollowers, actorsException, t)
|
||||
const uris = await computeFollowerUris(toFollowersOf, actorsException, t)
|
||||
return broadcastTo(uris, data, byActor)
|
||||
}
|
||||
|
||||
|
@ -115,8 +115,8 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) {
|
||||
const toActorFollowerIds = toActorFollower.map(a => a.id)
|
||||
async function computeFollowerUris (toFollowersOf: ActorModel[], actorsException: ActorModel[], t: Transaction) {
|
||||
const toActorFollowerIds = toFollowersOf.map(a => a.id)
|
||||
|
||||
const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t)
|
||||
const sharedInboxesException = await buildSharedInboxesException(actorsException)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue