Refactor a little bit nsfwPolicyToParam
This commit is contained in:
parent
65bb29c6d3
commit
3193ac2c3b
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) })
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue