From 4cb6d4578893db310297d7e118ce2fb7ecb952a3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Jan 2018 11:19:16 +0100 Subject: Add ability to delete comments --- server/lib/activitypub/process/process-delete.ts | 33 +++++++++++++++++++++--- server/lib/activitypub/send/send-delete.ts | 16 +++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 523a31822..604570e74 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts @@ -6,6 +6,7 @@ import { AccountModel } from '../../../models/account/account' import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' import { VideoChannelModel } from '../../../models/video/video-channel' +import { VideoCommentModel } from '../../../models/video/video-comment' import { getOrCreateActorAndServerAndModel } from '../actor' async function processDeleteActivity (activity: ActivityDelete) { @@ -24,9 +25,16 @@ async function processDeleteActivity (activity: ActivityDelete) { } { - let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id) - if (videoObject !== undefined) { - return processDeleteVideo(actor, videoObject) + const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id) + if (videoCommentInstance) { + return processDeleteVideoComment(actor, videoCommentInstance) + } + } + + { + const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id) + if (videoInstance) { + return processDeleteVideo(actor, videoInstance) } } @@ -101,3 +109,22 @@ async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid) } + +async function processDeleteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) { + const options = { + arguments: [ actor, videoComment ], + errorMessage: 'Cannot remove the remote video comment with many retries.' + } + + await retryTransactionWrapper(deleteRemoteVideoComment, options) +} + +function deleteRemoteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) { + logger.debug('Removing remote video comment "%s".', videoComment.url) + + return sequelizeTypescript.transaction(async t => { + await videoComment.destroy({ transaction: t }) + + logger.info('Remote video comment %s removed.', videoComment.url) + }) +} diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 4bc5db77e..1ca031898 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts @@ -2,6 +2,7 @@ import { Transaction } from 'sequelize' import { ActivityDelete } from '../../../../shared/models/activitypub' import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' +import { VideoCommentModel } from '../../../models/video/video-comment' import { VideoShareModel } from '../../../models/video/video-share' import { broadcastToFollowers } from './misc' @@ -22,11 +23,24 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) { return broadcastToFollowers(data, byActor, [ byActor ], t) } +async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { + const byActor = videoComment.Account.Actor + + const data = deleteActivityData(videoComment.url, byActor) + + const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t) + actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor) + actorsInvolved.push(byActor) + + return broadcastToFollowers(data, byActor, actorsInvolved, t) +} + // --------------------------------------------------------------------------- export { sendDeleteVideo, - sendDeleteActor + sendDeleteActor, + sendDeleteVideoComment } // --------------------------------------------------------------------------- -- cgit v1.2.3