From 6aa541481390980f9c85d2e66514ba0e6ce77a35 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Tue, 24 Sep 2019 08:48:01 +0200 Subject: Autoplay next recommended video (#2137) * Start working on autoplay of next video * Ignore changes made by gitpod * Apply changes from PR#1370 * Correct the spelling of recommendations * Fix linting errors * Move boolean check to existing onEnded handler * Pick a random video until the recommendations are improved * Add simple tests for autoPlayNextVideo * Fix lint ...again --- server/controllers/api/users/me.ts | 1 + server/helpers/custom-validators/users.ts | 5 +++++ server/models/account/user.ts | 8 ++++++++ server/tests/api/check-params/users.ts | 8 ++++++++ server/tests/api/users/users.ts | 13 +++++++++++++ 5 files changed, 35 insertions(+) (limited to 'server') diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index bf872ca52..cfc346c35 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -175,6 +175,7 @@ async function updateMe (req: express.Request, res: express.Response) { if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo + if (body.autoPlayNextVideo !== undefined) user.autoPlayNextVideo = body.autoPlayNextVideo if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled if (body.videoLanguages !== undefined) user.videoLanguages = body.videoLanguages if (body.theme !== undefined) user.theme = body.theme diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 68e84d9eb..16a95f120 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -65,6 +65,10 @@ function isUserBlockedValid (value: any) { return isBooleanValid(value) } +function isUserAutoPlayNextVideoValid (value: any) { + return isBooleanValid(value) +} + function isNoInstanceConfigWarningModal (value: any) { return isBooleanValid(value) } @@ -106,6 +110,7 @@ export { isUserNSFWPolicyValid, isUserWebTorrentEnabledValid, isUserAutoPlayVideoValid, + isUserAutoPlayNextVideoValid, isUserDisplayNameValid, isUserDescriptionValid, isNoInstanceConfigWarningModal, diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 451e1fd6b..38c6d474a 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -25,6 +25,7 @@ import { isNoInstanceConfigWarningModal, isUserAdminFlagsValid, isUserAutoPlayVideoValid, + isUserAutoPlayNextVideoValid, isUserBlockedReasonValid, isUserBlockedValid, isUserEmailVerifiedValid, @@ -160,6 +161,12 @@ export class UserModel extends Model { @Column autoPlayVideo: boolean + @AllowNull(false) + @Default(false) + @Is('UserAutoPlayNextVideo', value => throwIfNotValid(value, isUserAutoPlayNextVideoValid, 'auto play next video boolean')) + @Column + autoPlayNextVideo: boolean + @AllowNull(true) @Default(null) @Is('UserVideoLanguages', value => throwIfNotValid(value, isUserVideoLanguages, 'video languages')) @@ -597,6 +604,7 @@ export class UserModel extends Model { webTorrentEnabled: this.webTorrentEnabled, videosHistoryEnabled: this.videosHistoryEnabled, autoPlayVideo: this.autoPlayVideo, + autoPlayNextVideo: this.autoPlayNextVideo, videoLanguages: this.videoLanguages, role: this.role, diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 9d7ff8984..5d5af284c 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -418,6 +418,14 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) }) + it('Should fail with an invalid autoPlayNextVideo attribute', async function () { + const fields = { + autoPlayNextVideo: -1 + } + + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + }) + it('Should fail with an invalid videosHistoryEnabled attribute', async function () { const fields = { videosHistoryEnabled: -1 diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 95b1bb626..ca06942e7 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -481,6 +481,19 @@ describe('Test users', function () { expect(user.autoPlayVideo).to.be.false }) + it('Should be able to change the autoPlayNextVideo attribute', async function () { + await updateMyUser({ + url: server.url, + accessToken: accessTokenUser, + autoPlayNextVideo: true + }) + + const res = await getMyUserInformation(server.url, accessTokenUser) + const user = res.body + + expect(user.autoPlayNextVideo).to.be.true + }) + it('Should be able to change the email attribute', async function () { await updateMyUser({ url: server.url, -- cgit v1.2.3