aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-delete.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/lib/activitypub/send/send-delete.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/lib/activitypub/send/send-delete.ts')
-rw-r--r--server/lib/activitypub/send/send-delete.ts158
1 files changed, 0 insertions, 158 deletions
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
deleted file mode 100644
index 0d85d9001..000000000
--- a/server/lib/activitypub/send/send-delete.ts
+++ /dev/null
@@ -1,158 +0,0 @@
1import { Transaction } from 'sequelize'
2import { getServerActor } from '@server/models/application/application'
3import { ActivityAudience, ActivityDelete } from '@shared/models'
4import { logger } from '../../../helpers/logger'
5import { ActorModel } from '../../../models/actor/actor'
6import { VideoCommentModel } from '../../../models/video/video-comment'
7import { VideoShareModel } from '../../../models/video/video-share'
8import { MActorUrl } from '../../../types/models'
9import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video'
10import { audiencify } from '../audience'
11import { getDeleteActivityPubUrl } from '../url'
12import { getActorsInvolvedInVideo, getVideoCommentAudience } from './shared'
13import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './shared/send-utils'
14
15async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
16 logger.info('Creating job to broadcast delete of video %s.', video.url)
17
18 const byActor = video.VideoChannel.Account.Actor
19
20 const activityBuilder = (audience: ActivityAudience) => {
21 const url = getDeleteActivityPubUrl(video.url)
22
23 return buildDeleteActivity(url, video.url, byActor, audience)
24 }
25
26 return sendVideoRelatedActivity(activityBuilder, { byActor, video, contextType: 'Delete', transaction })
27}
28
29async function sendDeleteActor (byActor: ActorModel, transaction: Transaction) {
30 logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
31
32 const url = getDeleteActivityPubUrl(byActor.url)
33 const activity = buildDeleteActivity(url, byActor.url, byActor)
34
35 const actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, transaction)
36
37 // In case the actor did not have any videos
38 const serverActor = await getServerActor()
39 actorsInvolved.push(serverActor)
40
41 actorsInvolved.push(byActor)
42
43 return broadcastToFollowers({
44 data: activity,
45 byActor,
46 toFollowersOf: actorsInvolved,
47 contextType: 'Delete',
48 transaction
49 })
50}
51
52async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, transaction: Transaction) {
53 logger.info('Creating job to send delete of comment %s.', videoComment.url)
54
55 const isVideoOrigin = videoComment.Video.isOwned()
56
57 const url = getDeleteActivityPubUrl(videoComment.url)
58 const byActor = videoComment.isOwned()
59 ? videoComment.Account.Actor
60 : videoComment.Video.VideoChannel.Account.Actor
61
62 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, transaction)
63 const threadParentCommentsFiltered = threadParentComments.filter(c => !c.isDeleted())
64
65 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, transaction)
66 actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
67
68 const audience = getVideoCommentAudience(videoComment, threadParentCommentsFiltered, actorsInvolvedInComment, isVideoOrigin)
69 const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
70
71 // This was a reply, send it to the parent actors
72 const actorsException = [ byActor ]
73 await broadcastToActors({
74 data: activity,
75 byActor,
76 toActors: threadParentCommentsFiltered.map(c => c.Account.Actor),
77 transaction,
78 contextType: 'Delete',
79 actorsException
80 })
81
82 // Broadcast to our followers
83 await broadcastToFollowers({
84 data: activity,
85 byActor,
86 toFollowersOf: [ byActor ],
87 contextType: 'Delete',
88 transaction
89 })
90
91 // Send to actors involved in the comment
92 if (isVideoOrigin) {
93 return broadcastToFollowers({
94 data: activity,
95 byActor,
96 toFollowersOf: actorsInvolvedInComment,
97 transaction,
98 contextType: 'Delete',
99 actorsException
100 })
101 }
102
103 // Send to origin
104 return transaction.afterCommit(() => {
105 return unicastTo({
106 data: activity,
107 byActor,
108 toActorUrl: videoComment.Video.VideoChannel.Account.Actor.getSharedInbox(),
109 contextType: 'Delete'
110 })
111 })
112}
113
114async function sendDeleteVideoPlaylist (videoPlaylist: MVideoPlaylistFullSummary, transaction: Transaction) {
115 logger.info('Creating job to send delete of playlist %s.', videoPlaylist.url)
116
117 const byActor = videoPlaylist.OwnerAccount.Actor
118
119 const url = getDeleteActivityPubUrl(videoPlaylist.url)
120 const activity = buildDeleteActivity(url, videoPlaylist.url, byActor)
121
122 const serverActor = await getServerActor()
123 const toFollowersOf = [ byActor, serverActor ]
124
125 if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor)
126
127 return broadcastToFollowers({
128 data: activity,
129 byActor,
130 toFollowersOf,
131 contextType: 'Delete',
132 transaction
133 })
134}
135
136// ---------------------------------------------------------------------------
137
138export {
139 sendDeleteVideo,
140 sendDeleteActor,
141 sendDeleteVideoComment,
142 sendDeleteVideoPlaylist
143}
144
145// ---------------------------------------------------------------------------
146
147function buildDeleteActivity (url: string, object: string, byActor: MActorUrl, audience?: ActivityAudience): ActivityDelete {
148 const activity = {
149 type: 'Delete' as 'Delete',
150 id: url,
151 actor: byActor.url,
152 object
153 }
154
155 if (audience) return audiencify(activity, audience)
156
157 return activity
158}