Verified Commit a68ccaea authored by Chocobozzz's avatar Chocobozzz
Browse files

(breaking): Always list nsfw videos in playlists

Keep the same behaviour as unlisted videos
The frontend is in charge to blur the video element if the nsfw setting
is "hide" or "blur"
parent 789ba349
......@@ -15,7 +15,7 @@ import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/vid
import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
import { resetSequelizeInstance } from '../../helpers/database-utils'
import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils'
import { createReqFiles } from '../../helpers/express-utils'
import { logger } from '../../helpers/logger'
import { getFormattedObjects } from '../../helpers/utils'
import { CONFIG } from '../../initializers/config'
......@@ -474,10 +474,7 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
'filter:api.video-playlist.videos.list.result'
)
const options = {
displayNSFW: buildNSFWFilter(res, req.query.nsfw),
accountId: user ? user.Account.id : undefined
}
const options = { accountId: user?.Account?.id }
return res.json(getFormattedObjects(resultList.data, resultList.total, options))
}
......
......@@ -309,7 +309,23 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
return VideoPlaylistElementModel.increment({ position: by }, query)
}
getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
toFormattedJSON (
this: MVideoPlaylistElementFormattable,
options: { accountId?: number } = {}
): VideoPlaylistElement {
return {
id: this.id,
position: this.position,
startTimestamp: this.startTimestamp,
stopTimestamp: this.stopTimestamp,
type: this.getType(options.accountId),
video: this.getVideoElement(options.accountId)
}
}
getType (this: MVideoPlaylistElementFormattable, accountId?: number) {
const video = this.Video
if (!video) return VideoPlaylistElementType.DELETED
......@@ -323,34 +339,17 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
if (video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL) return VideoPlaylistElementType.PRIVATE
if (video.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE
if (video.nsfw === true && displayNSFW === false) return VideoPlaylistElementType.UNAVAILABLE
return VideoPlaylistElementType.REGULAR
}
getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
getVideoElement (this: MVideoPlaylistElementFormattable, accountId?: number) {
if (!this.Video) return null
if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null
if (this.getType(accountId) !== VideoPlaylistElementType.REGULAR) return null
return this.Video.toFormattedJSON()
}
toFormattedJSON (
this: MVideoPlaylistElementFormattable,
options: { displayNSFW?: boolean, accountId?: number } = {}
): VideoPlaylistElement {
return {
id: this.id,
position: this.position,
startTimestamp: this.startTimestamp,
stopTimestamp: this.stopTimestamp,
type: this.getType(options.displayNSFW, options.accountId),
video: this.getVideoElement(options.displayNSFW, options.accountId)
}
}
toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject {
const base: PlaylistElementObject = {
id: this.url,
......
......@@ -3,6 +3,7 @@
import { expect } from 'chai'
import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
import { uuidToShort } from '@shared/extra-utils'
import {
HttpStatusCode,
VideoPlaylist,
......@@ -23,7 +24,6 @@ import {
setDefaultVideoChannel,
waitJobs
} from '@shared/server-commands'
import { uuidToShort } from '@shared/extra-utils'
async function checkPlaylistElementType (
servers: PeerTubeServer[],
......@@ -752,19 +752,6 @@ describe('Test video playlists', function () {
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
})
it('Should hide the video if it is NSFW', async function () {
const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
expect(body.total).to.equal(3)
const elements = body.data
const element = elements.find(e => e.position === 3)
expect(element).to.exist
expect(element.video).to.be.null
expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
})
})
describe('Managing playlist elements', function () {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment