Commit cbaeffbc authored by les's avatar les
Browse files

.

parent 7d4b2287
const config = require('config')
module.exports = (sequelize, DataTypes) => {
const event = sequelize.define('event', {
id: {
......@@ -35,5 +37,21 @@ module.exports = (sequelize, DataTypes) => {
event.hasMany(models.comment)
}
event.prototype.toAP = function (username) {
return {
id: `${config.baseurl}/federation/m/c_${this.id}`,
type: 'Create',
actor: `${config.baseurl}/federation/u/${username}`,
object: {
id: `${config.baseurl}/federation/m/${this.id}`,
type: 'Note',
published: this.createdAt,
attributedTo: `${config.baseurl}/federation/u/${username}`,
to: 'https://www.w3.org/ns/activitystreams#Public',
content: this.title
}
}
}
return event
}
......@@ -4,6 +4,13 @@ const crypto = require('crypto')
const config = require('config')
const Helpers = {
async sendToFollowers (message, user) {
const followers = user.followers
console.error('send to ', followers)
for(let follower of followers) {
console.error('send message to ', follower)
}
},
async signAndSend(message, user, domain, req, res, targetOrigin) {
// get the URI of the actor object and append 'inbox' to it
let inbox = message.object.actor+'/inbox'
......@@ -34,7 +41,7 @@ const Helpers = {
console.log('Error:', error, response.body)
}
else {
console.log('Response:', response.body)
console.log('Response:', response.body, response.statusCode, response.status, response.statusMessage)
}
})
return res.status(200)
......
const { user: User } = require('../api/models')
const { user: User, event: Event } = require('../api/models')
const config = require('config')
const get = require('lodash/get')
......@@ -48,21 +48,31 @@ module.exports = {
}
res.json(ret)
},
outbox (req, res) {
async outbox (req, res) {
const name = req.params.name
const page = req.query.page
if (!name) return res.status(400).send('Bad request.')
const user = await User.findOne({
include: [ Event ],
where: { username: name }
})
if (!user) return res.status(404).send(`No record found for ${name}`)
console.error('Inside outbox, should return all events from this user')
// https://www.w3.org/TR/activitypub/#outbox
if (!page) {
const ret = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: `${config.baseurl}/federation/u/${name}/outbox`,
type: 'OrderedCollection',
totalItems: 1,
first: `${config.baseurl}/federation/u/${name}/outbox?page=true`,
last: `${config.baseurl}/federation/u/${name}/outbox?page=true`
summary: `${user.username} outbox`,
totalItems: user.events.length,
orderedItems: user.events.map(e => e.toAP(user.username))
// first: `${config.baseurl}/federation/u/${name}/outbox?page=true`,
// last: `${config.baseurl}/federation/u/${name}/outbox?page=true`
}
return res.json(ret)
}
......@@ -71,16 +81,7 @@ module.exports = {
id: `${config.baseurl}/federation/u/${name}/outbox?page=true`,
type: 'OrderedCollectionPage',
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
orderedItems: [{
id: `${config.baseurl}/federation/m/12341234`,
type: 'Note',
url: `${config.baseurl}/federation/m/12341234`,
published: new Date(),
attributedTo: `${config.baseurl}/federation/u/${name}`,
sensitive: false,
to: ['https://www.w3.org/ns/activitystreams#Public'],
content: 'prova'
}]
orderedItems: user.events.map(e => e.toAP(user.username))
}
res.json(ret)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment