2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityDelete } from '../../../../shared/models/activitypub'
|
2017-12-28 04:16:08 -06:00
|
|
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { sequelizeTypescript } from '../../../initializers'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
|
|
|
import { VideoChannelModel } from '../../../models/video/video-channel'
|
2018-01-04 04:19:16 -06:00
|
|
|
import { VideoCommentModel } from '../../../models/video/video-comment'
|
2018-10-02 04:33:18 -05:00
|
|
|
import { forwardVideoRelatedActivity } from '../send/utils'
|
2019-03-05 03:58:44 -06:00
|
|
|
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
|
2019-08-02 03:53:36 -05:00
|
|
|
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
|
|
|
|
|
|
|
|
async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
|
|
|
|
const { activity, byActor } = options
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2018-01-04 10:50:30 -06:00
|
|
|
const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2018-01-18 03:53:54 -06:00
|
|
|
if (activity.actor === objectUrl) {
|
2018-09-19 07:44:20 -05:00
|
|
|
// We need more attributes (all the account and channel)
|
|
|
|
const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url)
|
2018-01-18 03:53:54 -06:00
|
|
|
|
2018-09-19 07:44:20 -05:00
|
|
|
if (byActorFull.type === 'Person') {
|
|
|
|
if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.')
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2018-09-19 07:44:20 -05:00
|
|
|
byActorFull.Account.Actor = await byActorFull.Account.$get('Actor') as ActorModel
|
|
|
|
return retryTransactionWrapper(processDeleteAccount, byActorFull.Account)
|
|
|
|
} else if (byActorFull.type === 'Group') {
|
|
|
|
if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.')
|
2017-12-14 10:38:41 -06:00
|
|
|
|
2018-09-19 07:44:20 -05:00
|
|
|
byActorFull.VideoChannel.Actor = await byActorFull.VideoChannel.$get('Actor') as ActorModel
|
|
|
|
return retryTransactionWrapper(processDeleteVideoChannel, byActorFull.VideoChannel)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-01-04 10:50:30 -06:00
|
|
|
const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl)
|
2018-01-04 04:19:16 -06:00
|
|
|
if (videoCommentInstance) {
|
2018-09-19 07:44:20 -05:00
|
|
|
return retryTransactionWrapper(processDeleteVideoComment, byActor, videoCommentInstance, activity)
|
2018-01-04 04:19:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-01-04 10:50:30 -06:00
|
|
|
const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl)
|
2018-01-04 04:19:16 -06:00
|
|
|
if (videoInstance) {
|
2018-09-14 09:51:35 -05:00
|
|
|
if (videoInstance.isOwned()) throw new Error(`Remote instance cannot delete owned video ${videoInstance.url}.`)
|
|
|
|
|
2018-09-19 07:44:20 -05:00
|
|
|
return retryTransactionWrapper(processDeleteVideo, byActor, videoInstance)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 03:58:44 -06:00
|
|
|
{
|
|
|
|
const videoPlaylist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(objectUrl)
|
|
|
|
if (videoPlaylist) {
|
|
|
|
if (videoPlaylist.isOwned()) throw new Error(`Remote instance cannot delete owned playlist ${videoPlaylist.url}.`)
|
|
|
|
|
|
|
|
return retryTransactionWrapper(processDeleteVideoPlaylist, byActor, videoPlaylist)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 07:55:18 -05:00
|
|
|
return undefined
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processDeleteActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) {
|
2017-11-13 10:39:41 -06:00
|
|
|
logger.debug('Removing remote video "%s".', videoToDelete.uuid)
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
await sequelizeTypescript.transaction(async t => {
|
2017-12-14 10:38:41 -06:00
|
|
|
if (videoToDelete.VideoChannel.Account.Actor.id !== actor.id) {
|
|
|
|
throw new Error('Account ' + actor.url + ' does not own video channel ' + videoToDelete.VideoChannel.Actor.url)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
await videoToDelete.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
|
|
|
|
logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
|
|
|
|
}
|
|
|
|
|
2019-03-05 03:58:44 -06:00
|
|
|
async function processDeleteVideoPlaylist (actor: ActorModel, playlistToDelete: VideoPlaylistModel) {
|
|
|
|
logger.debug('Removing remote video playlist "%s".', playlistToDelete.uuid)
|
|
|
|
|
|
|
|
await sequelizeTypescript.transaction(async t => {
|
|
|
|
if (playlistToDelete.OwnerAccount.Actor.id !== actor.id) {
|
|
|
|
throw new Error('Account ' + actor.url + ' does not own video playlist ' + playlistToDelete.url)
|
|
|
|
}
|
|
|
|
|
|
|
|
await playlistToDelete.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
|
|
|
|
logger.info('Remote video playlist with uuid %s removed.', playlistToDelete.uuid)
|
|
|
|
}
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function processDeleteAccount (accountToRemove: AccountModel) {
|
2019-05-31 07:02:26 -05:00
|
|
|
logger.debug('Removing remote account "%s".', accountToRemove.Actor.url)
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
await sequelizeTypescript.transaction(async t => {
|
2017-12-14 10:38:41 -06:00
|
|
|
await accountToRemove.destroy({ transaction: t })
|
2017-11-13 10:39:41 -06:00
|
|
|
})
|
|
|
|
|
2019-05-31 07:02:26 -05:00
|
|
|
logger.info('Remote account %s removed.', accountToRemove.Actor.url)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) {
|
2019-05-31 07:02:26 -05:00
|
|
|
logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.url)
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
await sequelizeTypescript.transaction(async t => {
|
2017-12-14 10:38:41 -06:00
|
|
|
await videoChannelToRemove.destroy({ transaction: t })
|
2017-11-13 10:39:41 -06:00
|
|
|
})
|
|
|
|
|
2019-05-31 07:02:26 -05:00
|
|
|
logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2018-06-13 07:27:40 -05:00
|
|
|
function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) {
|
2018-01-04 04:19:16 -06:00
|
|
|
logger.debug('Removing remote video comment "%s".', videoComment.url)
|
|
|
|
|
|
|
|
return sequelizeTypescript.transaction(async t => {
|
2018-09-19 08:47:55 -05:00
|
|
|
if (videoComment.Account.id !== byActor.Account.id) {
|
|
|
|
throw new Error('Account ' + byActor.url + ' does not own video comment ' + videoComment.url)
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:19:16 -06:00
|
|
|
await videoComment.destroy({ transaction: t })
|
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
if (videoComment.Video.isOwned()) {
|
|
|
|
// Don't resend the activity to the sender
|
|
|
|
const exceptions = [ byActor ]
|
2018-10-02 04:33:18 -05:00
|
|
|
await forwardVideoRelatedActivity(activity, t, exceptions, videoComment.Video)
|
2018-03-27 03:26:52 -05:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:19:16 -06:00
|
|
|
logger.info('Remote video comment %s removed.', videoComment.url)
|
|
|
|
})
|
|
|
|
}
|