]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-like.ts
Add concept of video state, and add ability to wait transcoding before
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-like.ts
index a7fcec21c37dd924697eae155b23f0ded568bfe5..f1642f038ec6865b2b0cddbb815ec3234bb9018f 100644 (file)
@@ -1,11 +1,12 @@
 import { ActivityLike } from '../../../../shared/models/activitypub'
-import { retryTransactionWrapper } from '../../../helpers'
+import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { sequelizeTypescript } from '../../../initializers'
 import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
 import { ActorModel } from '../../../models/activitypub/actor'
-import { VideoModel } from '../../../models/video/video'
 import { getOrCreateActorAndServerAndModel } from '../actor'
-import { forwardActivity } from '../send/misc'
+import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
+import { getOrCreateAccountAndVideoAndChannel } from '../videos'
+import { getActorsInvolvedInVideo } from '../audience'
 
 async function processLikeActivity (activity: ActivityLike) {
   const actor = await getOrCreateActorAndServerAndModel(activity.actor)
@@ -30,17 +31,15 @@ async function processLikeVideo (actor: ActorModel, activity: ActivityLike) {
   return retryTransactionWrapper(createVideoLike, options)
 }
 
-function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
+async function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
   const videoUrl = activity.object
 
   const byAccount = byActor.Account
   if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url)
 
-  return sequelizeTypescript.transaction(async t => {
-    const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl)
-
-    if (!video) throw new Error('Unknown video ' + videoUrl)
+  const { video } = await getOrCreateAccountAndVideoAndChannel(videoUrl)
 
+  return sequelizeTypescript.transaction(async t => {
     const rate = {
       type: 'like' as 'like',
       videoId: video.id,
@@ -56,7 +55,8 @@ function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
     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)
     }
   })
 }