Merge branch 'feat/ap_event' into dev
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const config = require('config')
|
const config = require('config')
|
||||||
const moment = require('moment-timezone')
|
const moment = require('moment-timezone')
|
||||||
|
const htmlToText = require('html-to-text')
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Event = sequelize.define('event', {
|
const Event = sequelize.define('event', {
|
||||||
@@ -38,35 +39,36 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
Event.belongsTo(models.event, { as: 'parent' })
|
Event.belongsTo(models.event, { as: 'parent' })
|
||||||
}
|
}
|
||||||
|
|
||||||
Event.prototype.toNoteAP = function (username, locale, follower = []) {
|
Event.prototype.toAP = function (username, locale, follower = []) {
|
||||||
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
||||||
const tag_links = tags.map(t => {
|
|
||||||
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
|
||||||
}).join(' ')
|
|
||||||
|
|
||||||
const content = `<a href='${config.baseurl}/event/${this.id}'>${this.title}</a><br/>
|
const plainDescription = htmlToText.fromString(this.description.replace('\n', '').slice(0, 1000))
|
||||||
📍 ${this.place.name}<br/>
|
const summary = `
|
||||||
📅 ${moment.unix(this.start_datetime).locale(locale).format('dddd, D MMMM (HH:mm)')}<br/><br/>
|
📍 ${this.place.name}
|
||||||
${this.description.length > 500 ? this.description.substr(0, 500) + '...' : this.description}<br/>
|
📅 ${moment.unix(this.start_datetime).locale(locale).format('dddd, D MMMM (HH:mm)')}
|
||||||
${tag_links} <br/>`
|
|
||||||
|
|
||||||
// const attachment = []
|
${plainDescription}
|
||||||
// if (this.image_path) {
|
|
||||||
// attachment.push({
|
${tags.map(t => `#${t}`)}
|
||||||
// type: 'Document',
|
|
||||||
// mediaType: 'image/jpeg',
|
`
|
||||||
// url: `${config.baseurl}/media/${this.image_path}`,
|
|
||||||
// name: null,
|
const attachment = []
|
||||||
// blurHash: null
|
if (this.image_path) {
|
||||||
// })
|
attachment.push({
|
||||||
// }
|
type: 'Document',
|
||||||
|
mediaType: 'image/jpeg',
|
||||||
|
url: `${config.baseurl}/media/${this.image_path}`,
|
||||||
|
name: null,
|
||||||
|
blurHash: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `${config.baseurl}/federation/m/${this.id}`,
|
id: `${config.baseurl}/federation/m/${this.id}`,
|
||||||
url: `${config.baseurl}/federation/m/${this.id}`,
|
url: `${config.baseurl}/event/${this.id}`,
|
||||||
type: 'Note',
|
type: 'Event',
|
||||||
// do not send attachment, in mastodon a link preview is shown instead
|
attachment,
|
||||||
// attachment,
|
|
||||||
tag: tags.map(tag => ({
|
tag: tags.map(tag => ({
|
||||||
type: 'Hashtag',
|
type: 'Hashtag',
|
||||||
name: '#' + tag,
|
name: '#' + tag,
|
||||||
@@ -76,8 +78,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
attributedTo: `${config.baseurl}/federation/u/${username}`,
|
attributedTo: `${config.baseurl}/federation/u/${username}`,
|
||||||
to: follower || [],
|
to: follower || [],
|
||||||
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${username}/followers`],
|
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${username}/followers`],
|
||||||
content,
|
name: this.title,
|
||||||
summary: null,
|
summary,
|
||||||
sensitive: false
|
sensitive: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const Helpers = {
|
|||||||
to: recipients[sharedInbox],
|
to: recipients[sharedInbox],
|
||||||
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`],
|
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`],
|
||||||
actor: `${config.baseurl}/federation/u/${settingsController.settings.instance_name}`,
|
actor: `${config.baseurl}/federation/u/${settingsController.settings.instance_name}`,
|
||||||
object: event.toNoteAP(settingsController.settings.instance_name,
|
object: event.toAP(settingsController.settings.instance_name,
|
||||||
settingsController.settings.instance_locale,
|
settingsController.settings.instance_locale,
|
||||||
recipients[sharedInbox])
|
recipients[sharedInbox])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ router.get('/m/:event_id', async (req, res) => {
|
|||||||
|
|
||||||
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
||||||
if (!event) { return res.status(404).send('Not found') }
|
if (!event) { return res.status(404).send('Not found') }
|
||||||
return res.json(event.toNoteAP(event.user.username, req.settings.locale))
|
return res.json(event.toAP(event.user.username, req.settings.locale))
|
||||||
})
|
})
|
||||||
|
|
||||||
// get any message coming from federation
|
// get any message coming from federation
|
||||||
@@ -72,6 +72,8 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||||||
if (b.object.type === 'Note') {
|
if (b.object.type === 'Note') {
|
||||||
debug('Create a resource!')
|
debug('Create a resource!')
|
||||||
await Resources.create(req, res)
|
await Resources.create(req, res)
|
||||||
|
} else if (b.object.type === 'Event') {
|
||||||
|
debug('Event type is coming!!')
|
||||||
} else {
|
} else {
|
||||||
// await Resources.create(req, res)
|
// await Resources.create(req, res)
|
||||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
||||||
@@ -80,9 +82,16 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function redirect_on_html_accepted (req, res, next) {
|
||||||
|
if (req.accepts('html')) {
|
||||||
|
return res.redirect(settingsController.settings.baseurl)
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
router.get('/u/:name/outbox', Users.outbox)
|
router.get('/u/:name/outbox', Users.outbox)
|
||||||
router.get('/u/:name/followers', Users.followers)
|
router.get('/u/:name/followers', Users.followers)
|
||||||
router.get('/u/:name', Users.get)
|
router.get('/u/:name', redirect_on_html_accepted, Users.get)
|
||||||
|
|
||||||
// Handle 404
|
// Handle 404
|
||||||
router.use((req, res) => {
|
router.use((req, res) => {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ module.exports = {
|
|||||||
type: 'OrderedCollectionPage',
|
type: 'OrderedCollectionPage',
|
||||||
totalItems: events.length,
|
totalItems: events.length,
|
||||||
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
|
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
|
||||||
orderedItems: events.map(e => ({ ...e.toNoteAP(name, req.settings.locale), actor: `${config.baseurl}/federation/u/${name}` }))
|
orderedItems: events.map(e => ({ ...e.toAP(name, req.settings.locale), actor: `${config.baseurl}/federation/u/${name}` }))
|
||||||
// user.events.map(e => ({
|
// user.events.map(e => ({
|
||||||
// id: `${config.baseurl}/federation/m/${e.id}#create`,
|
// id: `${config.baseurl}/federation/m/${e.id}#create`,
|
||||||
// type: 'Create',
|
// type: 'Create',
|
||||||
|
|||||||
Reference in New Issue
Block a user