aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
diff options
context:
space:
mode:
authorBrad Johnson <bradsk88@gmail.com>2018-08-31 09:19:21 -0600
committerChocobozzz <me@florianbigard.com>2018-08-31 17:19:21 +0200
commit7f5f4152a4cd4fc328d6ae177d281ebe7e792dd3 (patch)
treefd0401bd9c43e1adbbedbd2042c93bd4fef46632 /client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
parent1a4710914432b44115b185cec1883fdf409aef1d (diff)
downloadPeerTube-7f5f4152a4cd4fc328d6ae177d281ebe7e792dd3.tar.gz
PeerTube-7f5f4152a4cd4fc328d6ae177d281ebe7e792dd3.tar.zst
PeerTube-7f5f4152a4cd4fc328d6ae177d281ebe7e792dd3.zip
Refactor: Separated "Other Videos" section into a dedicated component/service (#969)
* Separated "Other Videos" section into a dedicated component/service I'm currently working on some proof-of-concepts for recommendation providers that could work with PeerTube to provide useful video suggestions to the user. As a first step, I want to have great clarity about how PeerTube, itself, will surface these videos to the user. With this branch, I'm refactoring the "recommendations" to make it easier to swap out different recommender implementations quickly. Stop recommender from including the video that's being watched. Ensure always 5 recommendations * Treat recommendations as a stream of values, rather than a single async value. * Prioritize readability over HTTP response size early-optimization. * Simplify pipe
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.ts39
1 files changed, 39 insertions, 0 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
new file mode 100644
index 000000000..708d67699
--- /dev/null
+++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
@@ -0,0 +1,39 @@
1import { Inject, Injectable } from '@angular/core'
2import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
3import { Video } from '@app/shared/video/video.model'
4import { VideoService, VideosProvider } from '@app/shared/video/video.service'
5import { map } from 'rxjs/operators'
6import { Observable } from 'rxjs'
7
8/**
9 * Provides "recommendations" by providing the most recently uploaded videos.
10 */
11@Injectable()
12export class RecentVideosRecommendationService implements RecommendationService {
13
14 readonly pageSize = 5
15
16 constructor (
17 @Inject(VideoService) private videos: VideosProvider
18 ) {
19 }
20
21 getRecommendations (uuid: string): Observable<Video[]> {
22 return this.fetchPage(1)
23 .pipe(
24 map(vids => {
25 const otherVideos = vids.filter(v => v.uuid !== uuid)
26 return otherVideos.slice(0, this.pageSize)
27 })
28 )
29 }
30
31 private fetchPage (page: number): Observable<Video[]> {
32 let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 }
33 return this.videos.getVideos(pagination, '-createdAt')
34 .pipe(
35 map(v => v.videos)
36 )
37 }
38
39}