Try to refractor activities sending

There is still a need for work on this part though
This commit is contained in:
Chocobozzz 2018-03-27 13:33:56 +02:00
parent da99ccf268
commit 07197db4c5
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 100 additions and 169 deletions

View File

@ -4,7 +4,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
import { pageToStartAndCount } from '../../helpers/core-utils' import { pageToStartAndCount } from '../../helpers/core-utils'
import { ACTIVITY_PUB, CONFIG } from '../../initializers' 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 { audiencify, getAudience } from '../../lib/activitypub/send/misc'
import { createActivityData } from '../../lib/activitypub/send/send-create' import { createActivityData } from '../../lib/activitypub/send/send-create'
import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
@ -130,7 +130,7 @@ async function videoController (req: express.Request, res: express.Response, nex
async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
const share = res.locals.videoShare as VideoShareModel 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)) return res.json(activityPubContextify(object))
} }

View File

@ -20,7 +20,7 @@ import {
VIDEO_PRIVACIES VIDEO_PRIVACIES
} from '../../../initializers' } from '../../../initializers'
import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 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 { JobQueue } from '../../../lib/job-queue'
import { Redis } from '../../../lib/redis' import { Redis } from '../../../lib/redis'
import { import {
@ -365,11 +365,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
const serverAccount = await getServerActor() const serverAccount = await getServerActor()
if (videoInstance.isOwned()) { await sendCreateView(serverAccount, videoInstance, undefined)
await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
} else {
await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
}
return res.status(204).end() return res.status(204).end()
} }

View File

@ -3,7 +3,7 @@ import { UserVideoRateUpdate } from '../../../../shared'
import { retryTransactionWrapper } from '../../../helpers/database-utils' import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' 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 { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares'
import { AccountModel } from '../../../models/account/account' import { AccountModel } from '../../../models/account/account'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate' import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
@ -83,11 +83,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
// It is useful for the user to have a feedback // It is useful for the user to have a feedback
await videoInstance.increment(incrementQuery, sequelizeOptions) await videoInstance.increment(incrementQuery, sequelizeOptions)
if (videoInstance.isOwned()) { await sendVideoRateChange(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
await sendVideoRateChangeToFollowers(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
} else {
await sendVideoRateChangeToOrigin(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
}
}) })
logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)

View File

@ -4,9 +4,6 @@ export * from './actor'
export * from './fetch' export * from './fetch'
export * from './share' export * from './share'
export * from './videos' export * from './videos'
export * from './video-comments'
export * from './video-rates'
export * from './url' 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'

View File

@ -5,7 +5,7 @@ import { VideoModel } from '../../../models/video/video'
import { VideoShareModel } from '../../../models/video/video-share' import { VideoShareModel } from '../../../models/video/video-share'
import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc' 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 announcedObject = video.url
const accountsToForwardView = await getActorsInvolvedInVideo(video, t) const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
@ -13,8 +13,8 @@ async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: V
return announceActivityData(videoShare.url, byActor, announcedObject, t, audience) return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
} }
async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t) const data = await buildVideoAnnounce(byActor, videoShare, video, t)
return broadcastToFollowers(data, byActor, [ byActor ], t) return broadcastToFollowers(data, byActor, [ byActor ], t)
} }
@ -43,7 +43,7 @@ async function announceActivityData (
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
sendVideoAnnounceToFollowers, sendVideoAnnounce,
announceActivityData, announceActivityData,
buildVideoAnnounceToFollowers buildVideoAnnounce
} }

View File

@ -40,29 +40,9 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
} }
async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
const byActor = comment.Account.Actor const isOrigin = comment.Video.isOwned()
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)
}
async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) {
const byActor = comment.Account.Actor const byActor = comment.Account.Actor
const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
const commentObject = comment.toActivityPubObject(threadParentComments) const commentObject = comment.toActivityPubObject(threadParentComments)
@ -70,75 +50,82 @@ async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentMode
const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t) const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
actorsInvolvedInComment.push(byActor) actorsInvolvedInComment.push(byActor)
const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, true) const parentsCommentActors = threadParentComments.map(c => c.Account.Actor)
let audience: ActivityAudience
if (isOrigin) {
audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
} else {
audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
}
const data = await createActivityData(comment.url, byActor, commentObject, t, audience) const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
// This was a reply, send it to the parent actors // This was a reply, send it to the parent actors
const actorsException = [ byActor ] const actorsException = [ byActor ]
await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException) await broadcastToActors(data, byActor, parentsCommentActors, actorsException)
// Broadcast to our followers // Broadcast to our followers
await broadcastToFollowers(data, byActor, [ byActor ], t) await broadcastToFollowers(data, byActor, [ byActor ], t)
// Send to actors involved in the comment // 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 url = getVideoViewActivityPubUrl(byActor, video)
const viewActivityData = createViewActivityData(byActor, video) const viewActivityData = createViewActivityData(byActor, video)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 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) { return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
const url = getVideoViewActivityPubUrl(byActor, video) }
const viewActivityData = createViewActivityData(byActor, video)
const actorsToForwardView = await getActorsInvolvedInVideo(video, t) // Send to followers
const audience = getObjectFollowersAudience(actorsToForwardView) const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const data = await createActivityData(url, byActor, viewActivityData, t, audience) const data = await createActivityData(url, byActor, viewActivityData, t, audience)
// Use the server actor to send the view // Use the server actor to send the view
const serverActor = await getServerActor() const serverActor = await getServerActor()
const actorsException = [ byActor ] 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 url = getVideoDislikeActivityPubUrl(byActor, video)
const dislikeActivityData = createDislikeActivityData(byActor, video) const dislikeActivityData = createDislikeActivityData(byActor, video)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 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) { return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
const url = getVideoDislikeActivityPubUrl(byActor, video) }
const dislikeActivityData = createDislikeActivityData(byActor, video)
const actorsToForwardView = await getActorsInvolvedInVideo(video, t) // Send to followers
const audience = getObjectFollowersAudience(actorsToForwardView) const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
const actorsException = [ byActor ] const actorsException = [ byActor ]
return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException) return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException)
} }
async function createActivityData ( async function createActivityData (url: string,
url: string, byActor: ActorModel,
byActor: ActorModel, object: any,
object: any, t: Transaction,
t: Transaction, audience?: ActivityAudience): Promise<ActivityCreate> {
audience?: ActivityAudience
): Promise<ActivityCreate> {
if (!audience) { if (!audience) {
audience = await getAudience(byActor, t) audience = await getAudience(byActor, t)
} }
@ -173,11 +160,8 @@ export {
sendCreateVideo, sendCreateVideo,
sendVideoAbuse, sendVideoAbuse,
createActivityData, createActivityData,
sendCreateViewToOrigin, sendCreateView,
sendCreateViewToVideoFollowers, sendCreateDislike,
sendCreateDislikeToOrigin,
sendCreateDislikeToVideoFollowers,
createDislikeActivityData, createDislikeActivityData,
sendCreateVideoCommentToOrigin, sendCreateVideoComment
sendCreateVideoCommentToVideoFollowers
} }

View File

@ -13,20 +13,20 @@ import {
unicastTo unicastTo
} from './misc' } 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 url = getVideoLikeActivityPubUrl(byActor, video)
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 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) { return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
const url = getVideoLikeActivityPubUrl(byActor, video) }
const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) // Send to followers
const audience = getObjectFollowersAudience(accountsInvolvedInVideo) const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
const data = await likeActivityData(url, byActor, video, t, audience) const data = await likeActivityData(url, byActor, video, t, audience)
@ -56,7 +56,6 @@ async function likeActivityData (
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
sendLikeToOrigin, sendLike,
sendLikeToVideoFollowers,
likeActivityData likeActivityData
} }

View File

@ -30,68 +30,55 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
return unicastTo(data, me, following.inboxUrl) 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 likeUrl = getVideoLikeActivityPubUrl(byActor, video)
const undoUrl = getUndoActivityPubUrl(likeUrl) const undoUrl = getUndoActivityPubUrl(likeUrl)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
const object = await likeActivityData(likeUrl, byActor, video, t) 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) { return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
const likeUrl = getVideoLikeActivityPubUrl(byActor, video) }
const undoUrl = getUndoActivityPubUrl(likeUrl)
const toActorsFollowers = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
const audience = getObjectFollowersAudience(toActorsFollowers)
const object = await likeActivityData(likeUrl, byActor, video, t)
const data = await undoActivityData(undoUrl, byActor, object, t, audience) const data = await undoActivityData(undoUrl, byActor, object, t, audience)
const followersException = [ byActor ] 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 dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
const undoUrl = getUndoActivityPubUrl(dislikeUrl) const undoUrl = getUndoActivityPubUrl(dislikeUrl)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
const dislikeActivity = createDislikeActivityData(byActor, video) const dislikeActivity = createDislikeActivityData(byActor, video)
const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
const data = await undoActivityData(undoUrl, byActor, object, t, audience) if (video.isOwned() === false) {
const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
const data = await undoActivityData(undoUrl, byActor, object, t, audience)
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 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)
const dislikeActivity = createDislikeActivityData(byActor, video)
const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
const data = await undoActivityData(undoUrl, byActor, object, t) const data = await undoActivityData(undoUrl, byActor, object, t)
const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
const followersException = [ byActor ] const followersException = [ byActor ]
return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
sendUndoFollow, sendUndoFollow,
sendUndoLikeToOrigin, sendUndoLike,
sendUndoLikeToVideoFollowers, sendUndoDislike
sendUndoDislikeToOrigin,
sendUndoDislikeToVideoFollowers
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
import { getServerActor } from '../../helpers/utils' import { getServerActor } from '../../helpers/utils'
import { VideoModel } from '../../models/video/video' import { VideoModel } from '../../models/video/video'
import { VideoShareModel } from '../../models/video/video-share' import { VideoShareModel } from '../../models/video/video-share'
import { sendVideoAnnounceToFollowers } from './send' import { sendVideoAnnounce } from './send'
import { getAnnounceActivityPubUrl } from './url' import { getAnnounceActivityPubUrl } from './url'
async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
@ -23,7 +23,7 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction)
}, },
transaction: t transaction: t
}).then(([ serverShare, created ]) => { }).then(([ serverShare, created ]) => {
if (created) return sendVideoAnnounceToFollowers(serverActor, serverShare, video, t) if (created) return sendVideoAnnounce(serverActor, serverShare, video, t)
return undefined return undefined
}) })
@ -40,7 +40,7 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction)
}, },
transaction: t transaction: t
}).then(([ videoChannelShare, created ]) => { }).then(([ videoChannelShare, created ]) => {
if (created) return sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t) if (created) return sendVideoAnnounce(serverActor, videoChannelShare, video, t)
return undefined return undefined
}) })

View File

@ -1,52 +1,28 @@
import { Transaction } from 'sequelize' import { Transaction } from 'sequelize'
import { AccountModel } from '../../models/account/account' import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video' import { VideoModel } from '../../models/video/video'
import { import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, sendLikeToOrigin, sendLikeToVideoFollowers, sendUndoDislikeToOrigin,
sendUndoDislikeToVideoFollowers, sendUndoLikeToOrigin, sendUndoLikeToVideoFollowers
} from './send'
async function sendVideoRateChangeToFollowers (account: AccountModel, async function sendVideoRateChange (account: AccountModel,
video: VideoModel, video: VideoModel,
likes: number, likes: number,
dislikes: number, dislikes: number,
t: Transaction) { t: Transaction) {
const actor = account.Actor const actor = account.Actor
// Keep the order: first we undo and then we create // Keep the order: first we undo and then we create
// Undo Like // Undo Like
if (likes < 0) await sendUndoLikeToVideoFollowers(actor, video, t) if (likes < 0) await sendUndoLike(actor, video, t)
// Undo Dislike // Undo Dislike
if (dislikes < 0) await sendUndoDislikeToVideoFollowers(actor, video, t) if (dislikes < 0) await sendUndoDislike(actor, video, t)
// Like // Like
if (likes > 0) await sendLikeToVideoFollowers(actor, video, t) if (likes > 0) await sendLike(actor, video, t)
// Dislike // Dislike
if (dislikes > 0) await sendCreateDislikeToVideoFollowers(actor, video, t) if (dislikes > 0) await sendCreateDislike(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)
} }
export { export {
sendVideoRateChangeToFollowers, sendVideoRateChange
sendVideoRateChangeToOrigin
} }

View File

@ -5,7 +5,7 @@ import { AccountModel } from '../models/account/account'
import { VideoModel } from '../models/video/video' import { VideoModel } from '../models/video/video'
import { VideoCommentModel } from '../models/video/video-comment' import { VideoCommentModel } from '../models/video/video-comment'
import { getVideoCommentActivityPubUrl } from './activitypub' import { getVideoCommentActivityPubUrl } from './activitypub'
import { sendCreateVideoCommentToOrigin, sendCreateVideoCommentToVideoFollowers } from './activitypub/send' import { sendCreateVideoComment } from './activitypub/send'
async function createVideoComment (obj: { async function createVideoComment (obj: {
text: string, text: string,
@ -37,11 +37,7 @@ async function createVideoComment (obj: {
savedComment.Video = obj.video savedComment.Video = obj.video
savedComment.Account = obj.account savedComment.Account = obj.account
if (savedComment.Video.isOwned()) { await sendCreateVideoComment(savedComment, t)
await sendCreateVideoCommentToVideoFollowers(savedComment, t)
} else {
await sendCreateVideoCommentToOrigin(savedComment, t)
}
return savedComment return savedComment
} }