Try to refractor activities sending
authorChocobozzz <me@florianbigard.com>
Tue, 27 Mar 2018 11:33:56 +0000 (13:33 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 27 Mar 2018 11:33:56 +0000 (13:33 +0200)
There is still a need for work on this part though

server/controllers/activitypub/client.ts
server/controllers/api/videos/index.ts
server/controllers/api/videos/rate.ts
server/lib/activitypub/index.ts
server/lib/activitypub/send/send-announce.ts
server/lib/activitypub/send/send-create.ts
server/lib/activitypub/send/send-like.ts
server/lib/activitypub/send/send-undo.ts
server/lib/activitypub/share.ts
server/lib/activitypub/video-rates.ts
server/lib/video-comment.ts

index 3470798165e1a6c9e8ba51ab22c31d24d1c41e41..8e295b4f97470bb14bf0cacea1bf531d21bf36e4 100644 (file)
@@ -4,7 +4,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
 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'
@@ -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) {
   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))
 }
index 690872320056d3751fe5a4797091e657810aba4f..552e5edac74c08223a07feb3a3394f5ff4af6713 100644 (file)
@@ -20,7 +20,7 @@ import {
   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 {
@@ -365,11 +365,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
 
   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()
 }
index a7bd570eb71f9c22e979a500783e17efca157c16..23e9de9f3577f5686dd52964082d085dd426083d 100644 (file)
@@ -3,7 +3,7 @@ import { UserVideoRateUpdate } from '../../../../shared'
 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'
@@ -83,11 +83,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
     // 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)
index 0779d1e911b49f661f5b8fa958e0dbe63cab072f..88064c6b6d7fd0b40154805e0dab4485b0de158f 100644 (file)
@@ -4,9 +4,6 @@ export * from './actor'
 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'
index ed551a2b25bd865822f84ffcf8e252221f38ea3f..4179c9d43ee4c4c1a42468adf6e0ca250b587ec1 100644 (file)
@@ -5,7 +5,7 @@ import { VideoModel } from '../../../models/video/video'
 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)
@@ -13,8 +13,8 @@ async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: V
   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)
 }
@@ -43,7 +43,7 @@ async function announceActivityData (
 // ---------------------------------------------------------------------------
 
 export {
-  sendVideoAnnounceToFollowers,
+  sendVideoAnnounce,
   announceActivityData,
-  buildVideoAnnounceToFollowers
+  buildVideoAnnounce
 }
index d73dd8d249eb74a59fc1d2aa261c0b5e66e97c3e..4ff20b0334ad408aef6249b76c05938f07f1652e 100644 (file)
@@ -40,105 +40,92 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
   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)
   }
@@ -173,11 +160,8 @@ export {
   sendCreateVideo,
   sendVideoAbuse,
   createActivityData,
-  sendCreateViewToOrigin,
-  sendCreateViewToVideoFollowers,
-  sendCreateDislikeToOrigin,
-  sendCreateDislikeToVideoFollowers,
+  sendCreateView,
+  sendCreateDislike,
   createDislikeActivityData,
-  sendCreateVideoCommentToOrigin,
-  sendCreateVideoCommentToVideoFollowers
+  sendCreateVideoComment
 }
index b01249e69028386e60149a1806cbf48cc8541e39..fb2b4aaf87132f356af319c6930a4887b2da0cf3 100644 (file)
@@ -13,20 +13,20 @@ import {
   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)
 
@@ -56,7 +56,6 @@ async function likeActivityData (
 // ---------------------------------------------------------------------------
 
 export {
-  sendLikeToOrigin,
-  sendLikeToVideoFollowers,
+  sendLike,
   likeActivityData
 }
index 41a500384c0c92ba61dd0166848ce2850d60e34e..bd49d452e4e229b877767063557757531520c075 100644 (file)
@@ -30,68 +30,55 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
   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
 }
 
 // ---------------------------------------------------------------------------
index 038f19b7dadc5bd416b65f8445e7b589e8ed93b1..f256f8d21fca772d4c04bfab439e07bfaacde459 100644 (file)
@@ -3,7 +3,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
 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) {
@@ -23,7 +23,7 @@ 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
   })
@@ -40,7 +40,7 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction)
     },
     transaction: t
   }).then(([ videoChannelShare, created ]) => {
-    if (created) return sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t)
+    if (created) return sendVideoAnnounce(serverActor, videoChannelShare, video, t)
 
     return undefined
   })
index 1b2958cca0417e6ac36f796df455fcdb6fd3a08f..19011b4ab835efb47a10515dcdc2d5ad4887846d 100644 (file)
@@ -1,52 +1,28 @@
 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
 }
index 0d744c526ee74da49a7cc32cfe104857cc8c9bf3..f88e5cfdf9474f8b035614104a716afac2fcd0f5 100644 (file)
@@ -5,7 +5,7 @@ import { AccountModel } from '../models/account/account'
 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,
@@ -37,11 +37,7 @@ async function createVideoComment (obj: {
   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
 }