]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Handle mastodon shares
authorChocobozzz <me@florianbigard.com>
Tue, 19 Dec 2017 16:07:58 +0000 (17:07 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 19 Dec 2017 16:07:58 +0000 (17:07 +0100)
server/helpers/custom-validators/activitypub/announce.ts
server/lib/activitypub/process/process-announce.ts
shared/models/activitypub/activity.ts

index 80511129c3e89145472a84b08c9b21cd336e6e6e..469ed5127ecc53276576daa5b40fde9b7ab568ca 100644 (file)
@@ -1,9 +1,11 @@
-import { isBaseActivityValid } from './misc'
+import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
 import { isVideoTorrentCreateActivityValid } from './videos'
 
 function isAnnounceActivityValid (activity: any) {
+  console.log(activity)
   return isBaseActivityValid(activity, 'Announce') &&
     (
+      isActivityPubUrlValid(activity.object) ||
       isVideoTorrentCreateActivityValid(activity.object)
     )
 }
index 7dfee2f60a4868daad94d4ef50b35fe1adbffb49..5568ff538d21ae7f9e290d6627fe6c09ca33da8d 100644 (file)
@@ -1,4 +1,4 @@
-import { ActivityAnnounce } from '../../../../shared/models/activitypub'
+import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub'
 import { logger, retryTransactionWrapper } from '../../../helpers'
 import { sequelizeTypescript } from '../../../initializers'
 import { ActorModel } from '../../../models/activitypub/actor'
@@ -12,7 +12,9 @@ async function processAnnounceActivity (activity: ActivityAnnounce) {
   const announcedActivity = activity.object
   const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor)
 
-  if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') {
+  if (typeof announcedActivity === 'string') {
+    return processVideoShare(actorAnnouncer, activity)
+  } else if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') {
     return processVideoShare(actorAnnouncer, activity)
   }
 
@@ -35,18 +37,25 @@ export {
 function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
   const options = {
     arguments: [ actorAnnouncer, activity ],
-    errorMessage: 'Cannot share the video with many retries.'
+    errorMessage: 'Cannot share the video activity with many retries.'
   }
 
   return retryTransactionWrapper(shareVideo, options)
 }
 
 function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
-  const announcedActivity = activity.object
+  const announced = activity.object
 
   return sequelizeTypescript.transaction(async t => {
     // Add share entry
-    const video: VideoModel = await processCreateActivity(announcedActivity)
+    let video: VideoModel
+
+    if (typeof announced === 'string') {
+      video = await VideoModel.loadByUrlAndPopulateAccount(announced as string)
+      if (!video) throw new Error('Unknown video to share ' + announced)
+    } else {
+      video = await processCreateActivity(announced as ActivityCreate)
+    }
 
     const share = {
       actorId: actorAnnouncer.id,
index 84f5d851f7445489af4a1147c7656d02bec4b15e..d5359eba183229bdbf5df841a72be50b596c6461 100644 (file)
@@ -51,7 +51,7 @@ export interface ActivityAccept extends BaseActivity {
 
 export interface ActivityAnnounce extends BaseActivity {
   type: 'Announce'
-  object: ActivityCreate
+  object: ActivityCreate | string
 }
 
 export interface ActivityUndo extends BaseActivity {