-import { getVideoCommentActivityPubUrl } from './activitypub'
-import { sendCreateVideoComment } from './activitypub/send'
-import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight } from '../typings/models'
+import {
+ MAccountDefault,
+ MComment,
+ MCommentFormattable,
+ MCommentOwnerVideo,
+ MCommentOwnerVideoReply,
+ MVideoFullLight
+} from '../types/models'
+import { sendCreateVideoComment, sendDeleteVideoComment } from './activitypub/send'
+import { getLocalVideoCommentActivityPubUrl } from './activitypub/url'
+import { Hooks } from './plugins/hooks'
+
+async function removeComment (commentArg: MComment, req: express.Request, res: express.Response) {
+ let videoCommentInstanceBefore: MCommentOwnerVideo
+
+ await sequelizeTypescript.transaction(async t => {
+ const comment = await VideoCommentModel.loadByUrlAndPopulateAccountAndVideo(commentArg.url, t)
+
+ videoCommentInstanceBefore = cloneDeep(comment)
+
+ if (comment.isOwned() || comment.Video.isOwned()) {
+ await sendDeleteVideoComment(comment, t)
+ }
+
+ comment.markAsDeleted()
+
+ await comment.save({ transaction: t })
+
+ logger.info('Video comment %d deleted.', comment.id)
+ })
+
+ Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore, req, res })
+}