diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-17 15:52:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-18 11:35:50 +0100 |
commit | 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 (patch) | |
tree | 5e3392af5592d1401ada86d21f93bb7ad9da8ab1 /server/models/video | |
parent | 583cd0d2129dc855e599f981d70e537feade1632 (diff) | |
download | PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.gz PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.zst PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.zip |
Add history on server side
Add ability to disable, clear and list user videos history
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video.ts | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index adef37937..199ea9ea4 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -153,7 +153,8 @@ type AvailableForListIDsOptions = { | |||
153 | accountId?: number | 153 | accountId?: number |
154 | videoChannelId?: number | 154 | videoChannelId?: number |
155 | trendingDays?: number | 155 | trendingDays?: number |
156 | user?: UserModel | 156 | user?: UserModel, |
157 | historyOfUser?: UserModel | ||
157 | } | 158 | } |
158 | 159 | ||
159 | @Scopes({ | 160 | @Scopes({ |
@@ -416,6 +417,16 @@ type AvailableForListIDsOptions = { | |||
416 | query.subQuery = false | 417 | query.subQuery = false |
417 | } | 418 | } |
418 | 419 | ||
420 | if (options.historyOfUser) { | ||
421 | query.include.push({ | ||
422 | model: UserVideoHistoryModel, | ||
423 | required: true, | ||
424 | where: { | ||
425 | userId: options.historyOfUser.id | ||
426 | } | ||
427 | }) | ||
428 | } | ||
429 | |||
419 | return query | 430 | return query |
420 | }, | 431 | }, |
421 | [ ScopeNames.WITH_ACCOUNT_DETAILS ]: { | 432 | [ ScopeNames.WITH_ACCOUNT_DETAILS ]: { |
@@ -987,7 +998,8 @@ export class VideoModel extends Model<VideoModel> { | |||
987 | videoChannelId?: number, | 998 | videoChannelId?: number, |
988 | followerActorId?: number | 999 | followerActorId?: number |
989 | trendingDays?: number, | 1000 | trendingDays?: number, |
990 | user?: UserModel | 1001 | user?: UserModel, |
1002 | historyOfUser?: UserModel | ||
991 | }, countVideos = true) { | 1003 | }, countVideos = true) { |
992 | if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1004 | if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { |
993 | throw new Error('Try to filter all-local but no user has not the see all videos right') | 1005 | throw new Error('Try to filter all-local but no user has not the see all videos right') |
@@ -1026,6 +1038,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1026 | videoChannelId: options.videoChannelId, | 1038 | videoChannelId: options.videoChannelId, |
1027 | includeLocalVideos: options.includeLocalVideos, | 1039 | includeLocalVideos: options.includeLocalVideos, |
1028 | user: options.user, | 1040 | user: options.user, |
1041 | historyOfUser: options.historyOfUser, | ||
1029 | trendingDays | 1042 | trendingDays |
1030 | } | 1043 | } |
1031 | 1044 | ||
@@ -1341,7 +1354,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1341 | } | 1354 | } |
1342 | 1355 | ||
1343 | const [ count, rowsId ] = await Promise.all([ | 1356 | const [ count, rowsId ] = await Promise.all([ |
1344 | countVideos ? VideoModel.scope(countScope).count(countQuery) : Promise.resolve(undefined), | 1357 | countVideos ? VideoModel.scope(countScope).count(countQuery) : Promise.resolve<number>(undefined), |
1345 | VideoModel.scope(idsScope).findAll(query) | 1358 | VideoModel.scope(idsScope).findAll(query) |
1346 | ]) | 1359 | ]) |
1347 | const ids = rowsId.map(r => r.id) | 1360 | const ids = rowsId.map(r => r.id) |