2019-07-31 01:03:21 +02:00
|
|
|
const config = require('config')
|
2019-08-07 19:36:10 +02:00
|
|
|
const moment = require('moment')
|
2019-07-31 01:03:21 +02:00
|
|
|
|
2019-06-06 23:54:32 +02:00
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
|
|
const event = sequelize.define('event', {
|
2019-07-11 23:31:37 +02:00
|
|
|
id: {
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
primaryKey: true,
|
2019-09-11 19:12:24 +02:00
|
|
|
autoIncrement: true
|
2019-07-11 23:31:37 +02:00
|
|
|
},
|
2019-06-06 23:54:32 +02:00
|
|
|
title: DataTypes.STRING,
|
|
|
|
slug: DataTypes.STRING,
|
|
|
|
description: DataTypes.TEXT,
|
|
|
|
multidate: DataTypes.BOOLEAN,
|
2019-06-07 17:02:33 +02:00
|
|
|
start_datetime: {
|
2019-06-21 23:52:18 +02:00
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
index: true
|
|
|
|
},
|
|
|
|
end_datetime: {
|
|
|
|
type: DataTypes.INTEGER,
|
2019-06-06 23:54:32 +02:00
|
|
|
index: true
|
|
|
|
},
|
|
|
|
image_path: DataTypes.STRING,
|
|
|
|
is_visible: DataTypes.BOOLEAN,
|
2019-07-11 23:31:37 +02:00
|
|
|
recurrent: DataTypes.JSON,
|
|
|
|
// parent: DataTypes.INTEGER
|
2019-08-01 15:18:45 +02:00
|
|
|
likes: { type: DataTypes.JSON, defaultValue: [] },
|
|
|
|
boost: { type: DataTypes.JSON, defaultValue: [] }
|
2019-06-07 17:02:33 +02:00
|
|
|
}, {})
|
2019-06-26 14:44:21 +02:00
|
|
|
|
2019-06-07 17:02:33 +02:00
|
|
|
event.associate = function (models) {
|
2019-06-06 23:54:32 +02:00
|
|
|
event.belongsTo(models.place)
|
|
|
|
event.belongsTo(models.user)
|
|
|
|
event.belongsToMany(models.tag, { through: 'event_tags' })
|
|
|
|
event.belongsToMany(models.notification, { through: 'event_notification' })
|
|
|
|
event.hasMany(models.comment)
|
2019-06-07 17:02:33 +02:00
|
|
|
}
|
2019-06-26 14:44:21 +02:00
|
|
|
|
2019-09-11 19:12:24 +02:00
|
|
|
//
|
2019-09-11 21:20:44 +02:00
|
|
|
event.prototype.toAP = function (username, follower = []) {
|
2019-09-11 12:00:13 +02:00
|
|
|
const tags = this.tags && this.tags.map(t => '#' + t.tag).join(' ')
|
2019-09-18 12:55:33 +02:00
|
|
|
const content = `<a href='${config.baseurl}/event/${this.id}'>${this.title}</a><br/>
|
2019-09-11 12:00:13 +02:00
|
|
|
📍${this.place.name}<br/>
|
|
|
|
⏰ ${moment.unix(this.start_datetime).format('dddd, D MMMM (HH:mm)')}<br/><br/>
|
|
|
|
${this.description.length > 200 ? this.description.substr(0, 200) + '...' : this.description}<br/>
|
2019-09-18 12:55:33 +02:00
|
|
|
${tags} <br/>`
|
2019-09-11 12:00:13 +02:00
|
|
|
|
2019-09-11 19:12:24 +02:00
|
|
|
const attachment = []
|
2019-09-11 12:00:13 +02:00
|
|
|
if (this.image_path) {
|
|
|
|
attachment.push({
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/jpeg',
|
|
|
|
url: `${config.baseurl}/media/${this.image_path}`,
|
|
|
|
name: null,
|
|
|
|
blurHash: null
|
|
|
|
})
|
|
|
|
}
|
2019-09-06 11:58:11 +02:00
|
|
|
|
2019-07-31 01:03:21 +02:00
|
|
|
return {
|
2019-09-11 19:12:24 +02:00
|
|
|
type: 'Note',
|
|
|
|
id: `${config.baseurl}/federation/m/${this.id}`,
|
|
|
|
url: `${config.baseurl}/federation/m/${this.id}`,
|
|
|
|
attachment,
|
|
|
|
tag: this.tags.map(tag => ({
|
|
|
|
type: 'Hashtag',
|
|
|
|
name: '#' + tag.tag
|
|
|
|
})),
|
|
|
|
published: this.createdAt,
|
|
|
|
attributedTo: `${config.baseurl}/federation/u/${username}`,
|
|
|
|
to: ['https://www.w3.org/ns/activitystreams#Public'],
|
|
|
|
cc: follower || [],
|
|
|
|
content,
|
|
|
|
summary: null,
|
|
|
|
sensitive: false,
|
|
|
|
// }
|
2019-07-31 01:03:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:02:33 +02:00
|
|
|
return event
|
2019-06-09 00:45:50 +02:00
|
|
|
}
|