diff options
Diffstat (limited to 'client/src/app/videos/recommendations/recent-videos-recommendation.service.ts')
-rw-r--r-- | client/src/app/videos/recommendations/recent-videos-recommendation.service.ts | 39 |
1 files changed, 28 insertions, 11 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 708d67699..4723f7fd0 100644 --- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts +++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts | |||
@@ -1,9 +1,12 @@ | |||
1 | import { Inject, Injectable } from '@angular/core' | 1 | import { Inject, Injectable } from '@angular/core' |
2 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' | 2 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' |
3 | import { Video } from '@app/shared/video/video.model' | 3 | import { Video } from '@app/shared/video/video.model' |
4 | import { VideoService, VideosProvider } from '@app/shared/video/video.service' | 4 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' |
5 | import { VideoService } from '@app/shared/video/video.service' | ||
5 | import { map } from 'rxjs/operators' | 6 | import { map } from 'rxjs/operators' |
6 | import { Observable } from 'rxjs' | 7 | import { Observable } from 'rxjs' |
8 | import { SearchService } from '@app/search/search.service' | ||
9 | import { AdvancedSearch } from '@app/search/advanced-search.model' | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * Provides "recommendations" by providing the most recently uploaded videos. | 12 | * Provides "recommendations" by providing the most recently uploaded videos. |
@@ -14,26 +17,40 @@ export class RecentVideosRecommendationService implements RecommendationService | |||
14 | readonly pageSize = 5 | 17 | readonly pageSize = 5 |
15 | 18 | ||
16 | constructor ( | 19 | constructor ( |
17 | @Inject(VideoService) private videos: VideosProvider | 20 | private videos: VideoService, |
21 | private searchService: SearchService | ||
18 | ) { | 22 | ) { |
19 | } | 23 | } |
20 | 24 | ||
21 | getRecommendations (uuid: string): Observable<Video[]> { | 25 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { |
22 | return this.fetchPage(1) | 26 | return this.fetchPage(1, recommendation) |
23 | .pipe( | 27 | .pipe( |
24 | map(vids => { | 28 | map(vids => { |
25 | const otherVideos = vids.filter(v => v.uuid !== uuid) | 29 | const otherVideos = vids.filter(v => v.uuid !== recommendation.uuid) |
26 | return otherVideos.slice(0, this.pageSize) | 30 | return otherVideos.slice(0, this.pageSize) |
27 | }) | 31 | }) |
28 | ) | 32 | ) |
29 | } | 33 | } |
30 | 34 | ||
31 | private fetchPage (page: number): Observable<Video[]> { | 35 | private fetchPage (page: number, recommendation: RecommendationInfo): Observable<Video[]> { |
32 | let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } | 36 | let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } |
33 | return this.videos.getVideos(pagination, '-createdAt') | 37 | if (!recommendation.tags) { |
34 | .pipe( | 38 | return this.videos.getVideos(pagination, '-createdAt') |
35 | map(v => v.videos) | 39 | .pipe( |
36 | ) | 40 | map(v => v.videos) |
41 | ) | ||
42 | } | ||
43 | if (recommendation.tags.length === 0) { | ||
44 | return this.videos.getVideos(pagination, '-createdAt') | ||
45 | .pipe( | ||
46 | map(v => v.videos) | ||
47 | ) | ||
48 | } | ||
49 | return this.searchService.searchVideos('', | ||
50 | pagination, | ||
51 | new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' }) | ||
52 | ).pipe( | ||
53 | map(v => v.videos) | ||
54 | ) | ||
37 | } | 55 | } |
38 | |||
39 | } | 56 | } |