]>
Commit | Line | Data |
---|---|---|
3fd3ab2d | 1 | import { ActivityDelete } from '../../../../shared/models/activitypub' |
da854ddd C |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | |
80fdaf06 | 4 | import { sequelizeTypescript } from '../../../initializers/database' |
7d9ba5c0 | 5 | import { ActorModel } from '../../../models/actor/actor' |
3fd3ab2d | 6 | import { VideoModel } from '../../../models/video/video' |
4cb6d457 | 7 | import { VideoCommentModel } from '../../../models/video/video-comment' |
df0b219d | 8 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
26d6bf65 | 9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
c24822a8 C |
10 | import { |
11 | MAccountActor, | |
12 | MActor, | |
13 | MActorFull, | |
14 | MActorSignature, | |
15 | MChannelAccountActor, | |
16 | MChannelActor, | |
17 | MCommentOwnerVideo | |
18 | } from '../../../types/models' | |
0d8de275 C |
19 | import { markCommentAsDeleted } from '../../video-comment' |
20 | import { forwardVideoRelatedActivity } from '../send/utils' | |
1198edf4 C |
21 | |
22 | async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) { | |
23 | const { activity, byActor } = options | |
7a7724e6 | 24 | |
2890b615 | 25 | const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id |
7a7724e6 | 26 | |
f05a1c30 | 27 | if (activity.actor === objectUrl) { |
e587e0ec C |
28 | // We need more attributes (all the account and channel) |
29 | const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url) | |
f05a1c30 | 30 | |
e587e0ec C |
31 | if (byActorFull.type === 'Person') { |
32 | if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.') | |
7a7724e6 | 33 | |
453e83ea C |
34 | const accountToDelete = byActorFull.Account as MAccountActor |
35 | accountToDelete.Actor = byActorFull | |
36 | ||
37 | return retryTransactionWrapper(processDeleteAccount, accountToDelete) | |
e587e0ec C |
38 | } else if (byActorFull.type === 'Group') { |
39 | if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.') | |
50d6de9c | 40 | |
c24822a8 C |
41 | const channelToDelete = byActorFull.VideoChannel as MChannelAccountActor & { Actor: MActorFull } |
42 | channelToDelete.Actor = byActorFull | |
453e83ea | 43 | return retryTransactionWrapper(processDeleteVideoChannel, channelToDelete) |
7a7724e6 C |
44 | } |
45 | } | |
46 | ||
47 | { | |
511765c9 | 48 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccountAndVideo(objectUrl) |
4cb6d457 | 49 | if (videoCommentInstance) { |
e587e0ec | 50 | return retryTransactionWrapper(processDeleteVideoComment, byActor, videoCommentInstance, activity) |
4cb6d457 C |
51 | } |
52 | } | |
53 | ||
54 | { | |
2890b615 | 55 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) |
4cb6d457 | 56 | if (videoInstance) { |
a2377d15 C |
57 | if (videoInstance.isOwned()) throw new Error(`Remote instance cannot delete owned video ${videoInstance.url}.`) |
58 | ||
e587e0ec | 59 | return retryTransactionWrapper(processDeleteVideo, byActor, videoInstance) |
7a7724e6 C |
60 | } |
61 | } | |
62 | ||
df0b219d C |
63 | { |
64 | const videoPlaylist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(objectUrl) | |
65 | if (videoPlaylist) { | |
66 | if (videoPlaylist.isOwned()) throw new Error(`Remote instance cannot delete owned playlist ${videoPlaylist.url}.`) | |
67 | ||
68 | return retryTransactionWrapper(processDeleteVideoPlaylist, byActor, videoPlaylist) | |
69 | } | |
70 | } | |
71 | ||
bcec136e | 72 | return undefined |
7a7724e6 C |
73 | } |
74 | ||
75 | // --------------------------------------------------------------------------- | |
76 | ||
77 | export { | |
78 | processDeleteActivity | |
79 | } | |
80 | ||
81 | // --------------------------------------------------------------------------- | |
82 | ||
453e83ea | 83 | async function processDeleteVideo (actor: MActor, videoToDelete: VideoModel) { |
7a7724e6 C |
84 | logger.debug('Removing remote video "%s".', videoToDelete.uuid) |
85 | ||
3fd3ab2d | 86 | await sequelizeTypescript.transaction(async t => { |
50d6de9c C |
87 | if (videoToDelete.VideoChannel.Account.Actor.id !== actor.id) { |
88 | throw new Error('Account ' + actor.url + ' does not own video channel ' + videoToDelete.VideoChannel.Actor.url) | |
7a7724e6 C |
89 | } |
90 | ||
91 | await videoToDelete.destroy({ transaction: t }) | |
92 | }) | |
93 | ||
94 | logger.info('Remote video with uuid %s removed.', videoToDelete.uuid) | |
95 | } | |
96 | ||
453e83ea | 97 | async function processDeleteVideoPlaylist (actor: MActor, playlistToDelete: VideoPlaylistModel) { |
df0b219d C |
98 | logger.debug('Removing remote video playlist "%s".', playlistToDelete.uuid) |
99 | ||
100 | await sequelizeTypescript.transaction(async t => { | |
101 | if (playlistToDelete.OwnerAccount.Actor.id !== actor.id) { | |
102 | throw new Error('Account ' + actor.url + ' does not own video playlist ' + playlistToDelete.url) | |
103 | } | |
104 | ||
105 | await playlistToDelete.destroy({ transaction: t }) | |
106 | }) | |
107 | ||
108 | logger.info('Remote video playlist with uuid %s removed.', playlistToDelete.uuid) | |
109 | } | |
110 | ||
453e83ea | 111 | async function processDeleteAccount (accountToRemove: MAccountActor) { |
57cfff78 | 112 | logger.debug('Removing remote account "%s".', accountToRemove.Actor.url) |
7a7724e6 | 113 | |
3fd3ab2d | 114 | await sequelizeTypescript.transaction(async t => { |
50d6de9c | 115 | await accountToRemove.destroy({ transaction: t }) |
7a7724e6 C |
116 | }) |
117 | ||
57cfff78 | 118 | logger.info('Remote account %s removed.', accountToRemove.Actor.url) |
7a7724e6 C |
119 | } |
120 | ||
453e83ea | 121 | async function processDeleteVideoChannel (videoChannelToRemove: MChannelActor) { |
57cfff78 | 122 | logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.url) |
7a7724e6 | 123 | |
3fd3ab2d | 124 | await sequelizeTypescript.transaction(async t => { |
50d6de9c | 125 | await videoChannelToRemove.destroy({ transaction: t }) |
7a7724e6 C |
126 | }) |
127 | ||
57cfff78 | 128 | logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url) |
7a7724e6 | 129 | } |
4cb6d457 | 130 | |
0d8de275 C |
131 | function processDeleteVideoComment (byActor: MActorSignature, videoComment: MCommentOwnerVideo, activity: ActivityDelete) { |
132 | // Already deleted | |
133 | if (videoComment.isDeleted()) return | |
134 | ||
4cb6d457 C |
135 | logger.debug('Removing remote video comment "%s".', videoComment.url) |
136 | ||
137 | return sequelizeTypescript.transaction(async t => { | |
511765c9 C |
138 | if (byActor.Account.id !== videoComment.Account.id && byActor.Account.id !== videoComment.Video.VideoChannel.accountId) { |
139 | throw new Error(`Account ${byActor.url} does not own video comment ${videoComment.url} or video ${videoComment.Video.url}`) | |
12ba460e C |
140 | } |
141 | ||
69222afa JM |
142 | await sequelizeTypescript.transaction(async t => { |
143 | markCommentAsDeleted(videoComment) | |
144 | ||
145 | await videoComment.save() | |
146 | }) | |
4cb6d457 | 147 | |
73c08093 C |
148 | if (videoComment.Video.isOwned()) { |
149 | // Don't resend the activity to the sender | |
150 | const exceptions = [ byActor ] | |
659edaa6 | 151 | await forwardVideoRelatedActivity(activity, t, exceptions, videoComment.Video) |
73c08093 C |
152 | } |
153 | ||
4cb6d457 C |
154 | logger.info('Remote video comment %s removed.', videoComment.url) |
155 | }) | |
156 | } |