diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:49:20 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 1942f11d5ee6926ad93dc1b79fae18325ba5de18 (patch) | |
tree | 3f2a3cd9466a56c419d197ac832a3e9cbc86bec4 /client/src/app/videos/recommendations | |
parent | 67ed6552b831df66713bac9e672738796128d33f (diff) | |
download | PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.gz PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.zst PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.zip |
Lazy load all routes
Diffstat (limited to 'client/src/app/videos/recommendations')
8 files changed, 0 insertions, 308 deletions
diff --git a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts deleted file mode 100644 index a376453bf..000000000 --- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | import { Observable, of } from 'rxjs' | ||
2 | import { map, switchMap } from 'rxjs/operators' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { ServerService, UserService } from '@app/core' | ||
5 | import { AdvancedSearch } from '@app/search/advanced-search.model' | ||
6 | import { SearchService } from '@app/search/search.service' | ||
7 | import { Video, VideoService } from '@app/shared/shared-main' | ||
8 | import { ServerConfig } from '@shared/models' | ||
9 | import { RecommendationInfo } from './recommendation-info.model' | ||
10 | import { RecommendationService } from './recommendations.service' | ||
11 | |||
12 | /** | ||
13 | * Provides "recommendations" by providing the most recently uploaded videos. | ||
14 | */ | ||
15 | @Injectable() | ||
16 | export class RecentVideosRecommendationService implements RecommendationService { | ||
17 | readonly pageSize = 5 | ||
18 | |||
19 | private config: ServerConfig | ||
20 | |||
21 | constructor ( | ||
22 | private videos: VideoService, | ||
23 | private searchService: SearchService, | ||
24 | private userService: UserService, | ||
25 | private serverService: ServerService | ||
26 | ) { | ||
27 | this.config = this.serverService.getTmpConfig() | ||
28 | |||
29 | this.serverService.getConfig() | ||
30 | .subscribe(config => this.config = config) | ||
31 | } | ||
32 | |||
33 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { | ||
34 | return this.fetchPage(1, recommendation) | ||
35 | .pipe( | ||
36 | map(videos => { | ||
37 | const otherVideos = videos.filter(v => v.uuid !== recommendation.uuid) | ||
38 | return otherVideos.slice(0, this.pageSize) | ||
39 | }) | ||
40 | ) | ||
41 | } | ||
42 | |||
43 | private fetchPage (page: number, recommendation: RecommendationInfo): Observable<Video[]> { | ||
44 | const pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } | ||
45 | const defaultSubscription = this.videos.getVideos({ videoPagination: pagination, sort: '-createdAt' }) | ||
46 | .pipe(map(v => v.data)) | ||
47 | |||
48 | const tags = recommendation.tags | ||
49 | const searchIndexConfig = this.config.search.searchIndex | ||
50 | if ( | ||
51 | !tags || tags.length === 0 || | ||
52 | (searchIndexConfig.enabled === true && searchIndexConfig.disableLocalSearch === true) | ||
53 | ) { | ||
54 | return defaultSubscription | ||
55 | } | ||
56 | |||
57 | return this.userService.getAnonymousOrLoggedUser() | ||
58 | .pipe( | ||
59 | map(user => { | ||
60 | return { | ||
61 | search: '', | ||
62 | componentPagination: pagination, | ||
63 | advancedSearch: new AdvancedSearch({ | ||
64 | tagsOneOf: recommendation.tags.join(','), | ||
65 | sort: '-createdAt', | ||
66 | searchTarget: 'local', | ||
67 | nsfw: user.nsfwPolicy | ||
68 | ? this.videos.nsfwPolicyToParam(user.nsfwPolicy) | ||
69 | : undefined | ||
70 | }) | ||
71 | } | ||
72 | }), | ||
73 | switchMap(params => this.searchService.searchVideos(params)), | ||
74 | map(v => v.data), | ||
75 | switchMap(videos => { | ||
76 | if (videos.length <= 1) return defaultSubscription | ||
77 | |||
78 | return of(videos) | ||
79 | }) | ||
80 | ) | ||
81 | } | ||
82 | } | ||
diff --git a/client/src/app/videos/recommendations/recommendation-info.model.ts b/client/src/app/videos/recommendations/recommendation-info.model.ts deleted file mode 100644 index 0233563bb..000000000 --- a/client/src/app/videos/recommendations/recommendation-info.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface RecommendationInfo { | ||
2 | uuid: string | ||
3 | tags?: string[] | ||
4 | } | ||
diff --git a/client/src/app/videos/recommendations/recommendations.module.ts b/client/src/app/videos/recommendations/recommendations.module.ts deleted file mode 100644 index 03cc272ca..000000000 --- a/client/src/app/videos/recommendations/recommendations.module.ts +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | import { InputSwitchModule } from 'primeng/inputswitch' | ||
2 | import { CommonModule } from '@angular/common' | ||
3 | import { NgModule } from '@angular/core' | ||
4 | import { SharedMainModule } from '@app/shared/shared-main' | ||
5 | import { SharedVideoMiniatureModule } from '@app/shared/shared-video-miniature' | ||
6 | import { SharedVideoPlaylistModule } from '@app/shared/shared-video-playlist' | ||
7 | import { RecentVideosRecommendationService } from './recent-videos-recommendation.service' | ||
8 | import { RecommendedVideosComponent } from './recommended-videos.component' | ||
9 | import { RecommendedVideosStore } from './recommended-videos.store' | ||
10 | |||
11 | @NgModule({ | ||
12 | imports: [ | ||
13 | CommonModule, | ||
14 | InputSwitchModule, | ||
15 | |||
16 | SharedMainModule, | ||
17 | SharedVideoPlaylistModule, | ||
18 | SharedVideoMiniatureModule | ||
19 | ], | ||
20 | declarations: [ | ||
21 | RecommendedVideosComponent | ||
22 | ], | ||
23 | exports: [ | ||
24 | RecommendedVideosComponent | ||
25 | ], | ||
26 | providers: [ | ||
27 | RecommendedVideosStore, | ||
28 | RecentVideosRecommendationService | ||
29 | ] | ||
30 | }) | ||
31 | export class RecommendationsModule { | ||
32 | } | ||
diff --git a/client/src/app/videos/recommendations/recommendations.service.ts b/client/src/app/videos/recommendations/recommendations.service.ts deleted file mode 100644 index 1d79d35f6..000000000 --- a/client/src/app/videos/recommendations/recommendations.service.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { Video } from '@app/shared/shared-main' | ||
3 | import { RecommendationInfo } from './recommendation-info.model' | ||
4 | |||
5 | export interface RecommendationService { | ||
6 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> | ||
7 | } | ||
diff --git a/client/src/app/videos/recommendations/recommended-videos.component.html b/client/src/app/videos/recommendations/recommended-videos.component.html deleted file mode 100644 index 0467cabf5..000000000 --- a/client/src/app/videos/recommendations/recommended-videos.component.html +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | <div class="other-videos"> | ||
2 | <ng-container *ngIf="hasVideos$ | async"> | ||
3 | <div class="title-page-container"> | ||
4 | <h2 i18n class="title-page title-page-single"> | ||
5 | Other videos | ||
6 | </h2> | ||
7 | <div *ngIf="!playlist" class="title-page-autoplay" | ||
8 | [ngbTooltip]="autoPlayNextVideoTooltip" placement="bottom-right auto" | ||
9 | > | ||
10 | <span i18n>AUTOPLAY</span> | ||
11 | <p-inputSwitch class="small" [(ngModel)]="autoPlayNextVideo" (ngModelChange)="switchAutoPlayNextVideo()"></p-inputSwitch> | ||
12 | </div> | ||
13 | </div> | ||
14 | |||
15 | <ng-container *ngFor="let video of (videos$ | async); let i = index; let length = count"> | ||
16 | <my-video-miniature | ||
17 | [displayOptions]="displayOptions" [video]="video" [user]="userMiniature" | ||
18 | (videoBlocked)="onVideoRemoved()" (videoRemoved)="onVideoRemoved()"> | ||
19 | </my-video-miniature> | ||
20 | |||
21 | <hr *ngIf="!playlist && i == 0 && length > 1" /> | ||
22 | </ng-container> | ||
23 | </ng-container> | ||
24 | </div> | ||
diff --git a/client/src/app/videos/recommendations/recommended-videos.component.scss b/client/src/app/videos/recommendations/recommended-videos.component.scss deleted file mode 100644 index b278c9654..000000000 --- a/client/src/app/videos/recommendations/recommended-videos.component.scss +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | .title-page-container { | ||
2 | display: flex; | ||
3 | justify-content: space-between; | ||
4 | align-items: baseline; | ||
5 | margin-bottom: 25px; | ||
6 | flex-wrap: wrap-reverse; | ||
7 | |||
8 | .title-page.active, .title-page.title-page-single { | ||
9 | margin-bottom: unset; | ||
10 | margin-right: .5rem !important; | ||
11 | } | ||
12 | } | ||
13 | |||
14 | .title-page-autoplay { | ||
15 | display: flex; | ||
16 | width: max-content; | ||
17 | height: max-content; | ||
18 | align-items: center; | ||
19 | margin-left: auto; | ||
20 | |||
21 | span { | ||
22 | margin-right: 0.3rem; | ||
23 | text-transform: uppercase; | ||
24 | font-size: 85%; | ||
25 | font-weight: 600; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | hr { | ||
30 | margin-top: 0; | ||
31 | } | ||
diff --git a/client/src/app/videos/recommendations/recommended-videos.component.ts b/client/src/app/videos/recommendations/recommended-videos.component.ts deleted file mode 100644 index 016975341..000000000 --- a/client/src/app/videos/recommendations/recommended-videos.component.ts +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' | ||
3 | import { AuthService, Notifier, SessionStorageService, User, UserService } from '@app/core' | ||
4 | import { Video } from '@app/shared/shared-main' | ||
5 | import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' | ||
6 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' | ||
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
8 | import { RecommendationInfo } from './recommendation-info.model' | ||
9 | import { RecommendedVideosStore } from './recommended-videos.store' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-recommended-videos', | ||
13 | templateUrl: './recommended-videos.component.html', | ||
14 | styleUrls: [ './recommended-videos.component.scss' ] | ||
15 | }) | ||
16 | export class RecommendedVideosComponent implements OnInit, OnChanges { | ||
17 | @Input() inputRecommendation: RecommendationInfo | ||
18 | @Input() playlist: VideoPlaylist | ||
19 | @Output() gotRecommendations = new EventEmitter<Video[]>() | ||
20 | |||
21 | autoPlayNextVideo: boolean | ||
22 | autoPlayNextVideoTooltip: string | ||
23 | |||
24 | displayOptions: MiniatureDisplayOptions = { | ||
25 | date: true, | ||
26 | views: true, | ||
27 | by: true, | ||
28 | avatar: true | ||
29 | } | ||
30 | |||
31 | userMiniature: User | ||
32 | |||
33 | readonly hasVideos$: Observable<boolean> | ||
34 | readonly videos$: Observable<Video[]> | ||
35 | |||
36 | constructor ( | ||
37 | private userService: UserService, | ||
38 | private authService: AuthService, | ||
39 | private notifier: Notifier, | ||
40 | private i18n: I18n, | ||
41 | private store: RecommendedVideosStore, | ||
42 | private sessionStorageService: SessionStorageService | ||
43 | ) { | ||
44 | this.videos$ = this.store.recommendations$ | ||
45 | this.hasVideos$ = this.store.hasRecommendations$ | ||
46 | this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) | ||
47 | |||
48 | if (this.authService.isLoggedIn()) { | ||
49 | this.autoPlayNextVideo = this.authService.getUser().autoPlayNextVideo | ||
50 | } else { | ||
51 | this.autoPlayNextVideo = this.sessionStorageService.getItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' || false | ||
52 | this.sessionStorageService.watch([User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO]).subscribe( | ||
53 | () => this.autoPlayNextVideo = this.sessionStorageService.getItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' | ||
54 | ) | ||
55 | } | ||
56 | |||
57 | this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.') | ||
58 | } | ||
59 | |||
60 | ngOnInit () { | ||
61 | this.userService.getAnonymousOrLoggedUser() | ||
62 | .subscribe(user => this.userMiniature = user) | ||
63 | } | ||
64 | |||
65 | ngOnChanges () { | ||
66 | if (this.inputRecommendation) { | ||
67 | this.store.requestNewRecommendations(this.inputRecommendation) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | onVideoRemoved () { | ||
72 | this.store.requestNewRecommendations(this.inputRecommendation) | ||
73 | } | ||
74 | |||
75 | switchAutoPlayNextVideo () { | ||
76 | this.sessionStorageService.setItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString()) | ||
77 | |||
78 | if (this.authService.isLoggedIn()) { | ||
79 | const details = { | ||
80 | autoPlayNextVideo: this.autoPlayNextVideo | ||
81 | } | ||
82 | |||
83 | this.userService.updateMyProfile(details).subscribe( | ||
84 | () => { | ||
85 | this.authService.refreshUserInformation() | ||
86 | }, | ||
87 | err => this.notifier.error(err.message) | ||
88 | ) | ||
89 | } | ||
90 | } | ||
91 | } | ||
diff --git a/client/src/app/videos/recommendations/recommended-videos.store.ts b/client/src/app/videos/recommendations/recommended-videos.store.ts deleted file mode 100644 index 8c3fb6480..000000000 --- a/client/src/app/videos/recommendations/recommended-videos.store.ts +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | import { Observable, ReplaySubject } from 'rxjs' | ||
2 | import { map, shareReplay, switchMap, take } from 'rxjs/operators' | ||
3 | import { Inject, Injectable } from '@angular/core' | ||
4 | import { Video } from '@app/shared/shared-main' | ||
5 | import { RecentVideosRecommendationService } from './recent-videos-recommendation.service' | ||
6 | import { RecommendationInfo } from './recommendation-info.model' | ||
7 | import { RecommendationService } from './recommendations.service' | ||
8 | |||
9 | /** | ||
10 | * This store is intended to provide data for the RecommendedVideosComponent. | ||
11 | */ | ||
12 | @Injectable() | ||
13 | export class RecommendedVideosStore { | ||
14 | public readonly recommendations$: Observable<Video[]> | ||
15 | public readonly hasRecommendations$: Observable<boolean> | ||
16 | private readonly requestsForLoad$$ = new ReplaySubject<RecommendationInfo>(1) | ||
17 | |||
18 | constructor ( | ||
19 | @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService | ||
20 | ) { | ||
21 | this.recommendations$ = this.requestsForLoad$$.pipe( | ||
22 | switchMap(requestedRecommendation => { | ||
23 | return this.recommendations.getRecommendations(requestedRecommendation) | ||
24 | .pipe(take(1)) | ||
25 | }), | ||
26 | shareReplay() | ||
27 | ) | ||
28 | |||
29 | this.hasRecommendations$ = this.recommendations$.pipe( | ||
30 | map(otherVideos => otherVideos.length > 0) | ||
31 | ) | ||
32 | } | ||
33 | |||
34 | requestNewRecommendations (recommend: RecommendationInfo) { | ||
35 | this.requestsForLoad$$.next(recommend) | ||
36 | } | ||
37 | } | ||