aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorLoveIsGrief <LoveIsGrief@users.noreply.github.com>2019-09-24 08:48:01 +0200
committerChocobozzz <me@florianbigard.com>2019-09-24 08:48:01 +0200
commit6aa541481390980f9c85d2e66514ba0e6ce77a35 (patch)
tree7b2e934647a732645c69e5d05e4b18152b50a6b8 /server
parent32d7f2b754b8d20bf44ae2121c79570cbff973c3 (diff)
downloadPeerTube-6aa541481390980f9c85d2e66514ba0e6ce77a35.tar.gz
PeerTube-6aa541481390980f9c85d2e66514ba0e6ce77a35.tar.zst
PeerTube-6aa541481390980f9c85d2e66514ba0e6ce77a35.zip
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
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/me.ts1
-rw-r--r--server/helpers/custom-validators/users.ts5
-rw-r--r--server/models/account/user.ts8
-rw-r--r--server/tests/api/check-params/users.ts8
-rw-r--r--server/tests/api/users/users.ts13
5 files changed, 35 insertions, 0 deletions
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) {
175 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy 175 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
176 if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled 176 if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled
177 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo 177 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
178 if (body.autoPlayNextVideo !== undefined) user.autoPlayNextVideo = body.autoPlayNextVideo
178 if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled 179 if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled
179 if (body.videoLanguages !== undefined) user.videoLanguages = body.videoLanguages 180 if (body.videoLanguages !== undefined) user.videoLanguages = body.videoLanguages
180 if (body.theme !== undefined) user.theme = body.theme 181 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) {
65 return isBooleanValid(value) 65 return isBooleanValid(value)
66} 66}
67 67
68function isUserAutoPlayNextVideoValid (value: any) {
69 return isBooleanValid(value)
70}
71
68function isNoInstanceConfigWarningModal (value: any) { 72function isNoInstanceConfigWarningModal (value: any) {
69 return isBooleanValid(value) 73 return isBooleanValid(value)
70} 74}
@@ -106,6 +110,7 @@ export {
106 isUserNSFWPolicyValid, 110 isUserNSFWPolicyValid,
107 isUserWebTorrentEnabledValid, 111 isUserWebTorrentEnabledValid,
108 isUserAutoPlayVideoValid, 112 isUserAutoPlayVideoValid,
113 isUserAutoPlayNextVideoValid,
109 isUserDisplayNameValid, 114 isUserDisplayNameValid,
110 isUserDescriptionValid, 115 isUserDescriptionValid,
111 isNoInstanceConfigWarningModal, 116 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 {
25 isNoInstanceConfigWarningModal, 25 isNoInstanceConfigWarningModal,
26 isUserAdminFlagsValid, 26 isUserAdminFlagsValid,
27 isUserAutoPlayVideoValid, 27 isUserAutoPlayVideoValid,
28 isUserAutoPlayNextVideoValid,
28 isUserBlockedReasonValid, 29 isUserBlockedReasonValid,
29 isUserBlockedValid, 30 isUserBlockedValid,
30 isUserEmailVerifiedValid, 31 isUserEmailVerifiedValid,
@@ -160,6 +161,12 @@ export class UserModel extends Model<UserModel> {
160 @Column 161 @Column
161 autoPlayVideo: boolean 162 autoPlayVideo: boolean
162 163
164 @AllowNull(false)
165 @Default(false)
166 @Is('UserAutoPlayNextVideo', value => throwIfNotValid(value, isUserAutoPlayNextVideoValid, 'auto play next video boolean'))
167 @Column
168 autoPlayNextVideo: boolean
169
163 @AllowNull(true) 170 @AllowNull(true)
164 @Default(null) 171 @Default(null)
165 @Is('UserVideoLanguages', value => throwIfNotValid(value, isUserVideoLanguages, 'video languages')) 172 @Is('UserVideoLanguages', value => throwIfNotValid(value, isUserVideoLanguages, 'video languages'))
@@ -597,6 +604,7 @@ export class UserModel extends Model<UserModel> {
597 webTorrentEnabled: this.webTorrentEnabled, 604 webTorrentEnabled: this.webTorrentEnabled,
598 videosHistoryEnabled: this.videosHistoryEnabled, 605 videosHistoryEnabled: this.videosHistoryEnabled,
599 autoPlayVideo: this.autoPlayVideo, 606 autoPlayVideo: this.autoPlayVideo,
607 autoPlayNextVideo: this.autoPlayNextVideo,
600 videoLanguages: this.videoLanguages, 608 videoLanguages: this.videoLanguages,
601 609
602 role: this.role, 610 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 () {
418 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 418 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
419 }) 419 })
420 420
421 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
422 const fields = {
423 autoPlayNextVideo: -1
424 }
425
426 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
427 })
428
421 it('Should fail with an invalid videosHistoryEnabled attribute', async function () { 429 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
422 const fields = { 430 const fields = {
423 videosHistoryEnabled: -1 431 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 () {
481 expect(user.autoPlayVideo).to.be.false 481 expect(user.autoPlayVideo).to.be.false
482 }) 482 })
483 483
484 it('Should be able to change the autoPlayNextVideo attribute', async function () {
485 await updateMyUser({
486 url: server.url,
487 accessToken: accessTokenUser,
488 autoPlayNextVideo: true
489 })
490
491 const res = await getMyUserInformation(server.url, accessTokenUser)
492 const user = res.body
493
494 expect(user.autoPlayNextVideo).to.be.true
495 })
496
484 it('Should be able to change the email attribute', async function () { 497 it('Should be able to change the email attribute', async function () {
485 await updateMyUser({ 498 await updateMyUser({
486 url: server.url, 499 url: server.url,