Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Refactor a little bit nsfwPolicyToParam

Chocobozzz3193ac2c3b02
diff --git a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
index 631444398c..2ee168492c 100644
--- a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
+++ b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
@@ -2,10 +2,10 @@ import { from, Subject, Subscription } from 'rxjs'
import { concatMap, map, switchMap, tap } from 'rxjs/operators'
import { Component, OnDestroy, OnInit } from '@angular/core'
import { ComponentPagination, hasMoreItems, MarkdownService, User, UserService } from '@app/core'
+import { SimpleMemoize } from '@app/helpers'
import { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
import { NSFWPolicyType, VideoSortField } from '@shared/models'
-import { SimpleMemoize } from '@app/helpers'
@Component({
selector: 'my-account-video-channels',
@@ -98,7 +98,7 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
videoChannel,
videoPagination: this.videosPagination,
sort: this.videosSort,
- nsfwPolicy: this.nsfwPolicy
+ nsfw: this.videoService.nsfwPolicyToParam(this.nsfwPolicy)
}
return this.videoService.getVideoChannelVideos(options)
diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts
index 8f4594b255..ba0d30f3da 100644
--- a/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts
+++ b/client/src/app/+videos/+video-watch/shared/recommendations/recent-videos-recommendation.service.ts
@@ -43,9 +43,14 @@ export class RecentVideosRecommendationService implements RecommendationService
return this.userService.getAnonymousOrLoggedUser()
.pipe(
switchMap(user => {
+ const nsfw = user.nsfwPolicy
+ ? this.videos.nsfwPolicyToParam(user.nsfwPolicy)
+ : undefined
+
const defaultSubscription = this.videos.getVideos({
videoPagination: pagination,
- sort: '-publishedAt'
+ sort: '-publishedAt',
+ nsfw
}).pipe(map(v => v.data))
const searchIndexConfig = this.config.search.searchIndex
@@ -60,9 +65,7 @@ export class RecentVideosRecommendationService implements RecommendationService
tagsOneOf: recommendation.tags.join(','),
sort: '-publishedAt',
searchTarget: 'local',
- nsfw: user.nsfwPolicy
- ? this.videos.nsfwPolicyToParam(user.nsfwPolicy)
- : undefined,
+ nsfw,
excludeAlreadyWatched: user.id
? true
: undefined
diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
index df7cc95a7f..4f00eabd37 100644
--- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
+++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
@@ -84,7 +84,9 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
return this.userService.getAnonymousOrLoggedUser()
.pipe(
map(user => user.nsfwPolicy),
- switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
+ switchMap(nsfwPolicy => {
+ return this.videoService.getVideoChannelVideos({ ...videoOptions, nsfw: this.videoService.nsfwPolicyToParam(nsfwPolicy) })
+ })
)
}
}
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts
index cd0a300e26..a980c2dcf3 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -47,9 +47,6 @@ export type CommonVideoParams = {
privacyOneOf?: VideoPrivacy[]
isLive?: boolean
skipCount?: boolean
-
- // FIXME: remove?
- nsfwPolicy?: NSFWPolicyType
nsfw?: BooleanBothQuery
}
@@ -499,7 +496,7 @@ export class VideoService {
throw new Error('No highest privacy available')
}
- nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType) {
+ nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType): BooleanBothQuery {
return nsfwPolicy === 'do_not_list'
? 'false'
: 'both'
@@ -534,7 +531,6 @@ export class VideoService {
languageOneOf,
privacyOneOf,
skipCount,
- nsfwPolicy,
isLive,
nsfw
} = options
@@ -551,7 +547,6 @@ export class VideoService {
if (include !== undefined) newParams = newParams.set('include', include)
if (isLive !== undefined) newParams = newParams.set('isLive', isLive)
if (nsfw !== undefined) newParams = newParams.set('nsfw', nsfw)
- if (nsfwPolicy !== undefined) newParams = newParams.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy))
if (languageOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'languageOneOf', languageOneOf)
if (categoryOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'categoryOneOf', categoryOneOf)
if (privacyOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'privacyOneOf', privacyOneOf)