aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/recommendations
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/recommendations')
-rw-r--r--client/src/app/videos/recommendations/recent-videos-recommendation.service.ts58
-rw-r--r--client/src/app/videos/recommendations/recommended-videos.component.html6
-rw-r--r--client/src/app/videos/recommendations/recommended-videos.component.ts26
3 files changed, 53 insertions, 37 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
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 @@
1import { Injectable, OnInit } from '@angular/core'
2import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
3import { Video } from '@app/shared/video/video.model'
4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
5import { VideoService } from '@app/shared/video/video.service'
6import { map, switchMap } from 'rxjs/operators'
7import { Observable, of } from 'rxjs' 1import { Observable, of } from 'rxjs'
8import { SearchService } from '@app/search/search.service' 2import { map, switchMap } from 'rxjs/operators'
9import { AdvancedSearch } from '@app/search/advanced-search.model' 3import { Injectable } from '@angular/core'
10import { ServerService } from '@app/core' 4import { ServerService } from '@app/core'
5import { AdvancedSearch } from '@app/search/advanced-search.model'
6import { SearchService } from '@app/search/search.service'
7import { UserService } from '@app/shared'
8import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
9import { Video } from '@app/shared/video/video.model'
10import { VideoService } from '@app/shared/video/video.service'
11import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
11import { ServerConfig } from '@shared/models' 12import { ServerConfig } from '@shared/models'
12import { 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 @@
1import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core'
2import { Observable } from 'rxjs' 1import { Observable } from 'rxjs'
3import { Video } from '@app/shared/video/video.model' 2import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
3import { AuthService, Notifier } from '@app/core'
4import { User } from '@app/shared'
5import { SessionStorageService } from '@app/shared/misc/storage.service'
6import { UserService } from '@app/shared/users/user.service'
4import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' 7import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
5import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' 8import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
9import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
10import { Video } from '@app/shared/video/video.model'
6import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' 11import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store'
7import { User } from '@app/shared'
8import { AuthService, Notifier } from '@app/core'
9import { UserService } from '@app/shared/users/user.service'
10import { I18n } from '@ngx-translate/i18n-polyfill' 12import { I18n } from '@ngx-translate/i18n-polyfill'
11import { SessionStorageService } from '@app/shared/misc/storage.service'
12import { 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})
19export class RecommendedVideosComponent implements OnChanges { 19export 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 }