2019-07-30 18:32:26 +02:00
|
|
|
const config = require('config')
|
|
|
|
const Helpers = require('./helpers')
|
|
|
|
const { user: User } = require('../api/models')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
// follow request from fediverse
|
|
|
|
async follow (req, res, body, targetOrigin, domain) {
|
2019-07-30 18:56:32 +02:00
|
|
|
if (typeof body.object !== 'string') return
|
2019-07-30 18:32:26 +02:00
|
|
|
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
|
|
|
|
console.error('someone wants to follow ' + username)
|
|
|
|
const user = await User.findOne({ where: { username }})
|
|
|
|
if (!user) {
|
|
|
|
console.error('No user found!')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.error('FOLLOWERS ', user.followers)
|
|
|
|
if (user.followers.indexOf(body.actor) === -1) {
|
|
|
|
console.error('ok this is a new follower: ', body.actor)
|
|
|
|
await user.update({ followers: [...user.followers, body.actor] })
|
|
|
|
}
|
2019-07-30 19:10:58 +02:00
|
|
|
return Helpers.sendAcceptMessage(body, user, domain, req, res, targetOrigin)
|
2019-07-30 18:32:26 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
// unfollow request from fediverse
|
|
|
|
unfollow () {
|
|
|
|
console.error('inside unfollow')
|
|
|
|
}
|
2019-07-30 18:56:32 +02:00
|
|
|
}
|