alter accept/announce activity structre to meet Mastodon requirements, debug logging

This commit is contained in:
Will Murphy 2019-09-25 13:17:40 -04:00
parent a09ac67573
commit dbf8e5a413
4 changed files with 11 additions and 4 deletions

View file

@ -22,6 +22,7 @@
},
"scripts": {
"start": "node index.js",
"start:prod": "NODE_ENV=production authbind node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Will Murphy",

View file

@ -64,7 +64,7 @@ function addToOutbox (actor, activity) {
return Promise.all([
// ensure object is cached, but don't alter representation in activity
// so activities can be sent with objects as links
pubObject.resolve(activity.object),
//pubObject.resolve(activity.object),
store.stream.save(activity),
address(activity).then(addresses => pubFederation.deliver(actor, activity, addresses))
])

View file

@ -24,6 +24,7 @@ function deliver (actor, activity, addresses) {
delete activity.bcc
}
const requests = addresses.map(addr => {
console.log(`delivering to${addr}`)
return request({
method: 'POST',
url: addr,
@ -37,8 +38,12 @@ function deliver (actor, activity, addresses) {
authorizationHeaderName: 'Signature'
},
json: true,
resolveWithFullResponse: true,
simple: false,
body: pubUtils.toJSONLD(activity)
})
.then(result => console.log(addr, result.statusCode))
.catch(err => console.log(err))
})
return Promise.all(requests)
}

View file

@ -6,18 +6,19 @@ const store = require('../store')
router.post('/', net.validators.activity, net.security.verifySignature, function (req, res) {
req.body._meta = { _target: pub.utils.usernameToIRI(req.user) }
console.log(req.body);
// side effects
switch (req.body.type) {
case 'Accept':
// TODO - side effect necessary for following collection?
break
case 'Follow':
req.body._meta._target = req.body.object.id
//req.body._meta._target = req.body.object.id
// send acceptance reply
pub.actor.getOrCreateActor(req.user, true)
.then(user => {
const to = [pub.utils.actorFromActivity(req.body)]
const accept = pub.activity.build('Accept', user.id, req.body.id, to)
const accept = pub.activity.build('Accept', user.id, req.body, to)
return pub.activity.addToOutbox(user, accept)
})
.catch(e => console.log(e))
@ -30,7 +31,7 @@ router.post('/', net.validators.activity, net.security.verifySignature, function
pub.utils.actorFromActivity(req.body),
'https://www.w3.org/ns/activitystreams#Public'
]
const accept = pub.activity.build('Announce', user.id, req.body.id, to, cc)
const accept = pub.activity.build('Announce', user.id, req.body.object.id, to, cc)
return pub.activity.addToOutbox(user, accept)
}).catch(e => console.log(e))
break