From 07f81d9deedf4921b8518c2d2b16043167b4c5d5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 19 Feb 2021 13:47:37 +0100 Subject: Fix NSFW policy on account/channel videos --- .../account-search/account-search.component.ts | 19 ++++++++++--------- .../account-videos/account-videos.component.ts | 18 ++++++++++-------- .../video-channel-videos.component.ts | 20 +++++++++++--------- .../video-list/trending/video-trending.component.ts | 2 +- .../app/+videos/video-list/video-local.component.ts | 2 +- .../video-list/video-recently-added.component.ts | 2 +- .../shared-video-miniature/abstract-video-list.ts | 16 ++++++++++------ 7 files changed, 44 insertions(+), 35 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+accounts/account-search/account-search.component.ts b/client/src/app/+accounts/account-search/account-search.component.ts index 378aa78c4..dda4bf0c7 100644 --- a/client/src/app/+accounts/account-search/account-search.component.ts +++ b/client/src/app/+accounts/account-search/account-search.component.ts @@ -1,4 +1,4 @@ -import { Subscription } from 'rxjs' +import { forkJoin, Subscription } from 'rxjs' import { first, tap } from 'rxjs/operators' import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' @@ -16,6 +16,7 @@ import { VideoFilter } from '@shared/models' export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { titlePage: string loadOnInit = false + loadUserVideoPreferences = true search = '' filter: VideoFilter = null @@ -46,14 +47,14 @@ export class AccountSearchComponent extends AbstractVideoList implements OnInit, this.enableAllFilterIfPossible() // Parent get the account for us - this.accountSub = this.accountService.accountLoaded - .pipe(first()) - .subscribe(account => { - this.account = account - - this.reloadVideos() - this.generateSyndicationList() - }) + this.accountSub = forkJoin([ + this.accountService.accountLoaded.pipe(first()), + this.onUserLoadedSubject.pipe(first()) + ]).subscribe(([ account ]) => { + this.account = account + + this.reloadVideos() + }) } ngOnDestroy () { diff --git a/client/src/app/+accounts/account-videos/account-videos.component.ts b/client/src/app/+accounts/account-videos/account-videos.component.ts index da3903d2c..484d60e25 100644 --- a/client/src/app/+accounts/account-videos/account-videos.component.ts +++ b/client/src/app/+accounts/account-videos/account-videos.component.ts @@ -1,4 +1,4 @@ -import { Subscription } from 'rxjs' +import { forkJoin, Subscription } from 'rxjs' import { first, tap } from 'rxjs/operators' import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' @@ -18,6 +18,7 @@ import { VideoFilter } from '@shared/models' export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { titlePage: string loadOnInit = false + loadUserVideoPreferences = true filter: VideoFilter = null @@ -47,14 +48,15 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, this.enableAllFilterIfPossible() // Parent get the account for us - this.accountSub = this.accountService.accountLoaded - .pipe(first()) - .subscribe(account => { - this.account = account + this.accountSub = forkJoin([ + this.accountService.accountLoaded.pipe(first()), + this.onUserLoadedSubject.pipe(first()) + ]).subscribe(([ account ]) => { + this.account = account - this.reloadVideos() - this.generateSyndicationList() - }) + this.reloadVideos() + this.generateSyndicationList() + }) } ngOnDestroy () { diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts index a49fd0d5d..803651505 100644 --- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts +++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts @@ -1,4 +1,4 @@ -import { Subscription } from 'rxjs' +import { forkJoin, Subscription } from 'rxjs' import { first, tap } from 'rxjs/operators' import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' @@ -18,6 +18,7 @@ import { VideoFilter } from '@shared/models' export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { titlePage: string loadOnInit = false + loadUserVideoPreferences = true filter: VideoFilter = null @@ -53,14 +54,15 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On this.enableAllFilterIfPossible() // Parent get the video channel for us - this.videoChannelSub = this.videoChannelService.videoChannelLoaded - .pipe(first()) - .subscribe(videoChannel => { - this.videoChannel = videoChannel - - this.reloadVideos() - this.generateSyndicationList() - }) + this.videoChannelSub = forkJoin([ + this.videoChannelService.videoChannelLoaded.pipe(first()), + this.onUserLoadedSubject.pipe(first()) + ]).subscribe(([ videoChannel ]) => { + this.videoChannel = videoChannel + + this.reloadVideos() + this.generateSyndicationList() + }) } ngOnDestroy () { diff --git a/client/src/app/+videos/video-list/trending/video-trending.component.ts b/client/src/app/+videos/video-list/trending/video-trending.component.ts index 6128c4acd..c11f0da9d 100644 --- a/client/src/app/+videos/video-list/trending/video-trending.component.ts +++ b/client/src/app/+videos/video-list/trending/video-trending.component.ts @@ -19,7 +19,7 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, titlePage: string defaultSort: VideoSortField = '-trending' - useUserVideoPreferences = true + loadUserVideoPreferences = true private algorithmChangeSub: Subscription diff --git a/client/src/app/+videos/video-list/video-local.component.ts b/client/src/app/+videos/video-list/video-local.component.ts index af7eecff4..4be8cd6b5 100644 --- a/client/src/app/+videos/video-list/video-local.component.ts +++ b/client/src/app/+videos/video-list/video-local.component.ts @@ -17,7 +17,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On sort = '-publishedAt' as VideoSortField filter: VideoFilter = 'local' - useUserVideoPreferences = true + loadUserVideoPreferences = true constructor ( protected router: Router, diff --git a/client/src/app/+videos/video-list/video-recently-added.component.ts b/client/src/app/+videos/video-list/video-recently-added.component.ts index 2f4908074..506f92d25 100644 --- a/client/src/app/+videos/video-list/video-recently-added.component.ts +++ b/client/src/app/+videos/video-list/video-recently-added.component.ts @@ -17,7 +17,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On sort: VideoSortField = '-publishedAt' groupByDate = true - useUserVideoPreferences = true + loadUserVideoPreferences = true constructor ( protected route: ActivatedRoute, diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts index 5361f6d6c..f8abc1656 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts @@ -1,4 +1,4 @@ -import { fromEvent, Observable, Subject, Subscription } from 'rxjs' +import { fromEvent, Observable, ReplaySubject, Subject, Subscription } from 'rxjs' import { debounceTime, switchMap, tap } from 'rxjs/operators' import { AfterContentInit, @@ -63,7 +63,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte syndicationItems: Syndication[] = [] loadOnInit = true - useUserVideoPreferences = false + loadUserVideoPreferences = false + ownerDisplayType: OwnerDisplayType = 'account' displayModerationBlock = false titleTooltip: string @@ -98,6 +99,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte userMiniature: User + protected onUserLoadedSubject = new ReplaySubject(1) + protected serverConfig: ServerConfig protected abstract notifier: Notifier @@ -149,10 +152,11 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte this.calcPageSizes() const loadUserObservable = this.loadUserAndSettings() + loadUserObservable.subscribe(() => { + this.onUserLoadedSubject.next() - if (this.loadOnInit === true) { - loadUserObservable.subscribe(() => this.loadMoreVideos()) - } + if (this.loadOnInit === true) this.loadMoreVideos() + }) this.userService.listenAnonymousUpdate() .pipe(switchMap(() => this.loadUserAndSettings())) @@ -374,7 +378,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte .pipe(tap(user => { this.userMiniature = user - if (!this.useUserVideoPreferences) return + if (!this.loadUserVideoPreferences) return this.languageOneOf = user.videoLanguages this.nsfwPolicy = user.nsfwPolicy -- cgit v1.2.3