mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
[refactoring] s/comment/resource
This commit is contained in:
parent
bb14fbed83
commit
c43fe095a5
17 changed files with 214 additions and 165 deletions
|
@ -49,8 +49,7 @@
|
|||
"disable": "Disable",
|
||||
"me": "You",
|
||||
"password_updated": "Password updated!",
|
||||
"username": "Username",
|
||||
"comments": "Comments",
|
||||
"resources": "Resources",
|
||||
"activate_user": "Confirmed",
|
||||
"displayname": "Display name",
|
||||
"federation": "Federation",
|
||||
|
@ -141,20 +140,20 @@
|
|||
"user_create_ok": "User created",
|
||||
"allow_registration_description": "Allow open registrations?",
|
||||
"allow_anon_event": "Allow anon events (has to be confirmed)?",
|
||||
"allow_comments": "Enable comments",
|
||||
"allow_recurrent_event": "Enable recurrent events",
|
||||
"recurrent_event_visible": "Show recurrent events by default",
|
||||
"federation": "Federation / ActivityPub",
|
||||
"enable_federation": "Enable federation",
|
||||
"enable_federation_help": "It will be possible to follow this instance from the fediverse",
|
||||
"select_instance_timezone": "Select instance timezone",
|
||||
"enable_comments": "Enable comments",
|
||||
"enable_comments_help": "Allows you to add resources to the event from the fediverse",
|
||||
"enable_resources": "Enable resources",
|
||||
"enable_resources_help": "Allows you to add resources to the event from the fediverse",
|
||||
"hide_boost_bookmark": "Hides boost/bookmark numbers",
|
||||
"hide_boost_bookmark_help": "Hides the small icons that show the number of boosts / bookmarks coming from the fediverse",
|
||||
"block_instance": "Block",
|
||||
"unblock_instance": "Unblock",
|
||||
"user_add_help": "We will send an email to the new user with instructions to confirm the subscription and choose a password"
|
||||
"block": "Block",
|
||||
"unblock": "Unblock",
|
||||
"user_add_help": "We will send an email to the new user with instructions to confirm the subscription and choose a password",
|
||||
"instance_name": "Instance name"
|
||||
},
|
||||
"auth": {
|
||||
"not_confirmed": "Not confirmed yet",
|
||||
|
|
|
@ -65,7 +65,8 @@
|
|||
"feed_url_copied": "Feed url copiato, incollalo nel tuo feed reader",
|
||||
"follow_me_title": "Segui gli aggiornamenti dal fediverso",
|
||||
"follow": "Segui",
|
||||
"resources": "nessuna risorsa|una risorsa|{n} risorse",
|
||||
"n_resources": "nessuna risorsa|una risorsa|{n} risorse",
|
||||
"resources": "Risorse",
|
||||
"moderation": "Moderazione"
|
||||
},
|
||||
"login": {
|
||||
|
@ -141,27 +142,29 @@
|
|||
"user_create_ok": "Utente creato",
|
||||
"allow_registration_description": "Vuoi abilitare la registrazione?",
|
||||
"allow_anon_event": "Si possono inserire eventi anonimi (previa conferma)?",
|
||||
"allow_comments": "Abilita commenti",
|
||||
"allow_recurrent_event": "Abilita eventi fissi",
|
||||
"recurrent_event_visible": "Appuntamenti fissi visibili di default",
|
||||
"federation": "Federazione / ActivityPub",
|
||||
"enable_federation": "Abilita la federazione!",
|
||||
"enable_federation_help": "Sarà possibile seguire questa istanza dal fediverso",
|
||||
"select_instance_timezone": "Seleziona la timezone",
|
||||
"enable_comments": "Abilita commenti",
|
||||
"enable_comments_help": "Permette di aggiungere risorse all'evento dal fediverso",
|
||||
"enable_resources": "Abilita risorse",
|
||||
"enable_resources_help": "Permette di aggiungere risorse all'evento dal fediverso",
|
||||
"hide_boost_bookmark": "Nasconde numero condivisioni/segnalibri",
|
||||
"hide_boost_bookmark_help": "Nasconde le piccole icone che mostrano il numero di boost/bookmark in arrivo dal fediverso",
|
||||
"block": "Blocca",
|
||||
"unblock": "Sblocca",
|
||||
"user_add_help": "Manderemo una email al nuovo utente con le istruzioni per confermare l'iscrizione e scegliere una password",
|
||||
"comments": "Risorse",
|
||||
"resources": "Risorse",
|
||||
"hide_resource": "Nascondi risorsa",
|
||||
"show_resource": "Mostra risorsa",
|
||||
"remove_resource": "Elimina risorsa",
|
||||
"remove_resource_confirm": "Sicura di voler eliminare questa risorsa?",
|
||||
"block_user": "Blocca questo utente",
|
||||
"user_blocked": "L'utente {user} non potrà più aggiungere risorse"
|
||||
"user_blocked": "L'utente {user} non potrà più aggiungere risorse",
|
||||
"filter_instances": "Filtra istanze",
|
||||
"filter_users": "Filtra utenti",
|
||||
"instance_name": "Nome istanza"
|
||||
},
|
||||
"auth": {
|
||||
"not_confirmed": "Non abbiamo ancora confermato questa mail...",
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
template(slot='label')
|
||||
v-icon(name='network-wired')
|
||||
span.ml-1 {{$t('common.federation')}}
|
||||
Federation(:instances='instances')
|
||||
Federation
|
||||
|
||||
</template>
|
||||
<script>
|
||||
|
@ -67,7 +67,6 @@ export default {
|
|||
middleware: ['auth'],
|
||||
data () {
|
||||
return {
|
||||
instances: [],
|
||||
perPage: 10,
|
||||
eventPage: 1,
|
||||
description: '',
|
||||
|
@ -84,8 +83,7 @@ export default {
|
|||
try {
|
||||
const users = await $axios.$get('/users')
|
||||
const events = await $axios.$get('/event/unconfirmed')
|
||||
const instances = await $axios.$get('/instances')
|
||||
return { users, events, instances }
|
||||
return { users, events }
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
|
|
@ -58,32 +58,32 @@
|
|||
a.el-button.el-button--success.el-button--mini.is-plain(role='button' plain size='mini' type='success'
|
||||
:href='`${settings.baseurl}/api/event/${event.id}.ics`') <i class='el-icon-date'></i> {{$t('common.add_to_calendar')}}
|
||||
|
||||
//- comments from fediverse
|
||||
#comments.mt-1(v-if='settings.enable_federation')
|
||||
div.float-right(v-if='!settings.disable_gamification')
|
||||
//- resources from fediverse
|
||||
#resources.mt-1(v-if='settings.enable_federation')
|
||||
div.float-right(v-if='!settings.hide_boosts')
|
||||
small.mr-3 🔖 {{event.likes.length}}
|
||||
small ✊ {{event.boost.length}}<br/>
|
||||
|
||||
strong(v-if='settings.enable_comments') {{$tc('common.resources', event.comments.length)}} -
|
||||
strong(v-if='settings.enable_resources') {{$tc('common.resources', event.resources.length)}} -
|
||||
small {{$t('event.interact_with_me_at')}}
|
||||
el-button(type='text' size='mini' @click='showFollowMe=true') @{{fedi_user}}@{{settings.baseurl|url2host}}
|
||||
el-button(type='text' size='mini' @click='showFollowMe=true') @{{settings.instance_name}}@{{settings.baseurl|url2host}}
|
||||
|
||||
el-dialog.followDialog(:visible.sync='showFollowMe')
|
||||
h4(slot='title') {{$t('common.follow_me_title')}}
|
||||
FollowMe
|
||||
|
||||
.card-header(v-if='settings.enable_comments' v-for='comment in event.comments' :key='comment.id' :class='{disabled: comment.hidden}')
|
||||
a.float-right(:href='comment.data.url')
|
||||
small {{comment.data.published|datetime}}
|
||||
div.mt-1(v-html='comment_filter(comment.data.content)')
|
||||
img(v-for='img in comment.data.media_attachments' :src='img.url')
|
||||
.card-header(v-if='settings.enable_resources' v-for='resource in event.resources' :key='resource.id' :class='{disabled: resource.hidden}')
|
||||
a.float-right(:href='resource.data.url')
|
||||
small {{resource.data.published|datetime}}
|
||||
div.mt-1(v-html='resource_filter(resource.data.content)')
|
||||
img(v-for='img in resource.data.media_attachments' :src='img.url')
|
||||
el-dropdown
|
||||
el-button(type="primary" icon="el-icon-arrow-down" size='mini') {{$t('common.moderation')}}
|
||||
el-dropdown-menu(slot='dropdown')
|
||||
el-dropdown-item(v-if='!comment.hidden' icon='el-icon-remove' @click.native='hideComment(comment, true)') {{$t('admin.hide_resource')}}
|
||||
el-dropdown-item(v-else icon='el-icon-success' @click.native='hideComment(comment, false)') {{$t('admin.show_resource')}}
|
||||
el-dropdown-item(icon='el-icon-delete' @click.native='removeComment(comment)') {{$t('admin.remove_resource')}}
|
||||
el-dropdown-item(icon='el-icon-lock' @click.native='blockUser(comment)') {{$t('admin.block_user')}}
|
||||
el-dropdown-item(v-if='!resource.hidden' icon='el-icon-remove' @click.native='hideResource(resource, true)') {{$t('admin.hide_resource')}}
|
||||
el-dropdown-item(v-else icon='el-icon-success' @click.native='hideResource(resource, false)') {{$t('admin.show_resource')}}
|
||||
el-dropdown-item(icon='el-icon-delete' @click.native='removeResource(resource)') {{$t('admin.remove_resource')}}
|
||||
el-dropdown-item(icon='el-icon-lock' @click.native='blockUser(resource)') {{$t('admin.block_user')}}
|
||||
|
||||
</template>
|
||||
<script>
|
||||
|
@ -201,10 +201,6 @@ export default {
|
|||
computed: {
|
||||
...mapGetters(['filteredEvents']),
|
||||
...mapState(['settings']),
|
||||
fedi_user() {
|
||||
// TODO:
|
||||
return this.settings.fedi_admin
|
||||
},
|
||||
next() {
|
||||
let found = false
|
||||
const event = this.filteredEvents.find(e => {
|
||||
|
@ -262,29 +258,29 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
async hideComment (comment, hidden) {
|
||||
await this.$axios.$post(`/comments/${comment.id}`, { hidden })
|
||||
comment.hidden = hidden
|
||||
async hideResource (resource, hidden) {
|
||||
await this.$axios.$put(`/resources/${resource.id}`, { hidden })
|
||||
resource.hidden = hidden
|
||||
},
|
||||
async blockUser (comment) {
|
||||
await this.$axios.post('/instances/toggle_user_block', { user_id: comment.fedUserApId })
|
||||
Message({ message: this.$t('admin.user_blocked', {user: comment.fedUserApId}), type: 'success', showClose: true })
|
||||
async blockUser (resource) {
|
||||
await this.$axios.post('/instances/toggle_user_block', { user_id: resource.apUserApId })
|
||||
Message({ message: this.$t('admin.user_blocked', {user: resource.apUserApId}), type: 'success', showClose: true })
|
||||
},
|
||||
async removeComment (comment) {
|
||||
async removeResource (resource) {
|
||||
MessageBox.confirm(this.$t('admin.remove_resource_confirm'),
|
||||
this.$t('common.confirm'), {
|
||||
confirmButtonText: this.$t('common.ok'),
|
||||
cancelButtonText: this.$t('common.cancel'),
|
||||
type: 'error'
|
||||
}).then(async () => {
|
||||
await this.$axios.delete(`/comments/${comment.id}`)
|
||||
this.event.comments = this.event.comments.filter(c => c.id !== comment.id)
|
||||
await this.$axios.delete(`/resources/${resource.id}`)
|
||||
this.event.resources = this.event.resources.filter(r => r.id !== resources.id)
|
||||
})
|
||||
},
|
||||
copyLink() {
|
||||
Message({ message: this.$t('common.copied'), type: 'success', showClose: true })
|
||||
},
|
||||
comment_filter(value) {
|
||||
resource_filter(value) {
|
||||
return value.replace(
|
||||
/<a.*href="([^">]+).*>(?:.(?!<\/a>))*.<\/a>/,
|
||||
(orig, url) => {
|
||||
|
@ -379,7 +375,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
#comments {
|
||||
#resources {
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import Vue from 'vue'
|
||||
import moment from 'moment-timezone'
|
||||
import url from 'url'
|
||||
|
||||
export default ({ app, store }) => {
|
||||
// set timezone to instance_timezone!!
|
||||
|
@ -10,7 +11,6 @@ export default ({ app, store }) => {
|
|||
// replace links with anchors
|
||||
// TODO: remove fb tracking id
|
||||
Vue.filter('linkify', value => value.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1">$2</a>'))
|
||||
|
||||
Vue.filter('url2host', url => url.match(/^https?:\/\/(.[^/:]+)/i)[1])
|
||||
Vue.filter('datetime', value => moment(value).locale(store.state.locale).format('ddd, D MMMM HH:mm'))
|
||||
|
||||
|
|
|
@ -2,29 +2,28 @@ const crypto = require('crypto')
|
|||
const moment = require('moment-timezone')
|
||||
const { Op } = require('sequelize')
|
||||
const lodash = require('lodash')
|
||||
const { event: Event, comment: Comment, tag: Tag, place: Place,
|
||||
user: User, notification: Notification } = require('../models')
|
||||
const { event: Event, resource: Resource, tag: Tag, place: Place, notification: Notification } = require('../models')
|
||||
const Sequelize = require('sequelize')
|
||||
const exportController = require('./export')
|
||||
const debug = require('debug')('controller:event')
|
||||
|
||||
const eventController = {
|
||||
|
||||
/** add a comment to event
|
||||
/** add a resource to event
|
||||
* @todo not used anywhere, should we use with webmention?
|
||||
* @todo should we use this for roply coming from fediverse?
|
||||
*/
|
||||
async addComment (req, res) {
|
||||
// comments could be added to an event or to another comment
|
||||
let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
||||
if (!event) {
|
||||
const comment = await Comment.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } }, include: Event })
|
||||
event = comment.event
|
||||
}
|
||||
const comment = new Comment(req.body)
|
||||
event.addComment(comment)
|
||||
res.json(comment)
|
||||
},
|
||||
// async addComment (req, res) {
|
||||
// // comments could be added to an event or to another comment
|
||||
// let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
||||
// if (!event) {
|
||||
// const comment = await Resource.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } }, include: Event })
|
||||
// event = comment.event
|
||||
// }
|
||||
// const comment = new Comment(req.body)
|
||||
// event.addComment(comment)
|
||||
// res.json(comment)
|
||||
// },
|
||||
|
||||
async getMeta (req, res) {
|
||||
const places = await Place.findAll({
|
||||
|
@ -94,11 +93,10 @@ const eventController = {
|
|||
},
|
||||
include: [
|
||||
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
||||
{ model: User, attributes: ['username'] },
|
||||
{ model: Place, attributes: ['name', 'address'] },
|
||||
{ model: Comment, where: !is_admin && { hidden: false }, required: false }
|
||||
{ model: Resource, where: !is_admin && { hidden: false }, required: false }
|
||||
],
|
||||
order: [ [Comment, 'id', 'DESC'] ]
|
||||
order: [ [Resource, 'id', 'DESC'] ]
|
||||
})
|
||||
|
||||
if (event && (event.is_visible || is_admin)) {
|
||||
|
@ -230,12 +228,11 @@ const eventController = {
|
|||
attributes: { exclude: [ 'createdAt', 'updatedAt', 'placeId' ] },
|
||||
order: [[Tag, 'weigth', 'DESC']],
|
||||
include: [
|
||||
{ model: Comment, required: false, attributes: ['id'] },
|
||||
{ model: Resource, required: false, attributes: ['id'] },
|
||||
{ model: Tag, required: false },
|
||||
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
|
||||
]
|
||||
})
|
||||
|
||||
events = events.map(e => e.get()).map(e => {
|
||||
e.tags = e.tags.map(t => t.tag)
|
||||
return e
|
||||
|
|
30
server/api/controller/resource.js
Normal file
30
server/api/controller/resource.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const { resource: Resource } = require('../models')
|
||||
|
||||
const resourceController = {
|
||||
async hide (req, res) {
|
||||
const resource_id = req.params.resource_id
|
||||
const hidden = req.body.hidden
|
||||
const resource = await Resource.findByPk(resource_id)
|
||||
await resource.update({ hidden })
|
||||
res.json(resource)
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
const resource_id = req.params.resource_id
|
||||
const resource = await Resource.findByPk(resource_id)
|
||||
await resource.destroy()
|
||||
res.sendStatus(200)
|
||||
},
|
||||
|
||||
async getAll (req, res) {
|
||||
const limit = req.body.limit || 100
|
||||
// const where = {}
|
||||
// if (req.params.instanceId) {
|
||||
// where =
|
||||
//
|
||||
const resources = await Resource.findAll({ limit })
|
||||
res.json(resources)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = resourceController
|
|
@ -8,8 +8,9 @@ const eventController = require('./controller/event')
|
|||
const exportController = require('./controller/export')
|
||||
const userController = require('./controller/user')
|
||||
const settingsController = require('./controller/settings')
|
||||
const instancesController = require('./controller/instances')
|
||||
const fedUserController = require('./controller/fed_user')
|
||||
const instanceController = require('./controller/instance')
|
||||
const apUserController = require('./controller/ap_user')
|
||||
const resourceController = require('./controller/resource')
|
||||
|
||||
const storage = require('./storage')
|
||||
const upload = multer({ storage })
|
||||
|
@ -84,12 +85,13 @@ api.get('/export/:type', exportController.export)
|
|||
// get events in this range
|
||||
api.get('/event/:month/:year', eventController.getAll)
|
||||
|
||||
api.get('/instances', isAdmin, instancesController.getAll)
|
||||
api.get('/instances/:instance_domain', isAdmin, instancesController.get)
|
||||
api.post('/instances/toggle_block', isAdmin, instancesController.toggleBlock)
|
||||
api.post('/instances/toggle_user_block', isAdmin, fedUserController.toggleBlock)
|
||||
api.post('/comments/:comment_id', isAdmin, fedUserController.hideComment)
|
||||
api.delete('/comments/:comment_id', isAdmin, fedUserController.removeComment)
|
||||
api.get('/instances', isAdmin, instanceController.getAll)
|
||||
api.get('/instances/:instance_domain', isAdmin, instanceController.get)
|
||||
api.post('/instances/toggle_block', isAdmin, instanceController.toggleBlock)
|
||||
api.post('/instances/toggle_user_block', isAdmin, apUserController.toggleBlock)
|
||||
api.put('/resources/:resource_id', isAdmin, resourceController.hide)
|
||||
api.delete('/resources/:resource_id', isAdmin, resourceController.remove)
|
||||
api.get('/resources', isAdmin, resourceController.getAll)
|
||||
|
||||
// Handle 404
|
||||
api.use((req, res) => {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const comment = sequelize.define('comment', {
|
||||
activitypub_id: {
|
||||
type: DataTypes.STRING,
|
||||
index: true,
|
||||
unique: true
|
||||
},
|
||||
hidden: DataTypes.BOOLEAN,
|
||||
fedUserApId: {
|
||||
type: DataTypes.STRING,
|
||||
references: {
|
||||
model: 'fed_users',
|
||||
key: 'ap_id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
data: DataTypes.JSON
|
||||
}, {})
|
||||
comment.associate = function (models) {
|
||||
comment.belongsTo(models.event)
|
||||
comment.belongsTo(models.fed_users)
|
||||
}
|
||||
return comment
|
||||
}
|
|
@ -2,7 +2,7 @@ const config = require('config')
|
|||
const moment = require('moment')
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const event = sequelize.define('event', {
|
||||
const Event = sequelize.define('event', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
type: DataTypes.INTEGER,
|
||||
|
@ -29,15 +29,15 @@ module.exports = (sequelize, DataTypes) => {
|
|||
boost: { type: DataTypes.JSON, defaultValue: [] }
|
||||
}, {})
|
||||
|
||||
event.associate = function (models) {
|
||||
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)
|
||||
Event.associate = function (models) {
|
||||
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.resource)
|
||||
}
|
||||
|
||||
event.prototype.toAP = function (username, follower = []) {
|
||||
Event.prototype.toNoteAP = function (username, follower = []) {
|
||||
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>`
|
||||
|
@ -82,5 +82,5 @@ module.exports = (sequelize, DataTypes) => {
|
|||
}
|
||||
}
|
||||
|
||||
return event
|
||||
return Event
|
||||
}
|
||||
|
|
20
server/api/models/resource.js
Normal file
20
server/api/models/resource.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
|
||||
const Resource = sequelize.define('resource', {
|
||||
activitypub_id: {
|
||||
type: DataTypes.STRING,
|
||||
index: true,
|
||||
unique: true
|
||||
},
|
||||
hidden: DataTypes.BOOLEAN,
|
||||
data: DataTypes.JSON
|
||||
}, {})
|
||||
|
||||
Resource.associate = function (models) {
|
||||
// Resource.belongsTo(models.instance)
|
||||
Resource.belongsTo(models.event)
|
||||
Resource.belongsTo(models.ap_user)
|
||||
}
|
||||
|
||||
return Resource
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
const { event: Event, comment: Comment } = require('../api/models')
|
||||
const debug = require('debug')('fediverse:comment')
|
||||
|
||||
module.exports = {
|
||||
async create (req, res) {
|
||||
const body = req.body
|
||||
// search for related event
|
||||
const inReplyTo = body.object.inReplyTo
|
||||
const match = inReplyTo.match('.*/federation/m/(.*)')
|
||||
if (!match || match.length < 2) {
|
||||
debug('Comment not found %s', inReplyTo)
|
||||
return res.status(404).send('Event not found!')
|
||||
}
|
||||
let event = await Event.findByPk(Number(match[1]))
|
||||
|
||||
debug('comment coming for %s', inReplyTo)
|
||||
if (!event) {
|
||||
// in reply to another comment...
|
||||
const comment = await Comment.findOne({ where: { activitypub_id: inReplyTo }, include: [Event] })
|
||||
if (!comment) { return res.status(404).send('Not found') }
|
||||
event = comment.event
|
||||
}
|
||||
debug('comment from %s to "%s"', req.body.actor, event.title)
|
||||
|
||||
await Comment.create({
|
||||
activitypub_id: body.object.id,
|
||||
fedUserApId: req.body.actor,
|
||||
data: body.object,
|
||||
eventId: event.id
|
||||
})
|
||||
|
||||
res.sendStatus(201)
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
const comment = await Comment.findOne({ where: { activitypub_id: req.body.object.id } })
|
||||
if (!comment) {
|
||||
debug('Comment %s not found', req.body.object.id)
|
||||
return res.status(404).send('Not found')
|
||||
}
|
||||
await comment.destroy()
|
||||
debug('Comment %s removed!', req.body.object.id)
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
const config = require('config')
|
||||
const Helpers = require('./helpers')
|
||||
const { user: User, fed_users: FedUsers } = require('../api/models')
|
||||
const crypto = require('crypto')
|
||||
const debug = require('debug')('federation:follows')
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ const router = express.Router()
|
|||
const cors = require('cors')
|
||||
const Follows = require('./follows')
|
||||
const Users = require('./users')
|
||||
const { event: Event, user: User, tag: Tag, place: Place } = require('../api/models')
|
||||
const { Event, User, Tag, Place } = require('../api/models')
|
||||
const settingsController = require('../api/controller/settings')
|
||||
const Comments = require('./comments')
|
||||
const Resources = require('./resources')
|
||||
const Helpers = require('./helpers')
|
||||
const Ego = require('./ego')
|
||||
const debug = require('debug')('federation')
|
||||
|
@ -65,12 +65,12 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||
Ego.bookmark(req, res)
|
||||
break
|
||||
case 'Delete':
|
||||
await Comments.remove(req, res)
|
||||
await Resources.remove(req, res)
|
||||
break
|
||||
case 'Create':
|
||||
// this is a reply
|
||||
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
||||
await Comments.create(req, res)
|
||||
await Resources.create(req, res)
|
||||
} else {
|
||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
||||
}
|
||||
|
|
52
server/federation/resources.js
Normal file
52
server/federation/resources.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
const { event: Event, resource: Resource } = require('../api/models')
|
||||
const debug = require('debug')('fediverse:resource')
|
||||
const sanitize = require('sanitize-html')
|
||||
module.exports = {
|
||||
|
||||
async create (req, res) {
|
||||
const body = req.body
|
||||
|
||||
// search for related event
|
||||
const inReplyTo = body.object.inReplyTo
|
||||
const match = inReplyTo.match('.*/federation/m/(.*)')
|
||||
if (!match || match.length < 2) {
|
||||
debug('Resource not found %s', inReplyTo)
|
||||
return res.status(404).send('Event not found!')
|
||||
}
|
||||
|
||||
let event = await Event.findByPk(Number(match[1]))
|
||||
debug('Resource coming for %s', inReplyTo)
|
||||
if (!event) {
|
||||
// in reply to another resource...
|
||||
const resource = await Resource.findOne({ where: { activitypub_id: inReplyTo }, include: [Event] })
|
||||
if (!resource) { return res.status(404).send('Not found') }
|
||||
event = resource.event
|
||||
}
|
||||
debug('resource from %s to "%s"', req.body.actor, event.title)
|
||||
|
||||
// clean resource
|
||||
body.object.content = sanitize(body.object.content, {
|
||||
nonTextTags: ['span', 'style', 'script', 'textarea', 'noscript']
|
||||
})
|
||||
|
||||
await Resource.create({
|
||||
activitypub_id: body.object.id,
|
||||
apUserApId: req.body.actor,
|
||||
data: body.object,
|
||||
eventId: event.id
|
||||
})
|
||||
|
||||
res.sendStatus(201)
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
const resource = await Resource.findOne({ where: { activitypub_id: req.body.object.id } })
|
||||
if (!resource) {
|
||||
debug('Comment %s not found', req.body.object.id)
|
||||
return res.status(404).send('Not found')
|
||||
}
|
||||
await resource.destroy()
|
||||
debug('Comment %s removed!', req.body.object.id)
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
}
|
|
@ -1,14 +1,13 @@
|
|||
const { user: User, event: Event, place: Place, tag: Tag, fed_users: FedUsers } = require('../api/models')
|
||||
const { User, Event, Place, Tag, APUser } = require('../api/models')
|
||||
const config = require('config')
|
||||
const get = require('lodash/get')
|
||||
const debug = require('debug')('fediverse:user')
|
||||
|
||||
module.exports = {
|
||||
async get (req, res) {
|
||||
get (req, res) {
|
||||
const name = req.params.name
|
||||
if (!name) { return res.status(400).send('Bad request.') }
|
||||
const user = await User.findOne({ where: { username: name } })
|
||||
if (!user) { return res.status(404).send(`No record found for ${name}`) }
|
||||
// const user = await User.findOne({ where: { username: name } })
|
||||
if (name !== req.settings.instance_name) { return res.status(404).send(`No record found for ${name}`) }
|
||||
const ret = {
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
|
|
25
server/migrations/20191127234917-rename_comment_resource.js
Normal file
25
server/migrations/20191127234917-rename_comment_resource.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
/*
|
||||
Add altering commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||
*/
|
||||
return queryInterface.renameTable('comments', 'resources')
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
/*
|
||||
Add reverting commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.dropTable('users');
|
||||
*/
|
||||
return queryInterface.renameTable('resources', 'comments')
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue