]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-create.ts
Merge branch 'move-utils-to-shared' of https://github.com/buoyantair/PeerTube into...
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-create.ts
index 9a72cb899b56c7c3fb6f3fb6bebc937643827c60..df05ee452d318a6be78a0deb04946a00f2f796de 100644 (file)
@@ -12,9 +12,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos'
 import { forwardVideoRelatedActivity } from '../send/utils'
 import { Redis } from '../../redis'
 import { createOrUpdateCacheFile } from '../cache-file'
-import { immutableAssign } from '../../../../shared/utils'
 import { getVideoDislikeActivityPubUrl } from '../url'
-import { VideoModel } from '../../../models/video/video'
 
 async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
   const activityObject = activity.object
@@ -71,7 +69,7 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
 
     const [ , created ] = await AccountVideoRateModel.findOrCreate({
       where: rate,
-      defaults: immutableAssign(rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
+      defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
       transaction: t
     })
     if (created === true) await video.increment('dislikes', { transaction: t })
@@ -88,10 +86,19 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
 async function processCreateView (byActor: ActorModel, activity: ActivityCreate) {
   const view = activity.object as ViewObject
 
-  const video = await VideoModel.loadByUrl(view.object)
-  if (!video || video.isOwned() === false) return
+  const options = {
+    videoObject: view.object,
+    fetchType: 'only-video' as 'only-video'
+  }
+  const { video } = await getOrCreateVideoAndAccountAndChannel(options)
 
   await Redis.Instance.addVideoView(video.id)
+
+  if (video.isOwned()) {
+    // Don't resend the activity to the sender
+    const exceptions = [ byActor ]
+    await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+  }
 }
 
 async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) {