]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/activitypub.ts
Avoids easy cheating on vidoe views
[github/Chocobozzz/PeerTube.git] / server / helpers / activitypub.ts
index 43907b596be51fc4055c099e8dee486010e188a4..d64a6dd78fd6bb849e92952415303ff591756a3a 100644 (file)
@@ -1,7 +1,7 @@
 import { ResultList } from '../../shared/models'
 import { Activity } from '../../shared/models/activitypub'
 import { ACTIVITY_PUB } from '../initializers'
-import { AccountModel } from '../models/account/account'
+import { ActorModel } from '../models/activitypub/actor'
 import { signObject } from './peertube-crypto'
 
 function activityPubContextify <T> (data: T) {
@@ -10,22 +10,43 @@ function activityPubContextify <T> (data: T) {
       'https://www.w3.org/ns/activitystreams',
       'https://w3id.org/security/v1',
       {
+        'RsaSignature2017': 'https://w3id.org/security#RsaSignature2017',
         'Hashtag': 'as:Hashtag',
         'uuid': 'http://schema.org/identifier',
         'category': 'http://schema.org/category',
         'licence': 'http://schema.org/license',
-        'nsfw': 'as:sensitive',
+        'sensitive': 'as:sensitive',
         'language': 'http://schema.org/inLanguage',
         'views': 'http://schema.org/Number',
         'size': 'http://schema.org/Number',
-        'VideoChannel': 'https://peertu.be/ns/VideoChannel'
+        'commentsEnabled': 'http://schema.org/Boolean',
+        'support': 'http://schema.org/Text'
+      },
+      {
+        likes: {
+          '@id': 'as:likes',
+          '@type': '@id'
+        },
+        dislikes: {
+          '@id': 'as:dislikes',
+          '@type': '@id'
+        },
+        shares: {
+          '@id': 'as:shares',
+          '@type': '@id'
+        },
+        comments: {
+          '@id': 'as:comments',
+          '@type': '@id'
+        }
       }
     ]
   })
 }
 
-function activityPubCollection (results: any[]) {
+function activityPubCollection (url: string, results: any[]) {
   return {
+    id: url,
     type: 'OrderedCollection',
     totalItems: results.length,
     orderedItems: results
@@ -71,10 +92,10 @@ function activityPubCollectionPagination (url: string, page: any, result: Result
   return orderedCollectionPagination
 }
 
-function buildSignedActivity (byAccount: AccountModel, data: Object) {
+function buildSignedActivity (byActor: ActorModel, data: Object) {
   const activity = activityPubContextify(data)
 
-  return signObject(byAccount, activity) as Promise<Activity>
+  return signObject(byActor, activity) as Promise<Activity>
 }
 
 // ---------------------------------------------------------------------------