Skip to content

Commit

Permalink
Fix comment replies count on replies
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Feb 11, 2025
1 parent 3062576 commit 27d1430
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 24 additions & 14 deletions packages/tests/src/api/videos/video-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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' })
Expand All @@ -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()) {
Expand Down Expand Up @@ -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)
}

{
Expand All @@ -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)
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand All @@ -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 `
}

Expand Down

0 comments on commit 27d1430

Please sign in to comment.