diff options
Diffstat (limited to 'server/models/video/video.ts')
-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) |