X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fapp%2Fvideos%2Frecommendations%2Frecent-videos-recommendation.service.ts;h=6d7b159dad90e1cc13952a65f2979f690cbe2a4a;hb=01fe5bd721ae99569f776ad362ebdaa5ba8f494f;hp=59acf17bcc99c5620427a5610eccf2692fd4ff8d;hpb=19f22055162185d5f46d5916c82de3639de209a1;p=github%2FChocobozzz%2FPeerTube.git 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 import { Video } from '@app/shared/video/video.model' import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' import { VideoService } from '@app/shared/video/video.service' -import { map } from 'rxjs/operators' -import { Observable } from 'rxjs' +import { map, switchMap } from 'rxjs/operators' +import { Observable, of } from 'rxjs' import { SearchService } from '@app/search/search.service' import { AdvancedSearch } from '@app/search/advanced-search.model' @@ -13,7 +13,6 @@ import { AdvancedSearch } from '@app/search/advanced-search.model' */ @Injectable() export class RecentVideosRecommendationService implements RecommendationService { - readonly pageSize = 5 constructor ( @@ -32,24 +31,22 @@ export class RecentVideosRecommendationService implements RecommendationService } private fetchPage (page: number, recommendation: RecommendationInfo): Observable { - let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } - if (!recommendation.tags) { - return this.videos.getVideos(pagination, '-createdAt') - .pipe( - map(v => v.videos) - ) - } - if (recommendation.tags.length === 0) { - return this.videos.getVideos(pagination, '-createdAt') - .pipe( - map(v => v.videos) - ) - } + const pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } + const defaultSubscription = this.videos.getVideos(pagination, '-createdAt') + .pipe(map(v => v.videos)) + + if (!recommendation.tags || recommendation.tags.length === 0) return defaultSubscription + return this.searchService.searchVideos('', pagination, new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' }) ).pipe( - map(v => v.videos) + map(v => v.videos), + switchMap(videos => { + if (videos.length <= 1) return defaultSubscription + + return of(videos) + }) ) } }