1
0
Fork 0

Fix live update of autoplay next video

This commit is contained in:
Chocobozzz 2023-02-15 11:32:08 +01:00
parent e81d45b4cb
commit 6a7cea1527
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 22 additions and 10 deletions

View 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"
>

View 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)
}

View 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