diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/process/process-flag.ts | 8 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-flag.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 20 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-follow.ts | 2 |
9 files changed, 34 insertions, 21 deletions
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts index 0b3976089..8faab051e 100644 --- a/server/lib/activitypub/process/process-flag.ts +++ b/server/lib/activitypub/process/process-flag.ts | |||
@@ -31,7 +31,7 @@ async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, | |||
31 | 31 | ||
32 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: flag.object }) | 32 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: flag.object }) |
33 | 33 | ||
34 | return sequelizeTypescript.transaction(async t => { | 34 | const videoAbuse = await sequelizeTypescript.transaction(async t => { |
35 | const videoAbuseData = { | 35 | const videoAbuseData = { |
36 | reporterAccountId: account.id, | 36 | reporterAccountId: account.id, |
37 | reason: flag.content, | 37 | reason: flag.content, |
@@ -42,8 +42,10 @@ async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, | |||
42 | const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) | 42 | const videoAbuseInstance = await VideoAbuseModel.create(videoAbuseData, { transaction: t }) |
43 | videoAbuseInstance.Video = video | 43 | videoAbuseInstance.Video = video |
44 | 44 | ||
45 | Notifier.Instance.notifyOnNewVideoAbuse(videoAbuseInstance) | ||
46 | |||
47 | logger.info('Remote abuse for video uuid %s created', flag.object) | 45 | logger.info('Remote abuse for video uuid %s created', flag.object) |
46 | |||
47 | return videoAbuseInstance | ||
48 | }) | 48 | }) |
49 | |||
50 | Notifier.Instance.notifyOnNewVideoAbuse(videoAbuse) | ||
49 | } | 51 | } |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 28f18595b..9c21149f2 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -11,6 +11,7 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundanc | |||
11 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 11 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
12 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | 12 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
13 | import { getServerActor } from '../../../helpers/utils' | 13 | import { getServerActor } from '../../../helpers/utils' |
14 | import * as Bluebird from 'bluebird' | ||
14 | 15 | ||
15 | async function sendCreateVideo (video: VideoModel, t: Transaction) { | 16 | async function sendCreateVideo (video: VideoModel, t: Transaction) { |
16 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined | 17 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined |
@@ -82,7 +83,7 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio | |||
82 | 83 | ||
83 | // This was a reply, send it to the parent actors | 84 | // This was a reply, send it to the parent actors |
84 | const actorsException = [ byActor ] | 85 | const actorsException = [ byActor ] |
85 | await broadcastToActors(createActivity, byActor, parentsCommentActors, actorsException) | 86 | await broadcastToActors(createActivity, byActor, parentsCommentActors, t, actorsException) |
86 | 87 | ||
87 | // Broadcast to our followers | 88 | // Broadcast to our followers |
88 | await broadcastToFollowers(createActivity, byActor, [ byActor ], t) | 89 | await broadcastToFollowers(createActivity, byActor, [ byActor ], t) |
@@ -91,7 +92,7 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio | |||
91 | if (isOrigin) return broadcastToFollowers(createActivity, byActor, actorsInvolvedInComment, t, actorsException) | 92 | if (isOrigin) return broadcastToFollowers(createActivity, byActor, actorsInvolvedInComment, t, actorsException) |
92 | 93 | ||
93 | // Send to origin | 94 | // Send to origin |
94 | return unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl) | 95 | t.afterCommit(() => unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)) |
95 | } | 96 | } |
96 | 97 | ||
97 | function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate { | 98 | function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate { |
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 7bf5ca520..7a1d6f0ba 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts | |||
@@ -59,7 +59,7 @@ async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Trans | |||
59 | 59 | ||
60 | // This was a reply, send it to the parent actors | 60 | // This was a reply, send it to the parent actors |
61 | const actorsException = [ byActor ] | 61 | const actorsException = [ byActor ] |
62 | await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), actorsException) | 62 | await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException) |
63 | 63 | ||
64 | // Broadcast to our followers | 64 | // Broadcast to our followers |
65 | await broadcastToFollowers(activity, byActor, [ byActor ], t) | 65 | await broadcastToFollowers(activity, byActor, [ byActor ], t) |
@@ -68,7 +68,7 @@ async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Trans | |||
68 | if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException) | 68 | if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException) |
69 | 69 | ||
70 | // Send to origin | 70 | // Send to origin |
71 | return unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl) | 71 | t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)) |
72 | } | 72 | } |
73 | 73 | ||
74 | async function sendDeleteVideoPlaylist (videoPlaylist: VideoPlaylistModel, t: Transaction) { | 74 | async function sendDeleteVideoPlaylist (videoPlaylist: VideoPlaylistModel, t: Transaction) { |
diff --git a/server/lib/activitypub/send/send-flag.ts b/server/lib/activitypub/send/send-flag.ts index 96a7311b9..61ee389a6 100644 --- a/server/lib/activitypub/send/send-flag.ts +++ b/server/lib/activitypub/send/send-flag.ts | |||
@@ -6,8 +6,9 @@ import { unicastTo } from './utils' | |||
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub' | 7 | import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub' |
8 | import { audiencify, getAudience } from '../audience' | 8 | import { audiencify, getAudience } from '../audience' |
9 | import { Transaction } from 'sequelize' | ||
9 | 10 | ||
10 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) { | 11 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
11 | if (!video.VideoChannel.Account.Actor.serverId) return // Local user | 12 | if (!video.VideoChannel.Account.Actor.serverId) return // Local user |
12 | 13 | ||
13 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 14 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
@@ -18,7 +19,7 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, | |||
18 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } | 19 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } |
19 | const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience) | 20 | const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience) |
20 | 21 | ||
21 | return unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 22 | t.afterCommit(() => unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)) |
22 | } | 23 | } |
23 | 24 | ||
24 | function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag { | 25 | function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag { |
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 2c3d02014..c6e7fe83d 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts | |||
@@ -4,8 +4,9 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
4 | import { getActorFollowActivityPubUrl } from '../url' | 4 | import { getActorFollowActivityPubUrl } from '../url' |
5 | import { unicastTo } from './utils' | 5 | import { unicastTo } from './utils' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { Transaction } from 'sequelize' | ||
7 | 8 | ||
8 | function sendFollow (actorFollow: ActorFollowModel) { | 9 | function sendFollow (actorFollow: ActorFollowModel, t: Transaction) { |
9 | const me = actorFollow.ActorFollower | 10 | const me = actorFollow.ActorFollower |
10 | const following = actorFollow.ActorFollowing | 11 | const following = actorFollow.ActorFollowing |
11 | 12 | ||
@@ -17,7 +18,7 @@ function sendFollow (actorFollow: ActorFollowModel) { | |||
17 | const url = getActorFollowActivityPubUrl(me, following) | 18 | const url = getActorFollowActivityPubUrl(me, following) |
18 | const data = buildFollowActivity(url, me, following) | 19 | const data = buildFollowActivity(url, me, following) |
19 | 20 | ||
20 | return unicastTo(data, me, following.inboxUrl) | 21 | t.afterCommit(() => unicastTo(data, me, following.inboxUrl)) |
21 | } | 22 | } |
22 | 23 | ||
23 | function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow { | 24 | function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow { |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 8727a121e..8fcbbac5c 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -37,7 +37,7 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
37 | const followActivity = buildFollowActivity(followUrl, me, following) | 37 | const followActivity = buildFollowActivity(followUrl, me, following) |
38 | const undoActivity = undoActivityData(undoUrl, me, followActivity) | 38 | const undoActivity = undoActivityData(undoUrl, me, followActivity) |
39 | 39 | ||
40 | return unicastTo(undoActivity, me, following.inboxUrl) | 40 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) |
41 | } | 41 | } |
42 | 42 | ||
43 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | 43 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 7411c08d5..5bf092894 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -26,7 +26,9 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByAct | |||
26 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | 26 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) |
27 | 27 | ||
28 | // Needed to build the AP object | 28 | // Needed to build the AP object |
29 | if (!video.VideoCaptions) video.VideoCaptions = await video.$get('VideoCaptions') as VideoCaptionModel[] | 29 | if (!video.VideoCaptions) { |
30 | video.VideoCaptions = await video.$get('VideoCaptions', { transaction: t }) as VideoCaptionModel[] | ||
31 | } | ||
30 | 32 | ||
31 | const videoObject = video.toActivityPubObject() | 33 | const videoObject = video.toActivityPubObject() |
32 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) | 34 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) |
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 69706e620..1faae1d84 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -7,6 +7,7 @@ import { JobQueue } from '../../job-queue' | |||
7 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' | 8 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' |
9 | import { getServerActor } from '../../../helpers/utils' | 9 | import { getServerActor } from '../../../helpers/utils' |
10 | import { afterCommitIfTransaction } from '../../../helpers/database-utils' | ||
10 | 11 | ||
11 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { | 12 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { |
12 | byActor: ActorModel, | 13 | byActor: ActorModel, |
@@ -20,7 +21,9 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
20 | const audience = getRemoteVideoAudience(options.video, actorsInvolvedInVideo) | 21 | const audience = getRemoteVideoAudience(options.video, actorsInvolvedInVideo) |
21 | const activity = activityBuilder(audience) | 22 | const activity = activityBuilder(audience) |
22 | 23 | ||
23 | return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl) | 24 | return afterCommitIfTransaction(options.transaction, () => { |
25 | return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
26 | }) | ||
24 | } | 27 | } |
25 | 28 | ||
26 | // Send to followers | 29 | // Send to followers |
@@ -28,6 +31,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
28 | const activity = activityBuilder(audience) | 31 | const activity = activityBuilder(audience) |
29 | 32 | ||
30 | const actorsException = [ options.byActor ] | 33 | const actorsException = [ options.byActor ] |
34 | |||
31 | return broadcastToFollowers(activity, options.byActor, actorsInvolvedInVideo, options.transaction, actorsException) | 35 | return broadcastToFollowers(activity, options.byActor, actorsInvolvedInVideo, options.transaction, actorsException) |
32 | } | 36 | } |
33 | 37 | ||
@@ -76,7 +80,7 @@ async function forwardActivity ( | |||
76 | uris, | 80 | uris, |
77 | body: activity | 81 | body: activity |
78 | } | 82 | } |
79 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) | 83 | return afterCommitIfTransaction(t, () => JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })) |
80 | } | 84 | } |
81 | 85 | ||
82 | async function broadcastToFollowers ( | 86 | async function broadcastToFollowers ( |
@@ -87,20 +91,22 @@ async function broadcastToFollowers ( | |||
87 | actorsException: ActorModel[] = [] | 91 | actorsException: ActorModel[] = [] |
88 | ) { | 92 | ) { |
89 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) | 93 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) |
90 | return broadcastTo(uris, data, byActor) | 94 | |
95 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) | ||
91 | } | 96 | } |
92 | 97 | ||
93 | async function broadcastToActors ( | 98 | async function broadcastToActors ( |
94 | data: any, | 99 | data: any, |
95 | byActor: ActorModel, | 100 | byActor: ActorModel, |
96 | toActors: ActorModel[], | 101 | toActors: ActorModel[], |
102 | t?: Transaction, | ||
97 | actorsException: ActorModel[] = [] | 103 | actorsException: ActorModel[] = [] |
98 | ) { | 104 | ) { |
99 | const uris = await computeUris(toActors, actorsException) | 105 | const uris = await computeUris(toActors, actorsException) |
100 | return broadcastTo(uris, data, byActor) | 106 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) |
101 | } | 107 | } |
102 | 108 | ||
103 | async function broadcastTo (uris: string[], data: any, byActor: ActorModel) { | 109 | function broadcastTo (uris: string[], data: any, byActor: ActorModel) { |
104 | if (uris.length === 0) return undefined | 110 | if (uris.length === 0) return undefined |
105 | 111 | ||
106 | logger.debug('Creating broadcast job.', { uris }) | 112 | logger.debug('Creating broadcast job.', { uris }) |
@@ -114,7 +120,7 @@ async function broadcastTo (uris: string[], data: any, byActor: ActorModel) { | |||
114 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) | 120 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) |
115 | } | 121 | } |
116 | 122 | ||
117 | async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { | 123 | function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { |
118 | logger.debug('Creating unicast job.', { uri: toActorUrl }) | 124 | logger.debug('Creating unicast job.', { uri: toActorUrl }) |
119 | 125 | ||
120 | const payload = { | 126 | const payload = { |
@@ -123,7 +129,7 @@ async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { | |||
123 | body: data | 129 | body: data |
124 | } | 130 | } |
125 | 131 | ||
126 | return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) | 132 | JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) |
127 | } | 133 | } |
128 | 134 | ||
129 | // --------------------------------------------------------------------------- | 135 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index b3defb617..4ae66cd01 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts | |||
@@ -69,7 +69,7 @@ async function follow (fromActor: ActorModel, targetActor: ActorModel) { | |||
69 | actorFollow.ActorFollower = fromActor | 69 | actorFollow.ActorFollower = fromActor |
70 | 70 | ||
71 | // Send a notification to remote server if our follow is not already accepted | 71 | // Send a notification to remote server if our follow is not already accepted |
72 | if (actorFollow.state !== 'accepted') await sendFollow(actorFollow) | 72 | if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t) |
73 | 73 | ||
74 | return actorFollow | 74 | return actorFollow |
75 | }) | 75 | }) |