aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-follow.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-04 08:56:20 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commitf7cc67b455a12ccae9b0ea16876d166720364357 (patch)
treeeac2cdbf2e92a16b3eda5d74371c82bd79ae22cb /server/lib/activitypub/process/process-follow.ts
parentdc13348070d808d0ba3feb56a435b835c2e7e791 (diff)
downloadPeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.gz
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.zst
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.zip
Add new follow, mention and user registered notifs
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r--server/lib/activitypub/process/process-follow.ts11
1 files changed, 8 insertions, 3 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 24c9085f7..a67892440 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -5,6 +5,7 @@ import { sequelizeTypescript } 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 } from '../send'
8import { Notifier } from '../../notifier'
8 9
9async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { 10async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) {
10 const activityObject = activity.object 11 const activityObject = activity.object
@@ -21,13 +22,13 @@ export {
21// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
22 23
23async function processFollow (actor: ActorModel, targetActorURL: string) { 24async function processFollow (actor: ActorModel, targetActorURL: string) {
24 await sequelizeTypescript.transaction(async t => { 25 const { actorFollow, created } = await sequelizeTypescript.transaction(async t => {
25 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 26 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
26 27
27 if (!targetActor) throw new Error('Unknown actor') 28 if (!targetActor) throw new Error('Unknown actor')
28 if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') 29 if (targetActor.isOwned() === false) throw new Error('This is not a local actor.')
29 30
30 const [ actorFollow ] = await ActorFollowModel.findOrCreate({ 31 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
31 where: { 32 where: {
32 actorId: actor.id, 33 actorId: actor.id,
33 targetActorId: targetActor.id 34 targetActorId: targetActor.id
@@ -52,8 +53,12 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
52 actorFollow.ActorFollowing = targetActor 53 actorFollow.ActorFollowing = targetActor
53 54
54 // Target sends to actor he accepted the follow request 55 // Target sends to actor he accepted the follow request
55 return sendAccept(actorFollow) 56 await sendAccept(actorFollow)
57
58 return { actorFollow, created }
56 }) 59 })
57 60
61 if (created) Notifier.Instance.notifyOfNewFollow(actorFollow)
62
58 logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) 63 logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)
59} 64}