aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-delete.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-delete.ts')
-rw-r--r--server/lib/activitypub/process/process-delete.ts72
1 files changed, 35 insertions, 37 deletions
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 8f280d37f..65a4e5bcc 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -2,28 +2,30 @@ import { ActivityDelete } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { logger, retryTransactionWrapper } from '../../../helpers'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { AccountModel } from '../../../models/account/account' 4import { AccountModel } from '../../../models/account/account'
5import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
6import { VideoChannelModel } from '../../../models/video/video-channel' 7import { VideoChannelModel } from '../../../models/video/video-channel'
7import { getOrCreateAccountAndServer } from '../account' 8import { getOrCreateActorAndServerAndModel } from '../actor'
8 9
9async function processDeleteActivity (activity: ActivityDelete) { 10async function processDeleteActivity (activity: ActivityDelete) {
10 const account = await getOrCreateAccountAndServer(activity.actor) 11 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
11 12
12 if (account.url === activity.id) { 13 if (actor.url === activity.id) {
13 return processDeleteAccount(account) 14 if (actor.type === 'Person') {
14 } 15 if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
15 16
16 { 17 return processDeleteAccount(actor.Account)
17 let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id) 18 } else if (actor.type === 'Group') {
18 if (videoObject !== undefined) { 19 if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.')
19 return processDeleteVideo(account, videoObject) 20
21 return processDeleteVideoChannel(actor.VideoChannel)
20 } 22 }
21 } 23 }
22 24
23 { 25 {
24 let videoChannelObject = await VideoChannelModel.loadByUrl(activity.id) 26 let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
25 if (videoChannelObject !== undefined) { 27 if (videoObject !== undefined) {
26 return processDeleteVideoChannel(account, videoChannelObject) 28 return processDeleteVideo(actor, videoObject)
27 } 29 }
28 } 30 }
29 31
@@ -38,21 +40,21 @@ export {
38 40
39// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
40 42
41async function processDeleteVideo (account: AccountModel, videoToDelete: VideoModel) { 43async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) {
42 const options = { 44 const options = {
43 arguments: [ account, videoToDelete ], 45 arguments: [ actor, videoToDelete ],
44 errorMessage: 'Cannot remove the remote video with many retries.' 46 errorMessage: 'Cannot remove the remote video with many retries.'
45 } 47 }
46 48
47 await retryTransactionWrapper(deleteRemoteVideo, options) 49 await retryTransactionWrapper(deleteRemoteVideo, options)
48} 50}
49 51
50async function deleteRemoteVideo (account: AccountModel, videoToDelete: VideoModel) { 52async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel) {
51 logger.debug('Removing remote video "%s".', videoToDelete.uuid) 53 logger.debug('Removing remote video "%s".', videoToDelete.uuid)
52 54
53 await sequelizeTypescript.transaction(async t => { 55 await sequelizeTypescript.transaction(async t => {
54 if (videoToDelete.VideoChannel.Account.id !== account.id) { 56 if (videoToDelete.VideoChannel.Account.Actor.id !== actor.id) {
55 throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url) 57 throw new Error('Account ' + actor.url + ' does not own video channel ' + videoToDelete.VideoChannel.Actor.url)
56 } 58 }
57 59
58 await videoToDelete.destroy({ transaction: t }) 60 await videoToDelete.destroy({ transaction: t })
@@ -61,44 +63,40 @@ async function deleteRemoteVideo (account: AccountModel, videoToDelete: VideoMod
61 logger.info('Remote video with uuid %s removed.', videoToDelete.uuid) 63 logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
62} 64}
63 65
64async function processDeleteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) { 66async function processDeleteAccount (accountToRemove: AccountModel) {
65 const options = { 67 const options = {
66 arguments: [ account, videoChannelToRemove ], 68 arguments: [ accountToRemove ],
67 errorMessage: 'Cannot remove the remote video channel with many retries.' 69 errorMessage: 'Cannot remove the remote account with many retries.'
68 } 70 }
69 71
70 await retryTransactionWrapper(deleteRemoteVideoChannel, options) 72 await retryTransactionWrapper(deleteRemoteAccount, options)
71} 73}
72 74
73async function deleteRemoteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) { 75async function deleteRemoteAccount (accountToRemove: AccountModel) {
74 logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid) 76 logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid)
75 77
76 await sequelizeTypescript.transaction(async t => { 78 await sequelizeTypescript.transaction(async t => {
77 if (videoChannelToRemove.Account.id !== account.id) { 79 await accountToRemove.destroy({ transaction: t })
78 throw new Error('Account ' + account.url + ' does not own video channel ' + videoChannelToRemove.url)
79 }
80
81 await videoChannelToRemove.destroy({ transaction: t })
82 }) 80 })
83 81
84 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.uuid) 82 logger.info('Remote account with uuid %s removed.', accountToRemove.Actor.uuid)
85} 83}
86 84
87async function processDeleteAccount (accountToRemove: AccountModel) { 85async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) {
88 const options = { 86 const options = {
89 arguments: [ accountToRemove ], 87 arguments: [ videoChannelToRemove ],
90 errorMessage: 'Cannot remove the remote account with many retries.' 88 errorMessage: 'Cannot remove the remote video channel with many retries.'
91 } 89 }
92 90
93 await retryTransactionWrapper(deleteRemoteAccount, options) 91 await retryTransactionWrapper(deleteRemoteVideoChannel, options)
94} 92}
95 93
96async function deleteRemoteAccount (accountToRemove: AccountModel) { 94async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel) {
97 logger.debug('Removing remote account "%s".', accountToRemove.uuid) 95 logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid)
98 96
99 await sequelizeTypescript.transaction(async t => { 97 await sequelizeTypescript.transaction(async t => {
100 await accountToRemove.destroy({ transaction: t }) 98 await videoChannelToRemove.destroy({ transaction: t })
101 }) 99 })
102 100
103 logger.info('Remote account with uuid %s removed.', accountToRemove.uuid) 101 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
104} 102}