]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-comment.ts
Fix embed on mastodon
[github/Chocobozzz/PeerTube.git] / server / models / video / video-comment.ts
index 869a42afef0f14197fa8bf4643c7e87058651017..fb4d16b4d17b878f595f3e8c2c5482abf0b59138 100644 (file)
@@ -6,7 +6,7 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp
 import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
 import { AccountModel } from '../account/account'
 import { ActorModel } from '../activitypub/actor'
-import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils'
+import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { VideoChannelModel } from './video-channel'
 import { getServerActor } from '../../helpers/utils'
@@ -56,6 +56,19 @@ enum ScopeNames {
               ')'
             ),
             'totalReplies'
+          ],
+          [
+            Sequelize.literal(
+              '(' +
+                'SELECT COUNT("replies"."id") ' +
+                'FROM "videoComment" AS "replies" ' +
+                'INNER JOIN "video" ON "video"."id" = "replies"."videoId" ' +
+                'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+                'WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ' +
+                'AND "replies"."accountId" = "videoChannel"."accountId"' +
+              ')'
+            ),
+            'totalRepliesFromVideoAuthor'
           ]
         ]
       }
@@ -259,7 +272,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
     const query = {
       offset: start,
       limit: count,
-      order: getSort(sort),
+      order: getCommentSort(sort),
       where: {
         videoId,
         inReplyToCommentId: null,
@@ -501,6 +514,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
       updatedAt: this.updatedAt,
       deletedAt: this.deletedAt,
       isDeleted: this.isDeleted(),
+      totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0,
       totalReplies: this.get('totalReplies') || 0,
       account: this.Account ? this.Account.toFormattedJSON() : null
     } as VideoComment