Files
gancio/server/federation/comments.js

27 lines
774 B
JavaScript
Raw Normal View History

2019-08-01 15:18:45 +02:00
const { event: Event, comment: Comment } = require('../api/models')
const config = require('config')
2019-08-09 14:37:51 +02:00
const debug = require('debug')('fediverse:comment')
2019-08-01 15:18:45 +02:00
module.exports = {
2019-08-09 14:37:51 +02:00
async create (req, res) {
2019-08-01 15:18:45 +02:00
//search for related event
const inReplyTo = body.object.inReplyTo
2019-08-09 14:37:51 +02:00
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]))
2019-08-01 15:18:45 +02:00
2019-08-09 14:37:51 +02:00
if (!event) return res.status(404).send('Event not found!')
debug('comment from %s to %s', req.body.actor, event.titles)
2019-08-01 15:18:45 +02:00
2019-08-09 14:37:51 +02:00
await Comment.create({
activitypub_id: body.object.id,
data: body.object,
eventId: event.id
})
2019-08-01 15:18:45 +02:00
2019-08-09 14:37:51 +02:00
res.sendStatus(201)
2019-08-03 00:48:48 +02:00
2019-08-01 15:18:45 +02:00
}
}