diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/models/utils.ts | 14 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 4 |
3 files changed, 17 insertions, 3 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 79fcd0edf..1b7b94d74 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -46,7 +46,7 @@ const SORTABLE_COLUMNS = { | |||
46 | VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ], | 46 | VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ], |
47 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], | 47 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], |
48 | VIDEO_IMPORTS: [ 'createdAt' ], | 48 | VIDEO_IMPORTS: [ 'createdAt' ], |
49 | VIDEO_COMMENT_THREADS: [ 'createdAt' ], | 49 | VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ], |
50 | VIDEO_RATES: [ 'createdAt' ], | 50 | VIDEO_RATES: [ 'createdAt' ], |
51 | BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], | 51 | BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], |
52 | FOLLOWERS: [ 'createdAt', 'state', 'score' ], | 52 | FOLLOWERS: [ 'createdAt', 'state', 'score' ], |
diff --git a/server/models/utils.ts b/server/models/utils.ts index b53a52a05..4199cc443 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -22,6 +22,19 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt | |||
22 | return [ [ finalField, direction ], lastSort ] | 22 | return [ [ finalField, direction ], lastSort ] |
23 | } | 23 | } |
24 | 24 | ||
25 | function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { | ||
26 | const { direction, field } = buildDirectionAndField(value) | ||
27 | |||
28 | if (field === 'totalReplies') { | ||
29 | return [ | ||
30 | [ Sequelize.literal('"totalReplies"'), direction ], | ||
31 | lastSort | ||
32 | ] | ||
33 | } | ||
34 | |||
35 | return getSort(value, lastSort) | ||
36 | } | ||
37 | |||
25 | function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { | 38 | function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { |
26 | const { direction, field } = buildDirectionAndField(value) | 39 | const { direction, field } = buildDirectionAndField(value) |
27 | 40 | ||
@@ -167,6 +180,7 @@ export { | |||
167 | SortType, | 180 | SortType, |
168 | buildLocalAccountIdsIn, | 181 | buildLocalAccountIdsIn, |
169 | getSort, | 182 | getSort, |
183 | getCommentSort, | ||
170 | getVideoSort, | 184 | getVideoSort, |
171 | getBlacklistSort, | 185 | getBlacklistSort, |
172 | createSimilarityAttribute, | 186 | createSimilarityAttribute, |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 869a42afe..28f011b03 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -6,7 +6,7 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp | |||
6 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' | 6 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' |
7 | import { AccountModel } from '../account/account' | 7 | import { AccountModel } from '../account/account' |
8 | import { ActorModel } from '../activitypub/actor' | 8 | import { ActorModel } from '../activitypub/actor' |
9 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' | 9 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' |
10 | import { VideoModel } from './video' | 10 | import { VideoModel } from './video' |
11 | import { VideoChannelModel } from './video-channel' | 11 | import { VideoChannelModel } from './video-channel' |
12 | import { getServerActor } from '../../helpers/utils' | 12 | import { getServerActor } from '../../helpers/utils' |
@@ -259,7 +259,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
259 | const query = { | 259 | const query = { |
260 | offset: start, | 260 | offset: start, |
261 | limit: count, | 261 | limit: count, |
262 | order: getSort(sort), | 262 | order: getCommentSort(sort), |
263 | where: { | 263 | where: { |
264 | videoId, | 264 | videoId, |
265 | inReplyToCommentId: null, | 265 | inReplyToCommentId: null, |