]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-create.ts
Fix dependency errors between modules
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-create.ts
index ceb5413ca6d153b889305502e949ac74adfdeecb..9a72cb899b56c7c3fb6f3fb6bebc937643827c60 100644 (file)
@@ -9,9 +9,12 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoAbuseModel } from '../../../models/video/video-abuse'
 import { addVideoComment, resolveThread } from '../video-comments'
 import { getOrCreateVideoAndAccountAndChannel } from '../videos'
-import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
+import { forwardVideoRelatedActivity } from '../send/utils'
 import { Redis } from '../../redis'
-import { createCacheFile } from '../cache-file'
+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
@@ -65,9 +68,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
       videoId: video.id,
       accountId: byAccount.id
     }
+
     const [ , created ] = await AccountVideoRateModel.findOrCreate({
       where: rate,
-      defaults: rate,
+      defaults: immutableAssign(rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
       transaction: t
     })
     if (created === true) await video.increment('dislikes', { transaction: t })
@@ -84,19 +88,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
 async function processCreateView (byActor: ActorModel, activity: ActivityCreate) {
   const view = activity.object as ViewObject
 
-  const options = {
-    videoObject: view.object,
-    fetchType: 'only-video' as 'only-video'
-  }
-  const { video } = await getOrCreateVideoAndAccountAndChannel(options)
+  const video = await VideoModel.loadByUrl(view.object)
+  if (!video || video.isOwned() === false) return
 
   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) {
@@ -105,7 +100,7 @@ async function processCacheFile (byActor: ActorModel, activity: ActivityCreate)
   const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
 
   await sequelizeTypescript.transaction(async t => {
-    return createCacheFile(cacheFile, video, byActor, t)
+    return createOrUpdateCacheFile(cacheFile, video, byActor, t)
   })
 
   if (video.isOwned()) {