From 5c20a45518c3afc40c9494cad4a78def92e5e288 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Jun 2020 11:00:35 +0200 Subject: Fix anonymous nsfw policy --- .../videos/+video-watch/video-watch.component.html | 8 +-- .../recent-videos-recommendation.service.ts | 58 +++++++++++++--------- .../recommended-videos.component.html | 6 +-- .../recommended-videos.component.ts | 26 ++++++---- .../app/videos/video-list/video-local.component.ts | 3 +- .../video-list/video-most-liked.component.ts | 3 +- .../video-list/video-overview.component.html | 6 +-- .../videos/video-list/video-overview.component.ts | 25 ++++++---- .../video-list/video-recently-added.component.ts | 3 +- .../videos/video-list/video-trending.component.ts | 3 +- 10 files changed, 82 insertions(+), 59 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.html index 589aba603..89e696fe9 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html @@ -248,10 +248,10 @@ diff --git a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts index f06c35f9a..0abf938b7 100644 --- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts +++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts @@ -1,15 +1,15 @@ -import { Injectable, OnInit } from '@angular/core' -import { RecommendationService } from '@app/videos/recommendations/recommendations.service' -import { Video } from '@app/shared/video/video.model' -import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' -import { VideoService } from '@app/shared/video/video.service' -import { map, switchMap } from 'rxjs/operators' import { Observable, of } from 'rxjs' -import { SearchService } from '@app/search/search.service' -import { AdvancedSearch } from '@app/search/advanced-search.model' +import { map, switchMap } from 'rxjs/operators' +import { Injectable } from '@angular/core' import { ServerService } from '@app/core' +import { AdvancedSearch } from '@app/search/advanced-search.model' +import { SearchService } from '@app/search/search.service' +import { UserService } from '@app/shared' +import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' +import { Video } from '@app/shared/video/video.model' +import { VideoService } from '@app/shared/video/video.service' +import { RecommendationService } from '@app/videos/recommendations/recommendations.service' import { ServerConfig } from '@shared/models' -import { truncate } from 'lodash' /** * Provides "recommendations" by providing the most recently uploaded videos. @@ -23,13 +23,14 @@ export class RecentVideosRecommendationService implements RecommendationService constructor ( private videos: VideoService, private searchService: SearchService, + private userService: UserService, private serverService: ServerService ) { this.config = this.serverService.getTmpConfig() this.serverService.getConfig() .subscribe(config => this.config = config) - } + } getRecommendations (recommendation: RecommendationInfo): Observable { return this.fetchPage(1, recommendation) @@ -55,20 +56,29 @@ export class RecentVideosRecommendationService implements RecommendationService return defaultSubscription } - const params = { - search: '', - componentPagination: pagination, - advancedSearch: new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt', searchTarget: 'local' }) - } - - return this.searchService.searchVideos(params) - .pipe( - map(v => v.data), - switchMap(videos => { - if (videos.length <= 1) return defaultSubscription + return this.userService.getAnonymousOrLoggedUser() + .pipe( + map(user => { + return { + search: '', + componentPagination: pagination, + advancedSearch: new AdvancedSearch({ + tagsOneOf: recommendation.tags.join(','), + sort: '-createdAt', + searchTarget: 'local', + nsfw: user.nsfwPolicy + ? this.videos.nsfwPolicyToParam(user.nsfwPolicy) + : undefined + }) + } + }), + switchMap(params => this.searchService.searchVideos(params)), + map(v => v.data), + switchMap(videos => { + if (videos.length <= 1) return defaultSubscription - return of(videos) - }) - ) + return of(videos) + }) + ) } } diff --git a/client/src/app/videos/recommendations/recommended-videos.component.html b/client/src/app/videos/recommendations/recommended-videos.component.html index 17e19c083..0467cabf5 100644 --- a/client/src/app/videos/recommendations/recommended-videos.component.html +++ b/client/src/app/videos/recommendations/recommended-videos.component.html @@ -13,11 +13,11 @@ - - +
diff --git a/client/src/app/videos/recommendations/recommended-videos.component.ts b/client/src/app/videos/recommendations/recommended-videos.component.ts index d4a5df19a..a6f3bce3d 100644 --- a/client/src/app/videos/recommendations/recommended-videos.component.ts +++ b/client/src/app/videos/recommendations/recommended-videos.component.ts @@ -1,24 +1,23 @@ -import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core' import { Observable } from 'rxjs' -import { Video } from '@app/shared/video/video.model' +import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' +import { AuthService, Notifier } from '@app/core' +import { User } from '@app/shared' +import { SessionStorageService } from '@app/shared/misc/storage.service' +import { UserService } from '@app/shared/users/user.service' import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' +import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' +import { Video } from '@app/shared/video/video.model' import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' -import { User } from '@app/shared' -import { AuthService, Notifier } from '@app/core' -import { UserService } from '@app/shared/users/user.service' import { I18n } from '@ngx-translate/i18n-polyfill' -import { SessionStorageService } from '@app/shared/misc/storage.service' -import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' @Component({ selector: 'my-recommended-videos', templateUrl: './recommended-videos.component.html', styleUrls: [ './recommended-videos.component.scss' ] }) -export class RecommendedVideosComponent implements OnChanges { +export class RecommendedVideosComponent implements OnInit, OnChanges { @Input() inputRecommendation: RecommendationInfo - @Input() user: User @Input() playlist: VideoPlaylist @Output() gotRecommendations = new EventEmitter() @@ -32,6 +31,8 @@ export class RecommendedVideosComponent implements OnChanges { avatar: true } + userMiniature: User + readonly hasVideos$: Observable readonly videos$: Observable @@ -59,7 +60,12 @@ export class RecommendedVideosComponent implements OnChanges { this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.') } - public ngOnChanges (): void { + ngOnInit () { + this.userService.getAnonymousOrLoggedUser() + .subscribe(user => this.userMiniature = user) + } + + ngOnChanges () { if (this.inputRecommendation) { this.store.requestNewRecommendations(this.inputRecommendation) } 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 757b0e498..960523cd7 100644 --- a/client/src/app/videos/video-list/video-local.component.ts +++ b/client/src/app/videos/video-list/video-local.component.ts @@ -24,7 +24,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On sort = '-publishedAt' as VideoSortField filter: VideoFilter = 'local' - useUserVideoLanguagePreferences = true + useUserVideoPreferences = true constructor ( protected i18n: I18n, @@ -67,6 +67,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On filter: this.filter, categoryOneOf: this.categoryOneOf, languageOneOf: this.languageOneOf, + nsfwPolicy: this.nsfwPolicy, skipCount: true } diff --git a/client/src/app/videos/video-list/video-most-liked.component.ts b/client/src/app/videos/video-list/video-most-liked.component.ts index b69fad05f..cc91a2330 100644 --- a/client/src/app/videos/video-list/video-most-liked.component.ts +++ b/client/src/app/videos/video-list/video-most-liked.component.ts @@ -21,7 +21,7 @@ export class VideoMostLikedComponent extends AbstractVideoList implements OnInit titlePage: string defaultSort: VideoSortField = '-likes' - useUserVideoLanguagePreferences = true + useUserVideoPreferences = true constructor ( protected i18n: I18n, @@ -55,6 +55,7 @@ export class VideoMostLikedComponent extends AbstractVideoList implements OnInit sort: this.sort, categoryOneOf: this.categoryOneOf, languageOneOf: this.languageOneOf, + nsfwPolicy: this.nsfwPolicy, skipCount: true } diff --git a/client/src/app/videos/video-list/video-overview.component.html b/client/src/app/videos/video-list/video-overview.component.html index 19d03b5c5..6de2fc292 100644 --- a/client/src/app/videos/video-list/video-overview.component.html +++ b/client/src/app/videos/video-list/video-overview.component.html @@ -14,7 +14,7 @@
- +
@@ -25,7 +25,7 @@
- +
@@ -40,7 +40,7 @@
- +
diff --git a/client/src/app/videos/video-list/video-overview.component.ts b/client/src/app/videos/video-list/video-overview.component.ts index 101073949..8ff8400db 100644 --- a/client/src/app/videos/video-list/video-overview.component.ts +++ b/client/src/app/videos/video-list/video-overview.component.ts @@ -1,11 +1,11 @@ +import { Subject } from 'rxjs' import { Component, OnInit } from '@angular/core' -import { AuthService, Notifier } from '@app/core' -import { I18n } from '@ngx-translate/i18n-polyfill' -import { VideosOverview } from '@app/shared/overview/videos-overview.model' +import { Notifier } from '@app/core' +import { User, UserService } from '@app/shared' +import { ScreenService } from '@app/shared/misc/screen.service' import { OverviewService } from '@app/shared/overview' +import { VideosOverview } from '@app/shared/overview/videos-overview.model' import { Video } from '@app/shared/video/video.model' -import { ScreenService } from '@app/shared/misc/screen.service' -import { Subject } from 'rxjs' @Component({ selector: 'my-video-overview', @@ -18,6 +18,8 @@ export class VideoOverviewComponent implements OnInit { overviews: VideosOverview[] = [] notResults = false + userMiniature: User + private loaded = false private currentPage = 1 private maxPage = 20 @@ -25,19 +27,20 @@ export class VideoOverviewComponent implements OnInit { private isLoading = false constructor ( - private i18n: I18n, private notifier: Notifier, - private authService: AuthService, + private userService: UserService, private overviewService: OverviewService, private screenService: ScreenService ) { } - get user () { - return this.authService.getUser() - } - ngOnInit () { this.loadMoreResults() + + this.userService.getAnonymousOrLoggedUser() + .subscribe(user => this.userMiniature = user) + + this.userService.listenAnonymousUpdate() + .subscribe(user => this.userMiniature = user) } buildVideoChannelBy (object: { videos: Video[] }) { 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 c1ddd4fd4..9f57a61e3 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 @@ -22,7 +22,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On sort: VideoSortField = '-publishedAt' groupByDate = true - useUserVideoLanguagePreferences = true + useUserVideoPreferences = true constructor ( protected i18n: I18n, @@ -59,6 +59,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On sort: this.sort, categoryOneOf: this.categoryOneOf, languageOneOf: this.languageOneOf, + nsfwPolicy: this.nsfwPolicy, skipCount: true } diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts index fbe052277..62e0f4e69 100644 --- a/client/src/app/videos/video-list/video-trending.component.ts +++ b/client/src/app/videos/video-list/video-trending.component.ts @@ -21,7 +21,7 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, titlePage: string defaultSort: VideoSortField = '-trending' - useUserVideoLanguagePreferences = true + useUserVideoPreferences = true constructor ( protected i18n: I18n, @@ -72,6 +72,7 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, sort: this.sort, categoryOneOf: this.categoryOneOf, languageOneOf: this.languageOneOf, + nsfwPolicy: this.nsfwPolicy, skipCount: true } -- cgit v1.2.3