aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-08 17:26:01 +0200
committerChocobozzz <me@florianbigard.com>2019-04-08 17:30:48 +0200
commit883993c81ecc2388d4a4b37b29b81b6de73d264f (patch)
treef0f76995b6762b10a0c1a7ccc2b5d952f68014ea /server/lib/activitypub
parent0dc647775881eb1378b213a530996cd096de24ea (diff)
downloadPeerTube-883993c81ecc2388d4a4b37b29b81b6de73d264f.tar.gz
PeerTube-883993c81ecc2388d4a4b37b29b81b6de73d264f.tar.zst
PeerTube-883993c81ecc2388d4a4b37b29b81b6de73d264f.zip
Add notification on new instance follower (server side)
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/actor.ts2
-rw-r--r--server/lib/activitypub/process/process-follow.ts19
2 files changed, 14 insertions, 7 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 63e810642..c0ad07a52 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -342,6 +342,8 @@ function saveActorAndServerAndModelIfNotExist (
342 actorCreated.VideoChannel.Account = ownerActor.Account 342 actorCreated.VideoChannel.Account = ownerActor.Account
343 } 343 }
344 344
345 actorCreated.Server = server
346
345 return actorCreated 347 return actorCreated
346 } 348 }
347} 349}
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 140bbe9f1..276a57e60 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -24,14 +24,16 @@ export {
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
25 25
26async function processFollow (actor: ActorModel, targetActorURL: string) { 26async function processFollow (actor: ActorModel, targetActorURL: string) {
27 const { actorFollow, created } = await sequelizeTypescript.transaction(async t => { 27 const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => {
28 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 28 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
29 29
30 if (!targetActor) throw new Error('Unknown actor') 30 if (!targetActor) throw new Error('Unknown actor')
31 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.')
32 32
33 const serverActor = await getServerActor() 33 const serverActor = await getServerActor()
34 if (targetActor.id === serverActor.id && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { 34 const isFollowingInstance = targetActor.id === serverActor.id
35
36 if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
35 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) 37 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url)
36 38
37 return sendReject(actor, targetActor) 39 return sendReject(actor, targetActor)
@@ -50,9 +52,6 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
50 transaction: t 52 transaction: t
51 }) 53 })
52 54
53 actorFollow.ActorFollower = actor
54 actorFollow.ActorFollowing = targetActor
55
56 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) { 55 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) {
57 actorFollow.state = 'accepted' 56 actorFollow.state = 'accepted'
58 await actorFollow.save({ transaction: t }) 57 await actorFollow.save({ transaction: t })
@@ -64,10 +63,16 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
64 // Target sends to actor he accepted the follow request 63 // Target sends to actor he accepted the follow request
65 if (actorFollow.state === 'accepted') await sendAccept(actorFollow) 64 if (actorFollow.state === 'accepted') await sendAccept(actorFollow)
66 65
67 return { actorFollow, created } 66 return { actorFollow, created, isFollowingInstance }
68 }) 67 })
69 68
70 if (created) Notifier.Instance.notifyOfNewFollow(actorFollow) 69 // Rejected
70 if (!actorFollow) return
71
72 if (created) {
73 if (isFollowingInstance) Notifier.Instance.notifyOfNewInstanceFollow(actorFollow)
74 else Notifier.Instance.notifyOfNewUserFollow(actorFollow)
75 }
71 76
72 logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) 77 logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)
73} 78}