alter accept/announce activity structre to meet Mastodon requirements, debug logging
This commit is contained in:
parent
a09ac67573
commit
dbf8e5a413
4 changed files with 11 additions and 4 deletions
|
@ -22,6 +22,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
|
"start:prod": "NODE_ENV=production authbind node index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "Will Murphy",
|
"author": "Will Murphy",
|
||||||
|
|
|
@ -64,7 +64,7 @@ function addToOutbox (actor, activity) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
// ensure object is cached, but don't alter representation in activity
|
// ensure object is cached, but don't alter representation in activity
|
||||||
// so activities can be sent with objects as links
|
// so activities can be sent with objects as links
|
||||||
pubObject.resolve(activity.object),
|
//pubObject.resolve(activity.object),
|
||||||
store.stream.save(activity),
|
store.stream.save(activity),
|
||||||
address(activity).then(addresses => pubFederation.deliver(actor, activity, addresses))
|
address(activity).then(addresses => pubFederation.deliver(actor, activity, addresses))
|
||||||
])
|
])
|
||||||
|
|
|
@ -24,6 +24,7 @@ function deliver (actor, activity, addresses) {
|
||||||
delete activity.bcc
|
delete activity.bcc
|
||||||
}
|
}
|
||||||
const requests = addresses.map(addr => {
|
const requests = addresses.map(addr => {
|
||||||
|
console.log(`delivering to${addr}`)
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: addr,
|
url: addr,
|
||||||
|
@ -37,8 +38,12 @@ function deliver (actor, activity, addresses) {
|
||||||
authorizationHeaderName: 'Signature'
|
authorizationHeaderName: 'Signature'
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
|
resolveWithFullResponse: true,
|
||||||
|
simple: false,
|
||||||
body: pubUtils.toJSONLD(activity)
|
body: pubUtils.toJSONLD(activity)
|
||||||
})
|
})
|
||||||
|
.then(result => console.log(addr, result.statusCode))
|
||||||
|
.catch(err => console.log(err))
|
||||||
})
|
})
|
||||||
return Promise.all(requests)
|
return Promise.all(requests)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,19 @@ const store = require('../store')
|
||||||
|
|
||||||
router.post('/', net.validators.activity, net.security.verifySignature, function (req, res) {
|
router.post('/', net.validators.activity, net.security.verifySignature, function (req, res) {
|
||||||
req.body._meta = { _target: pub.utils.usernameToIRI(req.user) }
|
req.body._meta = { _target: pub.utils.usernameToIRI(req.user) }
|
||||||
|
console.log(req.body);
|
||||||
// side effects
|
// side effects
|
||||||
switch (req.body.type) {
|
switch (req.body.type) {
|
||||||
case 'Accept':
|
case 'Accept':
|
||||||
// TODO - side effect necessary for following collection?
|
// TODO - side effect necessary for following collection?
|
||||||
break
|
break
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
req.body._meta._target = req.body.object.id
|
//req.body._meta._target = req.body.object.id
|
||||||
// send acceptance reply
|
// send acceptance reply
|
||||||
pub.actor.getOrCreateActor(req.user, true)
|
pub.actor.getOrCreateActor(req.user, true)
|
||||||
.then(user => {
|
.then(user => {
|
||||||
const to = [pub.utils.actorFromActivity(req.body)]
|
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)
|
return pub.activity.addToOutbox(user, accept)
|
||||||
})
|
})
|
||||||
.catch(e => console.log(e))
|
.catch(e => console.log(e))
|
||||||
|
@ -30,7 +31,7 @@ router.post('/', net.validators.activity, net.security.verifySignature, function
|
||||||
pub.utils.actorFromActivity(req.body),
|
pub.utils.actorFromActivity(req.body),
|
||||||
'https://www.w3.org/ns/activitystreams#Public'
|
'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)
|
return pub.activity.addToOutbox(user, accept)
|
||||||
}).catch(e => console.log(e))
|
}).catch(e => console.log(e))
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue