From 35898576fadd552743f63d5b22e9b8e7813e4f58 Mon Sep 17 00:00:00 2001 From: Niko Date: Sat, 12 Feb 2022 03:03:16 +0100 Subject: [PATCH] Move custom side-effects events to activity/federation.js --- api/src/activity/federation.js | 10 ++++++++++ api/src/activity/index.js | 1 + api/src/server.js | 14 ++------------ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 api/src/activity/federation.js diff --git a/api/src/activity/federation.js b/api/src/activity/federation.js new file mode 100644 index 0000000..e69223a --- /dev/null +++ b/api/src/activity/federation.js @@ -0,0 +1,10 @@ +module.exports = { + inbox: (msg) => { + console.log('INBOX') + console.log(msg) + }, + outbox: (msg) => { + console.log('OUTBOX') + console.log(msg) + }, +}; diff --git a/api/src/activity/index.js b/api/src/activity/index.js index a9be412..5addef4 100644 --- a/api/src/activity/index.js +++ b/api/src/activity/index.js @@ -5,6 +5,7 @@ global.replaceImpl = (funcs, name, withFunc) => { } module.exports = { + federation: require('./federation.js'), rewriteImplementations: () => { require('./well-known.js').init() require('./actor.js').init() diff --git a/api/src/server.js b/api/src/server.js index 2c5dcce..a8bad16 100644 --- a/api/src/server.js +++ b/api/src/server.js @@ -62,18 +62,8 @@ app.get(routes.likes, apex.net.likes.get) app.get('/.well-known/webfinger', apex.net.webfinger.get) app.get('/.well-known/nodeinfo', apex.net.nodeInfoLocation.get) app.get('/nodeinfo/:version', apex.net.nodeInfo.get) - -// custom side-effects for your app -app.on('apex-outbox', msg => { - if (msg.activity.type === 'Create') { - console.log(`New ${msg.object.type} from ${msg.actor}`) - } -}) -app.on('apex-inbox', msg => { - if (msg.activity.type === 'Create') { - console.log(`New ${msg.object.type} from ${msg.actor} to ${msg.recipient}`) - } -}) +app.on('apex-outbox', activity.federation.outbox) +app.on('apex-inbox', activity.federation.inbox) // API defines app.route(api.url('/accounts/register')).post(api.accounts.register.post)