]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/context.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / context.ts
index 3bc40e2aa2749114f9786d0b40a76948776bfd03..a3ca52a31569227246b5eff8816e474bc751eab9 100644 (file)
@@ -1,7 +1,8 @@
 import { ContextType } from '@shared/models'
+import { Hooks } from '../plugins/hooks'
 
-function activityPubContextify <T> (data: T, type: ContextType) {
-  return { ...getContextData(type), ...data }
+async function activityPubContextify <T> (data: T, type: ContextType) {
+  return { ...await getContextData(type), ...data }
 }
 
 // ---------------------------------------------------------------------------
@@ -15,7 +16,7 @@ export {
 
 type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
 
-const contextStore = {
+const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
   Video: buildContext({
     Hashtag: 'as:Hashtag',
     uuid: 'sc:identifier',
@@ -24,6 +25,7 @@ const contextStore = {
     subtitleLanguage: 'sc:subtitleLanguage',
     sensitive: 'as:sensitive',
     language: 'sc:inLanguage',
+    identifier: 'sc:identifier',
 
     // TODO: remove in a few versions, introduced in 4.2
     icons: 'as:icon',
@@ -109,7 +111,8 @@ const contextStore = {
     stopTimestamp: {
       '@type': 'sc:Number',
       '@id': 'pt:stopTimestamp'
-    }
+    },
+    uuid: 'sc:identifier'
   }),
 
   CacheFile: buildContext({
@@ -125,9 +128,34 @@ const contextStore = {
     playlists: {
       '@id': 'pt:playlists',
       '@type': '@id'
-    }
+    },
+    support: {
+      '@type': 'sc:Text',
+      '@id': 'pt:support'
+    },
+
+    // TODO: remove in a few versions, introduced in 4.2
+    icons: 'as:icon'
+  }),
+
+  WatchAction: buildContext({
+    WatchAction: 'sc:WatchAction',
+    startTimestamp: {
+      '@type': 'sc:Number',
+      '@id': 'pt:startTimestamp'
+    },
+    stopTimestamp: {
+      '@type': 'sc:Number',
+      '@id': 'pt:stopTimestamp'
+    },
+    watchSection: {
+      '@type': 'sc:Number',
+      '@id': 'pt:stopTimestamp'
+    },
+    uuid: 'sc:identifier'
   }),
 
+  Collection: buildContext(),
   Follow: buildContext(),
   Reject: buildContext(),
   Accept: buildContext(),
@@ -138,10 +166,13 @@ const contextStore = {
   Rate: buildContext()
 }
 
-function getContextData (type: ContextType) {
-  return {
-    '@context': contextStore[type]
-  }
+async function getContextData (type: ContextType) {
+  const contextData = await Hooks.wrapObject(
+    contextStore[type],
+    'filter:activity-pub.activity.context.build.result'
+  )
+
+  return { '@context': contextData }
 }
 
 function buildContext (contextValue?: ContextValue) {
@@ -160,7 +191,7 @@ function buildContext (contextValue?: ContextValue) {
 
     {
       pt: 'https://joinpeertube.org/ns#',
-      sc: 'http://schema.org#',
+      sc: 'http://schema.org/',
 
       ...contextValue
     }