send emails with less spam points
This commit is contained in:
@@ -4,15 +4,21 @@ const debug = require('debug')('fediverse:comment')
|
||||
|
||||
module.exports = {
|
||||
async create (req, res) {
|
||||
|
||||
const body = req.body
|
||||
//search for related event
|
||||
const inReplyTo = body.object.inReplyTo
|
||||
const match = inReplyTo.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length<2) return res.status(404).send('Event not found!')
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
let event = await Event.findByPk(Number(match[1]))
|
||||
|
||||
if (!event) return res.status(404).send('Event not found!')
|
||||
debug('comment from %s to %s', req.body.actor, event.titles)
|
||||
debug('comment coming for %s', inReplyTo)
|
||||
if (!event) {
|
||||
// in reply to another comment...
|
||||
const comment = await Comment.findByPk(inReplyTo, { include: [Event] })
|
||||
if (!comment) return res.status(404).send('Not found')
|
||||
event = comment.event
|
||||
}
|
||||
debug('comment from %s to "%s"', req.body.actor, event.title)
|
||||
|
||||
await Comment.create({
|
||||
activitypub_id: body.object.id,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const fetch = require('node-fetch')
|
||||
const request = require('request')
|
||||
// const request = require('request')
|
||||
const crypto = require('crypto')
|
||||
const config = require('config')
|
||||
const httpSignature = require('http-signature')
|
||||
@@ -29,29 +29,23 @@ const Helpers = {
|
||||
console.error('header ', header)
|
||||
console.error('requestTo ', toInbox)
|
||||
console.error('host ', toOrigin.hostname)
|
||||
request({
|
||||
url: toInbox,
|
||||
const response = await fetch(toInbox, {
|
||||
headers: {
|
||||
'Host': toOrigin.hostname,
|
||||
'Date': d.toUTCString(),
|
||||
'Signature': header,
|
||||
'Content-Type': 'application/activity+json; charset=utf-8'
|
||||
'Content-Type': 'application/activity+json; charset=utf-8',
|
||||
'Accept': 'application/activity+json, application/json; chartset=utf-8'
|
||||
},
|
||||
method: 'POST',
|
||||
json: true,
|
||||
body: message
|
||||
}, function (error, response){
|
||||
if (error) {
|
||||
console.log('Error:', error, response.body)
|
||||
}
|
||||
else {
|
||||
console.log('Response:', response.body, response.statusCode, response.status, response.statusMessage)
|
||||
}
|
||||
})
|
||||
body: JSON.stringify(message) })
|
||||
|
||||
console.log('Response:', response.body, response.statusCode, response.status, response.statusMessage)
|
||||
},
|
||||
async sendEvent(event, user) {
|
||||
const followers = user.followers
|
||||
for(let follower of followers) {
|
||||
debug('Notify %s with event %s', follower, event.title)
|
||||
const body = event.toAP(user.username, follower)
|
||||
body['@context'] = 'https://www.w3.org/ns/activitystreams'
|
||||
Helpers.signAndSend(body, user, follower)
|
||||
|
||||
@@ -38,7 +38,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
||||
Follows.follow(req, res)
|
||||
break
|
||||
case 'Undo':
|
||||
// unfollow || unlike
|
||||
// unfollow || unlike || unboost
|
||||
if (b.object.type === 'Follow') {
|
||||
Follows.unfollow(req, res)
|
||||
} else if (b.object.type === 'Like') {
|
||||
|
||||
Reference in New Issue
Block a user