Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix comment replies count on replies

Chocobozzz27d14308e5a8
diff --git a/client/src/app/shared/shared-forms/select/select-options.component.ts b/client/src/app/shared/shared-forms/select/select-options.component.ts
index 719eb6c830..fff8b68e32 100644
--- a/client/src/app/shared/shared-forms/select/select-options.component.ts
+++ b/client/src/app/shared/shared-forms/select/select-options.component.ts
@@ -68,7 +68,7 @@ export class SelectOptionsComponent implements AfterContentInit, ControlValueAcc
// Allow plugins to update our value
@HostListener('change', [ '$event.target' ])
handleChange (target: HTMLInputElement) {
- // Prevent the primeng search input to out value
+ // Prevent the primeng search input to update our value
if (target.role === 'searchbox') return
this.writeValue(target.value)
diff --git a/packages/tests/src/api/videos/video-comments.ts b/packages/tests/src/api/videos/video-comments.ts
index 9bbeb0fcec..d93cbb43f3 100644
--- a/packages/tests/src/api/videos/video-comments.ts
+++ b/packages/tests/src/api/videos/video-comments.ts
@@ -238,11 +238,20 @@ describe('Test video comments', function () {
await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 })
const text3 = 'my second answer to thread 4'
- await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
+ await command.addReply({ videoId, toCommentId: threadId2, token: userAccessTokenServer1, text: text3 })
+ await command.addReplyToLastReply({ text: 'third answer' })
const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
expect(tree.comment.totalRepliesFromVideoAuthor).to.equal(1)
- expect(tree.comment.totalReplies).to.equal(2)
+ expect(tree.comment.totalReplies).to.equal(3)
+
+ const reply1 = tree.children.find(c => c.comment.text === text2)
+ expect(reply1.comment.totalReplies).to.equal(0)
+ expect(reply1.comment.totalRepliesFromVideoAuthor).to.equal(0)
+
+ const reply2 = tree.children.find(c => c.comment.text === text3)
+ expect(reply2.comment.totalReplies).to.equal(1)
+ expect(reply2.comment.totalRepliesFromVideoAuthor).to.equal(1)
})
})
@@ -257,9 +266,9 @@ describe('Test video comments', function () {
for (const fn of listFunctions()) {
const { data, total } = await fn({ start: 0, count: 1 })
- expect(total).to.equal(7)
+ expect(total).to.equal(8)
expect(data).to.have.lengthOf(1)
- expect(data[0].text).to.equal('my second answer to thread 4')
+ expect(data[0].text).to.equal('third answer')
expect(data[0].account.name).to.equal('root')
expect(data[0].account.displayName).to.equal('root')
expect(data[0].account.avatars).to.have.lengthOf(4)
@@ -268,7 +277,7 @@ describe('Test video comments', function () {
for (const fn of listFunctions()) {
const { data, total } = await fn({ start: 1, count: 2 })
- expect(total).to.equal(7)
+ expect(total).to.equal(8)
expect(data).to.have.lengthOf(2)
expect(data[0].account.avatars).to.have.lengthOf(4)
@@ -307,10 +316,11 @@ describe('Test video comments', function () {
for (const fn of listFunctions()) {
const { total, data } = await fn({ searchAccount: 'user' })
- expect(data).to.have.lengthOf(1)
- expect(total).to.equal(1)
+ expect(data).to.have.lengthOf(2)
+ expect(total).to.equal(2)
- expect(data[0].text).to.equal('a first answer to thread 4 by a third party')
+ expect(data[0].text).to.equal('my second answer to thread 4')
+ expect(data[1].text).to.equal('a first answer to thread 4 by a third party')
}
const { data, total } = await command.listCommentsOnMyVideos({ token: userAccessTokenServer1, searchAccount: 'user' })
@@ -322,8 +332,8 @@ describe('Test video comments', function () {
for (const fn of listFunctions()) {
const { total, data } = await fn({ searchVideo: 'video' })
- expect(data).to.have.lengthOf(7)
- expect(total).to.equal(7)
+ expect(data).to.have.lengthOf(8)
+ expect(total).to.equal(8)
}
for (const fn of listFunctions()) {
@@ -358,8 +368,8 @@ describe('Test video comments', function () {
{
const { total, data } = await command.listForAdmin({ videoId: videoUUID })
- expect(data).to.have.lengthOf(7)
- expect(total).to.equal(7)
+ expect(data).to.have.lengthOf(8)
+ expect(total).to.equal(8)
}
{
@@ -377,8 +387,8 @@ describe('Test video comments', function () {
{
const { total, data } = await command.listForAdmin({ videoChannelId: rootChannels[0].id })
- expect(data).to.have.lengthOf(7)
- expect(total).to.equal(7)
+ expect(data).to.have.lengthOf(8)
+ expect(total).to.equal(8)
}
{
diff --git a/server/core/models/video/sql/comment/video-comment-list-query-builder.ts b/server/core/models/video/sql/comment/video-comment-list-query-builder.ts
index a3f98e7eb5..906a8889fb 100644
--- a/server/core/models/video/sql/comment/video-comment-list-query-builder.ts
+++ b/server/core/models/video/sql/comment/video-comment-list-query-builder.ts
@@ -414,7 +414,7 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
`SELECT COUNT("replies"."id") AS "count" FROM "videoComment" AS "replies" ` +
`INNER JOIN "video" ON "video"."id" = "replies"."videoId" AND "replies"."videoId" = :videoId ` +
`LEFT JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` +
- `WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ` +
+ `WHERE ("replies"."inReplyToCommentId" = "VideoCommentModel"."id" OR "replies"."originCommentId" = "VideoCommentModel"."id") ` +
`AND "deletedAt" IS NULL ` +
`AND ${blockWhereString} ` +
`) "totalReplies" ON TRUE `
@@ -428,7 +428,8 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
`SELECT COUNT("replies"."id") AS "count" FROM "videoComment" AS "replies" ` +
`INNER JOIN "video" ON "video"."id" = "replies"."videoId" AND "replies"."videoId" = :videoId ` +
`INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ` +
- `WHERE "replies"."originCommentId" = "VideoCommentModel"."id" AND "replies"."accountId" = "videoChannel"."accountId"` +
+ `WHERE ("replies"."inReplyToCommentId" = "VideoCommentModel"."id" OR "replies"."originCommentId" = "VideoCommentModel"."id") ` +
+ `AND "replies"."accountId" = "videoChannel"."accountId"` +
`) "totalRepliesFromVideoAuthor" ON TRUE `
}