aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/process/process-follow.ts10
-rw-r--r--server/lib/activitypub/send/send-accept.ts2
-rw-r--r--server/lib/activitypub/send/send-follow.ts2
-rw-r--r--server/lib/activitypub/send/send-reject.ts18
-rw-r--r--server/lib/activitypub/send/send-undo.ts2
-rw-r--r--server/lib/activitypub/url.ts12
6 files changed, 25 insertions, 21 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 0cd537187..cecf09b47 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -1,12 +1,13 @@
1import { ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript, CONFIG } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { sendAccept } from '../send' 7import { sendAccept, sendReject } from '../send'
8import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
9import { getAPId } from '../../../helpers/activitypub' 9import { getAPId } from '../../../helpers/activitypub'
10import { getServerActor } from '../../../helpers/utils'
10 11
11async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { 12async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) {
12 const activityObject = getAPId(activity.object) 13 const activityObject = getAPId(activity.object)
@@ -29,6 +30,11 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
29 if (!targetActor) throw new Error('Unknown actor') 30 if (!targetActor) throw new Error('Unknown actor')
30 if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') 31 if (targetActor.isOwned() === false) throw new Error('This is not a local actor.')
31 32
33 const serverActor = await getServerActor()
34 if (targetActor.id === serverActor.id && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
35 return sendReject(actor, targetActor)
36 }
37
32 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ 38 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
33 where: { 39 where: {
34 actorId: actor.id, 40 actorId: actor.id,
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index b6abde13d..388a9ed23 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -17,7 +17,7 @@ async function sendAccept (actorFollow: ActorFollowModel) {
17 17
18 logger.info('Creating job to accept follower %s.', follower.url) 18 logger.info('Creating job to accept follower %s.', follower.url)
19 19
20 const followUrl = getActorFollowActivityPubUrl(actorFollow) 20 const followUrl = getActorFollowActivityPubUrl(follower, me)
21 const followData = buildFollowActivity(followUrl, follower, me) 21 const followData = buildFollowActivity(followUrl, follower, me)
22 22
23 const url = getActorFollowAcceptActivityPubUrl(actorFollow) 23 const url = getActorFollowAcceptActivityPubUrl(actorFollow)
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 170b46b48..2c3d02014 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -14,7 +14,7 @@ function sendFollow (actorFollow: ActorFollowModel) {
14 14
15 logger.info('Creating job to send follow request to %s.', following.url) 15 logger.info('Creating job to send follow request to %s.', following.url)
16 16
17 const url = getActorFollowActivityPubUrl(actorFollow) 17 const url = getActorFollowActivityPubUrl(me, following)
18 const data = buildFollowActivity(url, me, following) 18 const data = buildFollowActivity(url, me, following)
19 19
20 return unicastTo(data, me, following.inboxUrl) 20 return unicastTo(data, me, following.inboxUrl)
diff --git a/server/lib/activitypub/send/send-reject.ts b/server/lib/activitypub/send/send-reject.ts
index db8c2d86d..bac7ff556 100644
--- a/server/lib/activitypub/send/send-reject.ts
+++ b/server/lib/activitypub/send/send-reject.ts
@@ -1,15 +1,11 @@
1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' 1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor' 2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 3import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url'
4import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
5import { unicastTo } from './utils' 4import { unicastTo } from './utils'
6import { buildFollowActivity } from './send-follow' 5import { buildFollowActivity } from './send-follow'
7import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
8 7
9async function sendReject (actorFollow: ActorFollowModel) { 8async function sendReject (follower: ActorModel, following: ActorModel) {
10 const follower = actorFollow.ActorFollower
11 const me = actorFollow.ActorFollowing
12
13 if (!follower.serverId) { // This should never happen 9 if (!follower.serverId) { // This should never happen
14 logger.warn('Do not sending reject to local follower.') 10 logger.warn('Do not sending reject to local follower.')
15 return 11 return
@@ -17,13 +13,13 @@ async function sendReject (actorFollow: ActorFollowModel) {
17 13
18 logger.info('Creating job to reject follower %s.', follower.url) 14 logger.info('Creating job to reject follower %s.', follower.url)
19 15
20 const followUrl = getActorFollowActivityPubUrl(actorFollow) 16 const followUrl = getActorFollowActivityPubUrl(follower, following)
21 const followData = buildFollowActivity(followUrl, follower, me) 17 const followData = buildFollowActivity(followUrl, follower, following)
22 18
23 const url = getActorFollowAcceptActivityPubUrl(actorFollow) 19 const url = getActorFollowRejectActivityPubUrl(follower, following)
24 const data = buildRejectActivity(url, me, followData) 20 const data = buildRejectActivity(url, following, followData)
25 21
26 return unicastTo(data, me, follower.inboxUrl) 22 return unicastTo(data, following, follower.inboxUrl)
27} 23}
28 24
29// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index ecbf605d6..8727a121e 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -31,7 +31,7 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
31 31
32 logger.info('Creating job to send an unfollow request to %s.', following.url) 32 logger.info('Creating job to send an unfollow request to %s.', following.url)
33 33
34 const followUrl = getActorFollowActivityPubUrl(actorFollow) 34 const followUrl = getActorFollowActivityPubUrl(me, following)
35 const undoUrl = getUndoActivityPubUrl(followUrl) 35 const undoUrl = getUndoActivityPubUrl(followUrl)
36 36
37 const followActivity = buildFollowActivity(followUrl, me, following) 37 const followActivity = buildFollowActivity(followUrl, me, following)
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 7c2ee5bc6..401b83fc2 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -74,11 +74,8 @@ function getVideoDislikesActivityPubUrl (video: VideoModel) {
74 return video.url + '/dislikes' 74 return video.url + '/dislikes'
75} 75}
76 76
77function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) { 77function getActorFollowActivityPubUrl (follower: ActorModel, following: ActorModel) {
78 const me = actorFollow.ActorFollower 78 return follower.url + '/follows/' + following.id
79 const following = actorFollow.ActorFollowing
80
81 return me.url + '/follows/' + following.id
82} 79}
83 80
84function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { 81function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) {
@@ -88,6 +85,10 @@ function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) {
88 return follower.url + '/accepts/follows/' + me.id 85 return follower.url + '/accepts/follows/' + me.id
89} 86}
90 87
88function getActorFollowRejectActivityPubUrl (follower: ActorModel, following: ActorModel) {
89 return follower.url + '/rejects/follows/' + following.id
90}
91
91function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) { 92function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) {
92 return video.url + '/announces/' + byActor.id 93 return video.url + '/announces/' + byActor.id
93} 94}
@@ -120,6 +121,7 @@ export {
120 getVideoViewActivityPubUrl, 121 getVideoViewActivityPubUrl,
121 getVideoLikeActivityPubUrl, 122 getVideoLikeActivityPubUrl,
122 getVideoDislikeActivityPubUrl, 123 getVideoDislikeActivityPubUrl,
124 getActorFollowRejectActivityPubUrl,
123 getVideoCommentActivityPubUrl, 125 getVideoCommentActivityPubUrl,
124 getDeleteActivityPubUrl, 126 getDeleteActivityPubUrl,
125 getVideoSharesActivityPubUrl, 127 getVideoSharesActivityPubUrl,