]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix current video time saving for anonymous users
authorChocobozzz <me@florianbigard.com>
Wed, 1 Mar 2023 09:48:21 +0000 (10:48 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 1 Mar 2023 09:48:21 +0000 (10:48 +0100)
client/src/assets/player/shared/peertube/peertube-plugin.ts

index b5f177f3050b7afd7a61f84006cc443ab4360fc0..da9b3bd0ea2553b1be3c9a9864cfd672a0332a5d 100644 (file)
@@ -207,26 +207,20 @@ class PeerTubePlugin extends Plugin {
         .catch(err => logger.error('Cannot notify user is watching.', err))
 
       lastViewEvent = undefined
-
-      // Server won't save history, so save the video position in local storage
-      if (!this.authorizationHeader()) {
-        saveVideoWatchHistory(this.videoUUID, currentTime)
-      }
     }, this.videoViewIntervalMs)
   }
 
   private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
-    if (!this.videoViewUrl) return Promise.resolve(undefined)
-
-    const body: VideoView = {
-      currentTime,
-      viewEvent
+    // Server won't save history, so save the video position in local storage
+    if (!this.authorizationHeader()) {
+      saveVideoWatchHistory(this.videoUUID, currentTime)
     }
 
-    const headers = new Headers({
-      'Content-type': 'application/json; charset=UTF-8'
-    })
+    if (!this.videoViewUrl) return
+
+    const body: VideoView = { currentTime, viewEvent }
 
+    const headers = new Headers({ 'Content-type': 'application/json; charset=UTF-8' })
     if (this.authorizationHeader()) headers.set('Authorization', this.authorizationHeader())
 
     return fetch(this.videoViewUrl, { method: 'POST', body: JSON.stringify(body), headers })