]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-create.ts
Add local user subscriptions
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-create.ts
index ee180b765d8338e584a0d684bf583250014e7244..791148919f2958c2e1a6e9528543cbb478d2962d 100644 (file)
@@ -1,4 +1,4 @@
-import { ActivityCreate, VideoTorrentObject } from '../../../../shared'
+import { ActivityCreate, VideoAbuseState, VideoTorrentObject } from '../../../../shared'
 import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects'
 import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
@@ -9,9 +9,9 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoAbuseModel } from '../../../models/video/video-abuse'
 import { VideoCommentModel } from '../../../models/video/video-comment'
 import { getOrCreateActorAndServerAndModel } from '../actor'
-import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc'
 import { resolveThread } from '../video-comments'
 import { getOrCreateAccountAndVideoAndChannel } from '../videos'
+import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
 
 async function processCreateActivity (activity: ActivityCreate) {
   const activityObject = activity.object
@@ -21,13 +21,13 @@ async function processCreateActivity (activity: ActivityCreate) {
   if (activityType === 'View') {
     return processCreateView(actor, activity)
   } else if (activityType === 'Dislike') {
-    return processCreateDislike(actor, activity)
+    return retryTransactionWrapper(processCreateDislike, actor, activity)
   } else if (activityType === 'Video') {
     return processCreateVideo(actor, activity)
   } else if (activityType === 'Flag') {
-    return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject)
+    return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject)
   } else if (activityType === 'Note') {
-    return processCreateVideoComment(actor, activity)
+    return retryTransactionWrapper(processCreateVideoComment, actor, activity)
   }
 
   logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
@@ -54,15 +54,6 @@ async function processCreateVideo (
 }
 
 async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) {
-  const options = {
-    arguments: [ byActor, activity ],
-    errorMessage: 'Cannot dislike the video with many retries.'
-  }
-
-  return retryTransactionWrapper(createVideoDislike, options)
-}
-
-async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate) {
   const dislike = activity.object as DislikeObject
   const byAccount = byActor.Account
 
@@ -86,7 +77,8 @@ async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate
     if (video.isOwned() && created === true) {
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]
-      await forwardActivity(activity, t, exceptions)
+
+      await forwardVideoRelatedActivity(activity, t, exceptions, video)
     }
   })
 }
@@ -108,16 +100,7 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate)
   }
 }
 
-function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
-  const options = {
-    arguments: [ actor, videoAbuseToCreateData ],
-    errorMessage: 'Cannot insert the remote video abuse with many retries.'
-  }
-
-  return retryTransactionWrapper(addRemoteVideoAbuse, options)
-}
-
-async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
+async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
   logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
 
   const account = actor.Account
@@ -129,7 +112,8 @@ async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: V
     const videoAbuseData = {
       reporterAccountId: account.id,
       reason: videoAbuseToCreateData.content,
-      videoId: video.id
+      videoId: video.id,
+      state: VideoAbuseState.PENDING
     }
 
     await VideoAbuseModel.create(videoAbuseData)
@@ -138,16 +122,7 @@ async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: V
   })
 }
 
-function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) {
-  const options = {
-    arguments: [ byActor, activity ],
-    errorMessage: 'Cannot create video comment with many retries.'
-  }
-
-  return retryTransactionWrapper(createVideoComment, options)
-}
-
-async function createVideoComment (byActor: ActorModel, activity: ActivityCreate) {
+async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) {
   const comment = activity.object as VideoCommentObject
   const byAccount = byActor.Account
 
@@ -189,11 +164,7 @@ async function createVideoComment (byActor: ActorModel, activity: ActivityCreate
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]
 
-      // Mastodon does not add our announces in audience, so we forward to them manually
-      const additionalActors = await getActorsInvolvedInVideo(video, t)
-      const additionalFollowerUrls = additionalActors.map(a => a.followersUrl)
-
-      await forwardActivity(activity, t, exceptions, additionalFollowerUrls)
+      await forwardVideoRelatedActivity(activity, t, exceptions, video)
     }
   })
 }