Skip to content

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

Emit that chapters are updated after transaction

Chocobozzz35122160cdd3
diff --git a/server/core/lib/video-chapters.ts b/server/core/lib/video-chapters.ts
index 740493f4ae..de5f15a423 100644
--- a/server/core/lib/video-chapters.ts
+++ b/server/core/lib/video-chapters.ts
@@ -6,6 +6,7 @@ import { MVideoImmutable } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
import { InternalEventEmitter } from './internal-event-emitter.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
+import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
const lTags = loggerTagsFactory('video', 'chapters')
@@ -20,7 +21,9 @@ export async function replaceChapters (options: {
await createChapters({ videoId: video.id, chapters, transaction })
- InternalEventEmitter.Instance.emit('chapters-updated', { video })
+ afterCommitIfTransaction(transaction, () => {
+ InternalEventEmitter.Instance.emit('chapters-updated', { video })
+ })
}
export async function replaceChaptersIfNotExist (options: {
@@ -34,7 +37,9 @@ export async function replaceChaptersIfNotExist (options: {
await createChapters({ videoId: video.id, chapters, transaction })
- InternalEventEmitter.Instance.emit('chapters-updated', { video })
+ afterCommitIfTransaction(transaction, () => {
+ InternalEventEmitter.Instance.emit('chapters-updated', { video })
+ })
}
export async function replaceChaptersFromDescriptionIfNeeded (options: {
@@ -79,10 +84,10 @@ async function createChapters (options: {
}) {
const { chapters, transaction, videoId } = options
- const existingTimecodes = new Set<number>()
+ const existingTimecode = new Set<number>()
for (const chapter of chapters) {
- if (existingTimecodes.has(chapter.timecode)) continue
+ if (existingTimecode.has(chapter.timecode)) continue
await VideoChapterModel.create({
title: chapter.title,
@@ -90,7 +95,7 @@ async function createChapters (options: {
videoId
}, { transaction })
- existingTimecodes.add(chapter.timecode)
+ existingTimecode.add(chapter.timecode)
}
}
diff --git a/server/core/lib/video-comment.ts b/server/core/lib/video-comment.ts
index 731089daa6..fe42b00d81 100644
--- a/server/core/lib/video-comment.ts
+++ b/server/core/lib/video-comment.ts
@@ -21,6 +21,7 @@ import { AutomaticTagger } from './automatic-tags/automatic-tagger.js'
import { setAndSaveCommentAutomaticTags } from './automatic-tags/automatic-tags.js'
import { Notifier } from './notifier/notifier.js'
import { Hooks } from './plugins/hooks.js'
+import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
export async function removeComment (commentArg: MComment, req: express.Request, res: express.Response) {
let videoCommentInstanceBefore: MCommentOwnerVideo
@@ -56,11 +57,11 @@ export async function approveComment (commentArg: MComment) {
if (comment.isLocal()) {
await sendCreateVideoCommentIfNeeded(comment, t)
} else {
- sendReplyApproval(comment, 'ApproveReply')
+ afterCommitIfTransaction(t, () => sendReplyApproval(comment, 'ApproveReply'))
}
if (oldHeldForReview !== comment.heldForReview) {
- Notifier.Instance.notifyOnNewCommentApproval(comment)
+ afterCommitIfTransaction(t, () => Notifier.Instance.notifyOnNewCommentApproval(comment))
}
logger.info('Video comment %d approved.', comment.id)