2019-08-02 13:43:28 +02:00
|
|
|
const { event: Event } = require('../api/models')
|
|
|
|
const config = require('config')
|
2019-08-08 16:52:13 +02:00
|
|
|
const debug = require('debug')('fediverse:ego')
|
2019-08-02 13:43:28 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async boost (req, res) {
|
2019-08-08 16:52:13 +02:00
|
|
|
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
2019-08-08 16:52:13 +02:00
|
|
|
debug('boost %s', match[1])
|
|
|
|
const event = await Event.findByPk(Number(match[1]))
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
|
|
await event.update({ boost: [...event.boost, req.body.actor] })
|
2019-08-02 13:43:28 +02:00
|
|
|
res.sendStatus(201)
|
|
|
|
},
|
2019-08-08 16:52:13 +02:00
|
|
|
|
|
|
|
async bookmark (req, res) {
|
|
|
|
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
2019-08-08 16:52:13 +02:00
|
|
|
const event = await Event.findByPk(Number(match[1]))
|
|
|
|
debug('%s bookmark %s (%d)', req.body.actor, event.title, event.likes.length)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
|
|
await event.update({ likes: [...event.likes, req.body.actor] })
|
2019-08-02 13:43:28 +02:00
|
|
|
res.sendStatus(201)
|
2019-08-08 16:52:13 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
async unbookmark (req, res) {
|
|
|
|
const body = req.body
|
|
|
|
const object = body.object
|
|
|
|
const match = object.object.match(`${config.baseurl}/federation/m/(.*)`)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
2019-08-08 16:52:13 +02:00
|
|
|
const event = await Event.findByPk(Number(match[1]))
|
|
|
|
debug('%s unbookmark %s (%d)', body.actor, event.title, event.likes.length)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
|
|
await event.update({ likes: [...event.likes.filter(actor => actor !== body.actor)] })
|
2019-08-08 16:52:13 +02:00
|
|
|
res.sendStatus(201)
|
2019-08-02 13:43:28 +02:00
|
|
|
}
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|