]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix live update of autoplay next video
authorChocobozzz <me@florianbigard.com>
Wed, 15 Feb 2023 10:32:08 +0000 (11:32 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 15 Feb 2023 10:32:08 +0000 (11:32 +0100)
client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.html
client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts
client/src/app/core/users/user-local-storage.service.ts

index 5ac801622078c94c2acbd7850caa32873fcc03ae..2bbe26c96db0e6cc2eb93f570396226c55ac5c53 100644 (file)
@@ -14,7 +14,7 @@
     <ng-container *ngFor="let video of (videos$ | async); let i = index; let length = count">
       <span i18n *ngIf="!playlist && i === 0 && length !== 0 && autoPlayNextVideo" class="title-page-next-video-label">Next video to be played</span>
       <my-video-miniature
-        [displayOptions]="displayOptions" [video]="video" [user]="userMiniature" [displayAsRow]="displayAsRow"
+        [displayOptions]="displayOptions" [video]="video" [user]="user" [displayAsRow]="displayAsRow"
         (videoBlocked)="onVideoRemoved()" (videoRemoved)="onVideoRemoved()" (videoAccountMuted)="onVideoRemoved()"
         actorImageSize="32"
       >
index 97f742499c6bab7a2d1989d8f7ae881c673afc51..426f5d62271888f1066f6a3e36ee92c1ca6dedbc 100644 (file)
@@ -1,5 +1,5 @@
-import { Observable } from 'rxjs'
-import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
+import { Observable, startWith, Subscription, switchMap } from 'rxjs'
+import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output } from '@angular/core'
 import { AuthService, Notifier, User, UserService } from '@app/core'
 import { Video } from '@app/shared/shared-main'
 import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
@@ -12,7 +12,7 @@ import { RecommendedVideosStore } from './recommended-videos.store'
   templateUrl: './recommended-videos.component.html',
   styleUrls: [ './recommended-videos.component.scss' ]
 })
-export class RecommendedVideosComponent implements OnInit, OnChanges {
+export class RecommendedVideosComponent implements OnInit, OnChanges, OnDestroy {
   @Input() inputRecommendation: RecommendationInfo
   @Input() playlist: VideoPlaylist
   @Input() displayAsRow: boolean
@@ -29,7 +29,9 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
     avatar: true
   }
 
-  userMiniature: User
+  user: User
+
+  private userSub: Subscription
 
   readonly hasVideos$: Observable<boolean>
   readonly videos$: Observable<Video[]>
@@ -44,15 +46,20 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
     this.hasVideos$ = this.store.hasRecommendations$
     this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
 
-    this.userService.getAnonymousOrLoggedUser()
-      .subscribe(user => this.autoPlayNextVideo = user.autoPlayNextVideo)
-
     this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.`
   }
 
   ngOnInit () {
-    this.userService.getAnonymousOrLoggedUser()
-      .subscribe(user => this.userMiniature = user)
+    this.userSub = this.userService.listenAnonymousUpdate()
+      .pipe(
+        startWith(true),
+        switchMap(() => this.userService.getAnonymousOrLoggedUser())
+      )
+      .subscribe(user => {
+        this.user = user
+        this.autoPlayNextVideo = user.autoPlayNextVideo
+        console.log(this.autoPlayNextVideo)
+      })
   }
 
   ngOnChanges () {
@@ -61,6 +68,10 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
     }
   }
 
+  ngOnDestroy(): void {
+    if (this.userSub) this.userSub.unsubscribe()
+  }
+
   onVideoRemoved () {
     this.store.requestNewRecommendations(this.inputRecommendation)
   }
index d5fd1e447db675ccb1b1cc157fda280190db7f16..1e629249a692e3b54d589732d274fffd318d15ea 100644 (file)
@@ -168,6 +168,7 @@ export class UserLocalStorageService {
       UserLocalStorageKeys.NSFW_POLICY,
       UserLocalStorageKeys.P2P_ENABLED,
       UserLocalStorageKeys.AUTO_PLAY_VIDEO,
+      UserLocalStorageKeys.AUTO_PLAY_NEXT_VIDEO,
       UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST,
       UserLocalStorageKeys.THEME,
       UserLocalStorageKeys.VIDEO_LANGUAGES