mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Emit that chapters are updated after transaction
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user