]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/video/video.service.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.service.ts
index ac640c79186fc7ba0c9cc77a84e94023201b068a..49d6fc1c7e5c5abee9e40ddd2c9e109e9c004b53 100644 (file)
@@ -378,8 +378,8 @@ export class VideoService implements VideosProvider {
                )
   }
 
-  explainedPrivacyLabels (privacies: VideoConstant<VideoPrivacy>[], defaultPrivacyId = VideoPrivacy.PUBLIC) {
-    const base = [
+  explainedPrivacyLabels (serverPrivacies: VideoConstant<VideoPrivacy>[], defaultPrivacyId = VideoPrivacy.PUBLIC) {
+    const descriptions = [
       {
         id: VideoPrivacy.PRIVATE,
         description: $localize`Only I can see this video`
@@ -398,16 +398,24 @@ export class VideoService implements VideosProvider {
       }
     ]
 
-    const videoPrivacies = base
-      .filter(o => !!privacies.find(p => p.id === o.id)) // filter down to privacies that where in the input
-      .map(o => ({ ...privacies[o.id - 1], ...o })) // merge the input privacies that contain a label, and extend them with a description
-
     return {
-      defaultPrivacyId: videoPrivacies.find(p => p.id === defaultPrivacyId)?.id || videoPrivacies[0].id,
-      videoPrivacies
+      defaultPrivacyId: serverPrivacies.find(p => p.id === defaultPrivacyId)?.id || serverPrivacies[0].id,
+      videoPrivacies: serverPrivacies.map(p => ({ ...p, description: descriptions.find(p => p.id).description }))
     }
   }
 
+  getHighestAvailablePrivacy (serverPrivacies: VideoConstant<VideoPrivacy>[]) {
+    const order = [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL, VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC ]
+
+    for (const privacy of order) {
+      if (serverPrivacies.find(p => p.id === privacy)) {
+        return privacy
+      }
+    }
+
+    throw new Error('No highest privacy available')
+  }
+
   nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType) {
     return nsfwPolicy === 'do_not_list'
       ? 'false'