import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
import { pageToStartAndCount } from '../../helpers/core-utils'
import { ACTIVITY_PUB, CONFIG } from '../../initializers'
-import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send'
+import { buildVideoAnnounce } from '../../lib/activitypub/send'
import { audiencify, getAudience } from '../../lib/activitypub/send/misc'
import { createActivityData } from '../../lib/activitypub/send/send-create'
import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
const share = res.locals.videoShare as VideoShareModel
- const object = await buildVideoAnnounceToFollowers(share.Actor, share, res.locals.video, undefined)
+ const object = await buildVideoAnnounce(share.Actor, share, res.locals.video, undefined)
return res.json(activityPubContextify(object))
}
VIDEO_PRIVACIES
} from '../../../initializers'
import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
-import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
+import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
import { JobQueue } from '../../../lib/job-queue'
import { Redis } from '../../../lib/redis'
import {
const serverAccount = await getServerActor()
- if (videoInstance.isOwned()) {
- await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
- } else {
- await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
- }
+ await sendCreateView(serverAccount, videoInstance, undefined)
return res.status(204).end()
}
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { logger } from '../../../helpers/logger'
import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers'
-import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub'
+import { sendVideoRateChange } from '../../../lib/activitypub'
import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares'
import { AccountModel } from '../../../models/account/account'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
// It is useful for the user to have a feedback
await videoInstance.increment(incrementQuery, sequelizeOptions)
- if (videoInstance.isOwned()) {
- await sendVideoRateChangeToFollowers(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
- } else {
- await sendVideoRateChangeToOrigin(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
- }
+ await sendVideoRateChange(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
})
logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
export * from './fetch'
export * from './share'
export * from './videos'
+export * from './video-comments'
+export * from './video-rates'
export * from './url'
-export { videoCommentActivityObjectToDBAttributes } from './video-comments'
-export { addVideoComments } from './video-comments'
-export { addVideoComment } from './video-comments'
-export { sendVideoRateChangeToFollowers } from './video-rates'
-export { sendVideoRateChangeToOrigin } from './video-rates'
import { VideoShareModel } from '../../../models/video/video-share'
import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc'
-async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
+async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
const announcedObject = video.url
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
}
-async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
- const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t)
+async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
+ const data = await buildVideoAnnounce(byActor, videoShare, video, t)
return broadcastToFollowers(data, byActor, [ byActor ], t)
}
// ---------------------------------------------------------------------------
export {
- sendVideoAnnounceToFollowers,
+ sendVideoAnnounce,
announceActivityData,
- buildVideoAnnounceToFollowers
+ buildVideoAnnounce
}
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
}
-async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) {
+async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
+ const isOrigin = comment.Video.isOwned()
+
const byActor = comment.Account.Actor
const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
const commentObject = comment.toActivityPubObject(threadParentComments)
const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
actorsInvolvedInComment.push(byActor)
- const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
-
- const data = await createActivityData(comment.url, byActor, commentObject, t, 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)
-
- // Broadcast to our followers
- await broadcastToFollowers(data, byActor, [ byActor ], t)
- // Send to origin
- return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
+ const parentsCommentActors = threadParentComments.map(c => c.Account.Actor)
-async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) {
- const byActor = comment.Account.Actor
- const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
- const commentObject = comment.toActivityPubObject(threadParentComments)
-
- const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
- actorsInvolvedInComment.push(byActor)
+ let audience: ActivityAudience
+ if (isOrigin) {
+ audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
+ } else {
+ audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
+ }
- const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, true)
const data = await createActivityData(comment.url, byActor, commentObject, t, 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(data, byActor, parentsCommentActors, actorsException)
// Broadcast to our followers
await broadcastToFollowers(data, byActor, [ byActor ], t)
// Send to actors involved in the comment
- return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
+ if (isOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
+
+ // Send to origin
+ return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
}
-async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
const url = getVideoViewActivityPubUrl(byActor, video)
const viewActivityData = createViewActivityData(byActor, video)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
- const data = await createActivityData(url, byActor, viewActivityData, t, audience)
- return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
+ const data = await createActivityData(url, byActor, viewActivityData, t, audience)
-async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
- const url = getVideoViewActivityPubUrl(byActor, video)
- const viewActivityData = createViewActivityData(byActor, video)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
- const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
- const audience = getObjectFollowersAudience(actorsToForwardView)
+ // Send to followers
+ const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const data = await createActivityData(url, byActor, viewActivityData, t, audience)
// Use the server actor to send the view
const serverActor = await getServerActor()
const actorsException = [ byActor ]
- return broadcastToFollowers(data, serverActor, actorsToForwardView, t, actorsException)
+ return broadcastToFollowers(data, serverActor, actorsInvolvedInVideo, t, actorsException)
}
-async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
const url = getVideoDislikeActivityPubUrl(byActor, video)
const dislikeActivityData = createDislikeActivityData(byActor, video)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
- const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
- return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
+ const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
-async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
- const url = getVideoDislikeActivityPubUrl(byActor, video)
- const dislikeActivityData = createDislikeActivityData(byActor, video)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
- const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
- const audience = getObjectFollowersAudience(actorsToForwardView)
+ // Send to followers
+ const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
const actorsException = [ byActor ]
- return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException)
+ return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException)
}
-async function createActivityData (
- url: string,
- byActor: ActorModel,
- object: any,
- t: Transaction,
- audience?: ActivityAudience
-): Promise<ActivityCreate> {
+async function createActivityData (url: string,
+ byActor: ActorModel,
+ object: any,
+ t: Transaction,
+ audience?: ActivityAudience): Promise<ActivityCreate> {
if (!audience) {
audience = await getAudience(byActor, t)
}
sendCreateVideo,
sendVideoAbuse,
createActivityData,
- sendCreateViewToOrigin,
- sendCreateViewToVideoFollowers,
- sendCreateDislikeToOrigin,
- sendCreateDislikeToVideoFollowers,
+ sendCreateView,
+ sendCreateDislike,
createDislikeActivityData,
- sendCreateVideoCommentToOrigin,
- sendCreateVideoCommentToVideoFollowers
+ sendCreateVideoComment
}
unicastTo
} from './misc'
-async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
const url = getVideoLikeActivityPubUrl(byActor, video)
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
- const data = await likeActivityData(url, byActor, video, t, audience)
- return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
+ const data = await likeActivityData(url, byActor, video, t, audience)
-async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
- const url = getVideoLikeActivityPubUrl(byActor, video)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
- const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
+ // Send to followers
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
const data = await likeActivityData(url, byActor, video, t, audience)
// ---------------------------------------------------------------------------
export {
- sendLikeToOrigin,
- sendLikeToVideoFollowers,
+ sendLike,
likeActivityData
}
return unicastTo(data, me, following.inboxUrl)
}
-async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
const undoUrl = getUndoActivityPubUrl(likeUrl)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
const object = await likeActivityData(likeUrl, byActor, video, t)
- const data = await undoActivityData(undoUrl, byActor, object, t, audience)
- return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
+ const data = await undoActivityData(undoUrl, byActor, object, t, audience)
-async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
- const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
- const undoUrl = getUndoActivityPubUrl(likeUrl)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
- const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
- const audience = getObjectFollowersAudience(toActorsFollowers)
- const object = await likeActivityData(likeUrl, byActor, video, t)
+ const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const data = await undoActivityData(undoUrl, byActor, object, t, audience)
const followersException = [ byActor ]
- return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException)
+ return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
}
-async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
const dislikeActivity = createDislikeActivityData(byActor, video)
const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
- const data = await undoActivityData(undoUrl, byActor, object, t, audience)
-
- return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
-
-async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
- const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
- const undoUrl = getUndoActivityPubUrl(dislikeUrl)
+ if (video.isOwned() === false) {
+ const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
+ const data = await undoActivityData(undoUrl, byActor, object, t, audience)
- const dislikeActivity = createDislikeActivityData(byActor, video)
- const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
+ return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ }
const data = await undoActivityData(undoUrl, byActor, object, t)
- const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
-
const followersException = [ byActor ]
- return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException)
+ return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
}
// ---------------------------------------------------------------------------
export {
sendUndoFollow,
- sendUndoLikeToOrigin,
- sendUndoLikeToVideoFollowers,
- sendUndoDislikeToOrigin,
- sendUndoDislikeToVideoFollowers
+ sendUndoLike,
+ sendUndoDislike
}
// ---------------------------------------------------------------------------
import { getServerActor } from '../../helpers/utils'
import { VideoModel } from '../../models/video/video'
import { VideoShareModel } from '../../models/video/video-share'
-import { sendVideoAnnounceToFollowers } from './send'
+import { sendVideoAnnounce } from './send'
import { getAnnounceActivityPubUrl } from './url'
async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
},
transaction: t
}).then(([ serverShare, created ]) => {
- if (created) return sendVideoAnnounceToFollowers(serverActor, serverShare, video, t)
+ if (created) return sendVideoAnnounce(serverActor, serverShare, video, t)
return undefined
})
},
transaction: t
}).then(([ videoChannelShare, created ]) => {
- if (created) return sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t)
+ if (created) return sendVideoAnnounce(serverActor, videoChannelShare, video, t)
return undefined
})
import { Transaction } from 'sequelize'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
-import {
- sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, sendLikeToOrigin, sendLikeToVideoFollowers, sendUndoDislikeToOrigin,
- sendUndoDislikeToVideoFollowers, sendUndoLikeToOrigin, sendUndoLikeToVideoFollowers
-} from './send'
+import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
-async function sendVideoRateChangeToFollowers (account: AccountModel,
- video: VideoModel,
- likes: number,
- dislikes: number,
- t: Transaction) {
+async function sendVideoRateChange (account: AccountModel,
+ video: VideoModel,
+ likes: number,
+ dislikes: number,
+ t: Transaction) {
const actor = account.Actor
// Keep the order: first we undo and then we create
// Undo Like
- if (likes < 0) await sendUndoLikeToVideoFollowers(actor, video, t)
+ if (likes < 0) await sendUndoLike(actor, video, t)
// Undo Dislike
- if (dislikes < 0) await sendUndoDislikeToVideoFollowers(actor, video, t)
+ if (dislikes < 0) await sendUndoDislike(actor, video, t)
// Like
- if (likes > 0) await sendLikeToVideoFollowers(actor, video, t)
+ if (likes > 0) await sendLike(actor, video, t)
// Dislike
- if (dislikes > 0) await sendCreateDislikeToVideoFollowers(actor, video, t)
-}
-
-async function sendVideoRateChangeToOrigin (account: AccountModel,
- video: VideoModel,
- likes: number,
- dislikes: number,
- t: Transaction) {
- const actor = account.Actor
-
- // Keep the order: first we undo and then we create
-
- // Undo Like
- if (likes < 0) await sendUndoLikeToOrigin(actor, video, t)
- // Undo Dislike
- if (dislikes < 0) await sendUndoDislikeToOrigin(actor, video, t)
-
- // Like
- if (likes > 0) await sendLikeToOrigin(actor, video, t)
- // Dislike
- if (dislikes > 0) await sendCreateDislikeToOrigin(actor, video, t)
+ if (dislikes > 0) await sendCreateDislike(actor, video, t)
}
export {
- sendVideoRateChangeToFollowers,
- sendVideoRateChangeToOrigin
+ sendVideoRateChange
}
import { VideoModel } from '../models/video/video'
import { VideoCommentModel } from '../models/video/video-comment'
import { getVideoCommentActivityPubUrl } from './activitypub'
-import { sendCreateVideoCommentToOrigin, sendCreateVideoCommentToVideoFollowers } from './activitypub/send'
+import { sendCreateVideoComment } from './activitypub/send'
async function createVideoComment (obj: {
text: string,
savedComment.Video = obj.video
savedComment.Account = obj.account
- if (savedComment.Video.isOwned()) {
- await sendCreateVideoCommentToVideoFollowers(savedComment, t)
- } else {
- await sendCreateVideoCommentToOrigin(savedComment, t)
- }
+ await sendCreateVideoComment(savedComment, t)
return savedComment
}