aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-28 14:51:30 +0200
committerChocobozzz <me@florianbigard.com>2018-09-28 14:51:30 +0200
commit01fe5bd721ae99569f776ad362ebdaa5ba8f494f (patch)
tree1acfe24beb2531987660578524be324b2885525f /client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
parent19f22055162185d5f46d5916c82de3639de209a1 (diff)
downloadPeerTube-01fe5bd721ae99569f776ad362ebdaa5ba8f494f.tar.gz
PeerTube-01fe5bd721ae99569f776ad362ebdaa5ba8f494f.tar.zst
PeerTube-01fe5bd721ae99569f776ad362ebdaa5ba8f494f.zip
Fix no other videos displayed on some videos
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.ts31
1 files changed, 14 insertions, 17 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 59acf17bc..6d7b159da 100644
--- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
+++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
@@ -3,8 +3,8 @@ import { RecommendationService } from '@app/videos/recommendations/recommendatio
3import { Video } from '@app/shared/video/video.model' 3import { Video } from '@app/shared/video/video.model'
4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' 4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
5import { VideoService } from '@app/shared/video/video.service' 5import { VideoService } from '@app/shared/video/video.service'
6import { map } from 'rxjs/operators' 6import { map, switchMap } from 'rxjs/operators'
7import { Observable } from 'rxjs' 7import { Observable, of } from 'rxjs'
8import { SearchService } from '@app/search/search.service' 8import { SearchService } from '@app/search/search.service'
9import { AdvancedSearch } from '@app/search/advanced-search.model' 9import { AdvancedSearch } from '@app/search/advanced-search.model'
10 10
@@ -13,7 +13,6 @@ import { AdvancedSearch } from '@app/search/advanced-search.model'
13 */ 13 */
14@Injectable() 14@Injectable()
15export class RecentVideosRecommendationService implements RecommendationService { 15export class RecentVideosRecommendationService implements RecommendationService {
16
17 readonly pageSize = 5 16 readonly pageSize = 5
18 17
19 constructor ( 18 constructor (
@@ -32,24 +31,22 @@ export class RecentVideosRecommendationService implements RecommendationService
32 } 31 }
33 32
34 private fetchPage (page: number, recommendation: RecommendationInfo): Observable<Video[]> { 33 private fetchPage (page: number, recommendation: RecommendationInfo): Observable<Video[]> {
35 let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } 34 const pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 }
36 if (!recommendation.tags) { 35 const defaultSubscription = this.videos.getVideos(pagination, '-createdAt')
37 return this.videos.getVideos(pagination, '-createdAt') 36 .pipe(map(v => v.videos))
38 .pipe( 37
39 map(v => v.videos) 38 if (!recommendation.tags || recommendation.tags.length === 0) return defaultSubscription
40 ) 39
41 }
42 if (recommendation.tags.length === 0) {
43 return this.videos.getVideos(pagination, '-createdAt')
44 .pipe(
45 map(v => v.videos)
46 )
47 }
48 return this.searchService.searchVideos('', 40 return this.searchService.searchVideos('',
49 pagination, 41 pagination,
50 new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' }) 42 new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' })
51 ).pipe( 43 ).pipe(
52 map(v => v.videos) 44 map(v => v.videos),
45 switchMap(videos => {
46 if (videos.length <= 1) return defaultSubscription
47
48 return of(videos)
49 })
53 ) 50 )
54 } 51 }
55} 52}