mirror of https://github.com/Chocobozzz/PeerTube
Refactor a little bit nsfwPolicyToParam
parent
65bb29c6d3
commit
3193ac2c3b
|
@ -2,10 +2,10 @@ import { from, Subject, Subscription } from 'rxjs'
|
||||||
import { concatMap, map, switchMap, tap } from 'rxjs/operators'
|
import { concatMap, map, switchMap, tap } from 'rxjs/operators'
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core'
|
import { Component, OnDestroy, OnInit } from '@angular/core'
|
||||||
import { ComponentPagination, hasMoreItems, MarkdownService, User, UserService } from '@app/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 { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
|
||||||
import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
|
import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
|
||||||
import { NSFWPolicyType, VideoSortField } from '@shared/models'
|
import { NSFWPolicyType, VideoSortField } from '@shared/models'
|
||||||
import { SimpleMemoize } from '@app/helpers'
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-account-video-channels',
|
selector: 'my-account-video-channels',
|
||||||
|
@ -98,7 +98,7 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
|
||||||
videoChannel,
|
videoChannel,
|
||||||
videoPagination: this.videosPagination,
|
videoPagination: this.videosPagination,
|
||||||
sort: this.videosSort,
|
sort: this.videosSort,
|
||||||
nsfwPolicy: this.nsfwPolicy
|
nsfw: this.videoService.nsfwPolicyToParam(this.nsfwPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.videoService.getVideoChannelVideos(options)
|
return this.videoService.getVideoChannelVideos(options)
|
||||||
|
|
|
@ -43,9 +43,14 @@ export class RecentVideosRecommendationService implements RecommendationService
|
||||||
return this.userService.getAnonymousOrLoggedUser()
|
return this.userService.getAnonymousOrLoggedUser()
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(user => {
|
switchMap(user => {
|
||||||
|
const nsfw = user.nsfwPolicy
|
||||||
|
? this.videos.nsfwPolicyToParam(user.nsfwPolicy)
|
||||||
|
: undefined
|
||||||
|
|
||||||
const defaultSubscription = this.videos.getVideos({
|
const defaultSubscription = this.videos.getVideos({
|
||||||
videoPagination: pagination,
|
videoPagination: pagination,
|
||||||
sort: '-publishedAt'
|
sort: '-publishedAt',
|
||||||
|
nsfw
|
||||||
}).pipe(map(v => v.data))
|
}).pipe(map(v => v.data))
|
||||||
|
|
||||||
const searchIndexConfig = this.config.search.searchIndex
|
const searchIndexConfig = this.config.search.searchIndex
|
||||||
|
@ -60,9 +65,7 @@ export class RecentVideosRecommendationService implements RecommendationService
|
||||||
tagsOneOf: recommendation.tags.join(','),
|
tagsOneOf: recommendation.tags.join(','),
|
||||||
sort: '-publishedAt',
|
sort: '-publishedAt',
|
||||||
searchTarget: 'local',
|
searchTarget: 'local',
|
||||||
nsfw: user.nsfwPolicy
|
nsfw,
|
||||||
? this.videos.nsfwPolicyToParam(user.nsfwPolicy)
|
|
||||||
: undefined,
|
|
||||||
excludeAlreadyWatched: user.id
|
excludeAlreadyWatched: user.id
|
||||||
? true
|
? true
|
||||||
: undefined
|
: undefined
|
||||||
|
|
|
@ -84,7 +84,9 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
|
||||||
return this.userService.getAnonymousOrLoggedUser()
|
return this.userService.getAnonymousOrLoggedUser()
|
||||||
.pipe(
|
.pipe(
|
||||||
map(user => user.nsfwPolicy),
|
map(user => user.nsfwPolicy),
|
||||||
switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
|
switchMap(nsfwPolicy => {
|
||||||
|
return this.videoService.getVideoChannelVideos({ ...videoOptions, nsfw: this.videoService.nsfwPolicyToParam(nsfwPolicy) })
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,6 @@ export type CommonVideoParams = {
|
||||||
privacyOneOf?: VideoPrivacy[]
|
privacyOneOf?: VideoPrivacy[]
|
||||||
isLive?: boolean
|
isLive?: boolean
|
||||||
skipCount?: boolean
|
skipCount?: boolean
|
||||||
|
|
||||||
// FIXME: remove?
|
|
||||||
nsfwPolicy?: NSFWPolicyType
|
|
||||||
nsfw?: BooleanBothQuery
|
nsfw?: BooleanBothQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +496,7 @@ export class VideoService {
|
||||||
throw new Error('No highest privacy available')
|
throw new Error('No highest privacy available')
|
||||||
}
|
}
|
||||||
|
|
||||||
nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType) {
|
nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType): BooleanBothQuery {
|
||||||
return nsfwPolicy === 'do_not_list'
|
return nsfwPolicy === 'do_not_list'
|
||||||
? 'false'
|
? 'false'
|
||||||
: 'both'
|
: 'both'
|
||||||
|
@ -534,7 +531,6 @@ export class VideoService {
|
||||||
languageOneOf,
|
languageOneOf,
|
||||||
privacyOneOf,
|
privacyOneOf,
|
||||||
skipCount,
|
skipCount,
|
||||||
nsfwPolicy,
|
|
||||||
isLive,
|
isLive,
|
||||||
nsfw
|
nsfw
|
||||||
} = options
|
} = options
|
||||||
|
@ -551,7 +547,6 @@ export class VideoService {
|
||||||
if (include !== undefined) newParams = newParams.set('include', include)
|
if (include !== undefined) newParams = newParams.set('include', include)
|
||||||
if (isLive !== undefined) newParams = newParams.set('isLive', isLive)
|
if (isLive !== undefined) newParams = newParams.set('isLive', isLive)
|
||||||
if (nsfw !== undefined) newParams = newParams.set('nsfw', nsfw)
|
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 (languageOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'languageOneOf', languageOneOf)
|
||||||
if (categoryOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'categoryOneOf', categoryOneOf)
|
if (categoryOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'categoryOneOf', categoryOneOf)
|
||||||
if (privacyOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'privacyOneOf', privacyOneOf)
|
if (privacyOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'privacyOneOf', privacyOneOf)
|
||||||
|
|
Loading…
Reference in New Issue