test new AP type Event
This commit is contained in:
parent
6cdb48c20c
commit
95784c090f
1 changed files with 14 additions and 11 deletions
|
@ -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', {
|
||||||
|
@ -40,15 +41,17 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
|
|
||||||
Event.prototype.toAP = 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/>`
|
|
||||||
|
${plainDescription}
|
||||||
|
|
||||||
|
${tags.map(t => `#${t}`)}
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
const attachment = []
|
const attachment = []
|
||||||
if (this.image_path) {
|
if (this.image_path) {
|
||||||
|
@ -63,7 +66,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
|
|
||||||
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: 'Event',
|
type: 'Event',
|
||||||
attachment,
|
attachment,
|
||||||
tag: tags.map(tag => ({
|
tag: tags.map(tag => ({
|
||||||
|
@ -75,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue