diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-16 11:00:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-16 11:26:46 +0200 |
commit | 5c20a45518c3afc40c9494cad4a78def92e5e288 (patch) | |
tree | d4f6894b37394f3a40e6c58d34012bc55c05f55e /client/src/app/videos | |
parent | 64e0f8cf12c804a7a2fa582fd954f686cea9a45b (diff) | |
download | PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.tar.gz PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.tar.zst PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.zip |
Fix anonymous nsfw policy
Diffstat (limited to 'client/src/app/videos')
10 files changed, 82 insertions, 59 deletions
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 @@ | |||
248 | </div> | 248 | </div> |
249 | 249 | ||
250 | <my-recommended-videos | 250 | <my-recommended-videos |
251 | [inputRecommendation]="{ uuid: video.uuid, tags: video.tags }" | 251 | [inputRecommendation]="{ uuid: video.uuid, tags: video.tags }" |
252 | [user]="user" | 252 | [user]="user" |
253 | [playlist]="playlist" | 253 | [playlist]="playlist" |
254 | (gotRecommendations)="onRecommendations($event)" | 254 | (gotRecommendations)="onRecommendations($event)" |
255 | ></my-recommended-videos> | 255 | ></my-recommended-videos> |
256 | </div> | 256 | </div> |
257 | 257 | ||
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 @@ | |||
1 | import { Injectable, OnInit } from '@angular/core' | ||
2 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' | ||
3 | import { Video } from '@app/shared/video/video.model' | ||
4 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | ||
5 | import { VideoService } from '@app/shared/video/video.service' | ||
6 | import { map, switchMap } from 'rxjs/operators' | ||
7 | import { Observable, of } from 'rxjs' | 1 | import { Observable, of } from 'rxjs' |
8 | import { SearchService } from '@app/search/search.service' | 2 | import { map, switchMap } from 'rxjs/operators' |
9 | import { AdvancedSearch } from '@app/search/advanced-search.model' | 3 | import { Injectable } from '@angular/core' |
10 | import { ServerService } from '@app/core' | 4 | import { ServerService } from '@app/core' |
5 | import { AdvancedSearch } from '@app/search/advanced-search.model' | ||
6 | import { SearchService } from '@app/search/search.service' | ||
7 | import { UserService } from '@app/shared' | ||
8 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | ||
9 | import { Video } from '@app/shared/video/video.model' | ||
10 | import { VideoService } from '@app/shared/video/video.service' | ||
11 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' | ||
11 | import { ServerConfig } from '@shared/models' | 12 | import { ServerConfig } from '@shared/models' |
12 | import { truncate } from 'lodash' | ||
13 | 13 | ||
14 | /** | 14 | /** |
15 | * Provides "recommendations" by providing the most recently uploaded videos. | 15 | * Provides "recommendations" by providing the most recently uploaded videos. |
@@ -23,13 +23,14 @@ export class RecentVideosRecommendationService implements RecommendationService | |||
23 | constructor ( | 23 | constructor ( |
24 | private videos: VideoService, | 24 | private videos: VideoService, |
25 | private searchService: SearchService, | 25 | private searchService: SearchService, |
26 | private userService: UserService, | ||
26 | private serverService: ServerService | 27 | private serverService: ServerService |
27 | ) { | 28 | ) { |
28 | this.config = this.serverService.getTmpConfig() | 29 | this.config = this.serverService.getTmpConfig() |
29 | 30 | ||
30 | this.serverService.getConfig() | 31 | this.serverService.getConfig() |
31 | .subscribe(config => this.config = config) | 32 | .subscribe(config => this.config = config) |
32 | } | 33 | } |
33 | 34 | ||
34 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { | 35 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { |
35 | return this.fetchPage(1, recommendation) | 36 | return this.fetchPage(1, recommendation) |
@@ -55,20 +56,29 @@ export class RecentVideosRecommendationService implements RecommendationService | |||
55 | return defaultSubscription | 56 | return defaultSubscription |
56 | } | 57 | } |
57 | 58 | ||
58 | const params = { | 59 | return this.userService.getAnonymousOrLoggedUser() |
59 | search: '', | 60 | .pipe( |
60 | componentPagination: pagination, | 61 | map(user => { |
61 | advancedSearch: new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt', searchTarget: 'local' }) | 62 | return { |
62 | } | 63 | search: '', |
63 | 64 | componentPagination: pagination, | |
64 | return this.searchService.searchVideos(params) | 65 | advancedSearch: new AdvancedSearch({ |
65 | .pipe( | 66 | tagsOneOf: recommendation.tags.join(','), |
66 | map(v => v.data), | 67 | sort: '-createdAt', |
67 | switchMap(videos => { | 68 | searchTarget: 'local', |
68 | if (videos.length <= 1) return defaultSubscription | 69 | nsfw: user.nsfwPolicy |
70 | ? this.videos.nsfwPolicyToParam(user.nsfwPolicy) | ||
71 | : undefined | ||
72 | }) | ||
73 | } | ||
74 | }), | ||
75 | switchMap(params => this.searchService.searchVideos(params)), | ||
76 | map(v => v.data), | ||
77 | switchMap(videos => { | ||
78 | if (videos.length <= 1) return defaultSubscription | ||
69 | 79 | ||
70 | return of(videos) | 80 | return of(videos) |
71 | }) | 81 | }) |
72 | ) | 82 | ) |
73 | } | 83 | } |
74 | } | 84 | } |
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 @@ | |||
13 | </div> | 13 | </div> |
14 | 14 | ||
15 | <ng-container *ngFor="let video of (videos$ | async); let i = index; let length = count"> | 15 | <ng-container *ngFor="let video of (videos$ | async); let i = index; let length = count"> |
16 | <my-video-miniature | 16 | <my-video-miniature |
17 | [displayOptions]="displayOptions" [video]="video" [user]="user" | 17 | [displayOptions]="displayOptions" [video]="video" [user]="userMiniature" |
18 | (videoBlocked)="onVideoRemoved()" (videoRemoved)="onVideoRemoved()"> | 18 | (videoBlocked)="onVideoRemoved()" (videoRemoved)="onVideoRemoved()"> |
19 | </my-video-miniature> | 19 | </my-video-miniature> |
20 | 20 | ||
21 | <hr *ngIf="!playlist && i == 0 && length > 1" /> | 21 | <hr *ngIf="!playlist && i == 0 && length > 1" /> |
22 | </ng-container> | 22 | </ng-container> |
23 | </ng-container> | 23 | </ng-container> |
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 @@ | |||
1 | import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core' | ||
2 | import { Observable } from 'rxjs' | 1 | import { Observable } from 'rxjs' |
3 | import { Video } from '@app/shared/video/video.model' | 2 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' |
3 | import { AuthService, Notifier } from '@app/core' | ||
4 | import { User } from '@app/shared' | ||
5 | import { SessionStorageService } from '@app/shared/misc/storage.service' | ||
6 | import { UserService } from '@app/shared/users/user.service' | ||
4 | import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' | 7 | import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' |
5 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | 8 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' |
9 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' | ||
10 | import { Video } from '@app/shared/video/video.model' | ||
6 | import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' | 11 | import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' |
7 | import { User } from '@app/shared' | ||
8 | import { AuthService, Notifier } from '@app/core' | ||
9 | import { UserService } from '@app/shared/users/user.service' | ||
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | 12 | import { I18n } from '@ngx-translate/i18n-polyfill' |
11 | import { SessionStorageService } from '@app/shared/misc/storage.service' | ||
12 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' | ||
13 | 13 | ||
14 | @Component({ | 14 | @Component({ |
15 | selector: 'my-recommended-videos', | 15 | selector: 'my-recommended-videos', |
16 | templateUrl: './recommended-videos.component.html', | 16 | templateUrl: './recommended-videos.component.html', |
17 | styleUrls: [ './recommended-videos.component.scss' ] | 17 | styleUrls: [ './recommended-videos.component.scss' ] |
18 | }) | 18 | }) |
19 | export class RecommendedVideosComponent implements OnChanges { | 19 | export class RecommendedVideosComponent implements OnInit, OnChanges { |
20 | @Input() inputRecommendation: RecommendationInfo | 20 | @Input() inputRecommendation: RecommendationInfo |
21 | @Input() user: User | ||
22 | @Input() playlist: VideoPlaylist | 21 | @Input() playlist: VideoPlaylist |
23 | @Output() gotRecommendations = new EventEmitter<Video[]>() | 22 | @Output() gotRecommendations = new EventEmitter<Video[]>() |
24 | 23 | ||
@@ -32,6 +31,8 @@ export class RecommendedVideosComponent implements OnChanges { | |||
32 | avatar: true | 31 | avatar: true |
33 | } | 32 | } |
34 | 33 | ||
34 | userMiniature: User | ||
35 | |||
35 | readonly hasVideos$: Observable<boolean> | 36 | readonly hasVideos$: Observable<boolean> |
36 | readonly videos$: Observable<Video[]> | 37 | readonly videos$: Observable<Video[]> |
37 | 38 | ||
@@ -59,7 +60,12 @@ export class RecommendedVideosComponent implements OnChanges { | |||
59 | this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.') | 60 | this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.') |
60 | } | 61 | } |
61 | 62 | ||
62 | public ngOnChanges (): void { | 63 | ngOnInit () { |
64 | this.userService.getAnonymousOrLoggedUser() | ||
65 | .subscribe(user => this.userMiniature = user) | ||
66 | } | ||
67 | |||
68 | ngOnChanges () { | ||
63 | if (this.inputRecommendation) { | 69 | if (this.inputRecommendation) { |
64 | this.store.requestNewRecommendations(this.inputRecommendation) | 70 | this.store.requestNewRecommendations(this.inputRecommendation) |
65 | } | 71 | } |
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 | |||
24 | sort = '-publishedAt' as VideoSortField | 24 | sort = '-publishedAt' as VideoSortField |
25 | filter: VideoFilter = 'local' | 25 | filter: VideoFilter = 'local' |
26 | 26 | ||
27 | useUserVideoLanguagePreferences = true | 27 | useUserVideoPreferences = true |
28 | 28 | ||
29 | constructor ( | 29 | constructor ( |
30 | protected i18n: I18n, | 30 | protected i18n: I18n, |
@@ -67,6 +67,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On | |||
67 | filter: this.filter, | 67 | filter: this.filter, |
68 | categoryOneOf: this.categoryOneOf, | 68 | categoryOneOf: this.categoryOneOf, |
69 | languageOneOf: this.languageOneOf, | 69 | languageOneOf: this.languageOneOf, |
70 | nsfwPolicy: this.nsfwPolicy, | ||
70 | skipCount: true | 71 | skipCount: true |
71 | } | 72 | } |
72 | 73 | ||
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 | |||
21 | titlePage: string | 21 | titlePage: string |
22 | defaultSort: VideoSortField = '-likes' | 22 | defaultSort: VideoSortField = '-likes' |
23 | 23 | ||
24 | useUserVideoLanguagePreferences = true | 24 | useUserVideoPreferences = true |
25 | 25 | ||
26 | constructor ( | 26 | constructor ( |
27 | protected i18n: I18n, | 27 | protected i18n: I18n, |
@@ -55,6 +55,7 @@ export class VideoMostLikedComponent extends AbstractVideoList implements OnInit | |||
55 | sort: this.sort, | 55 | sort: this.sort, |
56 | categoryOneOf: this.categoryOneOf, | 56 | categoryOneOf: this.categoryOneOf, |
57 | languageOneOf: this.languageOneOf, | 57 | languageOneOf: this.languageOneOf, |
58 | nsfwPolicy: this.nsfwPolicy, | ||
58 | skipCount: true | 59 | skipCount: true |
59 | } | 60 | } |
60 | 61 | ||
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 @@ | |||
14 | </h1> | 14 | </h1> |
15 | 15 | ||
16 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> | 16 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> |
17 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="user" [displayVideoActions]="false"> | 17 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="userMiniature" [displayVideoActions]="false"> |
18 | </my-video-miniature> | 18 | </my-video-miniature> |
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
@@ -25,7 +25,7 @@ | |||
25 | </h2> | 25 | </h2> |
26 | 26 | ||
27 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> | 27 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> |
28 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="user" [displayVideoActions]="false"> | 28 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="userMiniature" [displayVideoActions]="false"> |
29 | </my-video-miniature> | 29 | </my-video-miniature> |
30 | </div> | 30 | </div> |
31 | </div> | 31 | </div> |
@@ -40,7 +40,7 @@ | |||
40 | </div> | 40 | </div> |
41 | 41 | ||
42 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> | 42 | <div class="video-wrapper" *ngFor="let video of buildVideos(object.videos)"> |
43 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="user" [displayVideoActions]="false"> | 43 | <my-video-miniature [video]="video" [fitWidth]="true" [user]="userMiniature" [displayVideoActions]="false"> |
44 | </my-video-miniature> | 44 | </my-video-miniature> |
45 | </div> | 45 | </div> |
46 | </div> | 46 | </div> |
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 @@ | |||
1 | import { Subject } from 'rxjs' | ||
1 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
2 | import { AuthService, Notifier } from '@app/core' | 3 | import { Notifier } from '@app/core' |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | 4 | import { User, UserService } from '@app/shared' |
4 | import { VideosOverview } from '@app/shared/overview/videos-overview.model' | 5 | import { ScreenService } from '@app/shared/misc/screen.service' |
5 | import { OverviewService } from '@app/shared/overview' | 6 | import { OverviewService } from '@app/shared/overview' |
7 | import { VideosOverview } from '@app/shared/overview/videos-overview.model' | ||
6 | import { Video } from '@app/shared/video/video.model' | 8 | import { Video } from '@app/shared/video/video.model' |
7 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
8 | import { Subject } from 'rxjs' | ||
9 | 9 | ||
10 | @Component({ | 10 | @Component({ |
11 | selector: 'my-video-overview', | 11 | selector: 'my-video-overview', |
@@ -18,6 +18,8 @@ export class VideoOverviewComponent implements OnInit { | |||
18 | overviews: VideosOverview[] = [] | 18 | overviews: VideosOverview[] = [] |
19 | notResults = false | 19 | notResults = false |
20 | 20 | ||
21 | userMiniature: User | ||
22 | |||
21 | private loaded = false | 23 | private loaded = false |
22 | private currentPage = 1 | 24 | private currentPage = 1 |
23 | private maxPage = 20 | 25 | private maxPage = 20 |
@@ -25,19 +27,20 @@ export class VideoOverviewComponent implements OnInit { | |||
25 | private isLoading = false | 27 | private isLoading = false |
26 | 28 | ||
27 | constructor ( | 29 | constructor ( |
28 | private i18n: I18n, | ||
29 | private notifier: Notifier, | 30 | private notifier: Notifier, |
30 | private authService: AuthService, | 31 | private userService: UserService, |
31 | private overviewService: OverviewService, | 32 | private overviewService: OverviewService, |
32 | private screenService: ScreenService | 33 | private screenService: ScreenService |
33 | ) { } | 34 | ) { } |
34 | 35 | ||
35 | get user () { | ||
36 | return this.authService.getUser() | ||
37 | } | ||
38 | |||
39 | ngOnInit () { | 36 | ngOnInit () { |
40 | this.loadMoreResults() | 37 | this.loadMoreResults() |
38 | |||
39 | this.userService.getAnonymousOrLoggedUser() | ||
40 | .subscribe(user => this.userMiniature = user) | ||
41 | |||
42 | this.userService.listenAnonymousUpdate() | ||
43 | .subscribe(user => this.userMiniature = user) | ||
41 | } | 44 | } |
42 | 45 | ||
43 | buildVideoChannelBy (object: { videos: Video[] }) { | 46 | 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 | |||
22 | sort: VideoSortField = '-publishedAt' | 22 | sort: VideoSortField = '-publishedAt' |
23 | groupByDate = true | 23 | groupByDate = true |
24 | 24 | ||
25 | useUserVideoLanguagePreferences = true | 25 | useUserVideoPreferences = true |
26 | 26 | ||
27 | constructor ( | 27 | constructor ( |
28 | protected i18n: I18n, | 28 | protected i18n: I18n, |
@@ -59,6 +59,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On | |||
59 | sort: this.sort, | 59 | sort: this.sort, |
60 | categoryOneOf: this.categoryOneOf, | 60 | categoryOneOf: this.categoryOneOf, |
61 | languageOneOf: this.languageOneOf, | 61 | languageOneOf: this.languageOneOf, |
62 | nsfwPolicy: this.nsfwPolicy, | ||
62 | skipCount: true | 63 | skipCount: true |
63 | } | 64 | } |
64 | 65 | ||
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, | |||
21 | titlePage: string | 21 | titlePage: string |
22 | defaultSort: VideoSortField = '-trending' | 22 | defaultSort: VideoSortField = '-trending' |
23 | 23 | ||
24 | useUserVideoLanguagePreferences = true | 24 | useUserVideoPreferences = true |
25 | 25 | ||
26 | constructor ( | 26 | constructor ( |
27 | protected i18n: I18n, | 27 | protected i18n: I18n, |
@@ -72,6 +72,7 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, | |||
72 | sort: this.sort, | 72 | sort: this.sort, |
73 | categoryOneOf: this.categoryOneOf, | 73 | categoryOneOf: this.categoryOneOf, |
74 | languageOneOf: this.languageOneOf, | 74 | languageOneOf: this.languageOneOf, |
75 | nsfwPolicy: this.nsfwPolicy, | ||
75 | skipCount: true | 76 | skipCount: true |
76 | } | 77 | } |
77 | 78 | ||