mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
fix notifications
This commit is contained in:
parent
0a51c42fe0
commit
5a5c62efb4
5 changed files with 24 additions and 26 deletions
|
@ -305,10 +305,11 @@ const eventController = {
|
|||
// without waiting for the task manager
|
||||
if (event.recurrent) {
|
||||
eventController._createRecurrent()
|
||||
} else {
|
||||
// send notifications (mastodon / email)
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
}
|
||||
// send notifications (mastodon / email)
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
} catch (e) {
|
||||
debug(e)
|
||||
res.sendStatus(400)
|
||||
|
@ -373,10 +374,10 @@ const eventController = {
|
|||
// without waiting for the task manager
|
||||
if (event.recurrent) {
|
||||
eventController._createRecurrent()
|
||||
} else {
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Update', event.id)
|
||||
}
|
||||
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Update', event.id)
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
|
|
|
@ -7,6 +7,7 @@ const sequelize = require('./index')
|
|||
|
||||
const Resource = require('./resource')
|
||||
const Notification = require('./notification')
|
||||
const EventNotification = require('./eventnotification')
|
||||
const Place = require('./place')
|
||||
const User = require('./user')
|
||||
const Tag = require('./tag')
|
||||
|
@ -43,13 +44,16 @@ Event.belongsTo(Place)
|
|||
Place.hasMany(Event)
|
||||
|
||||
Event.belongsTo(User)
|
||||
User.hasMany(Event)
|
||||
|
||||
Event.belongsToMany(Tag, { through: 'event_tags' })
|
||||
|
||||
Event.belongsToMany(Notification, { through: 'event_notification' })
|
||||
Notification.belongsToMany(Event, { through: 'event_notification' })
|
||||
Event.belongsToMany(Notification, { through: EventNotification })
|
||||
Notification.belongsToMany(Event, { through: EventNotification })
|
||||
|
||||
Event.hasMany(Resource)
|
||||
Resource.belongsTo(Event)
|
||||
|
||||
Event.hasMany(Event, { as: 'child', foreignKey: 'parentId' })
|
||||
Event.belongsTo(Event, { as: 'parent' })
|
||||
|
||||
|
@ -62,7 +66,7 @@ Event.prototype.toAP = function (username, locale, to = []) {
|
|||
|
||||
${plainDescription}
|
||||
|
||||
${tags.map(t => `#${t}`)}
|
||||
${tags && tags.map(t => `#${t}`)}
|
||||
|
||||
`
|
||||
|
||||
|
@ -90,7 +94,7 @@ Event.prototype.toAP = function (username, locale, to = []) {
|
|||
name: this.place && this.place.name
|
||||
},
|
||||
attachment,
|
||||
tag: tags.map(tag => ({
|
||||
tag: tags && tags.map(tag => ({
|
||||
type: 'Hashtag',
|
||||
name: '#' + tag,
|
||||
href: '/tags/' + tag
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
// const Event = require('./event')
|
||||
|
||||
class Notification extends Model {}
|
||||
|
||||
|
@ -27,6 +26,4 @@ Notification.init({
|
|||
}]
|
||||
})
|
||||
|
||||
// Notification.belongsToMany(Event, { through: 'event_notification' })
|
||||
|
||||
module.exports = Notification
|
||||
|
|
|
@ -3,8 +3,6 @@ const bcrypt = require('bcryptjs')
|
|||
const { Model, DataTypes } = require('sequelize')
|
||||
const sequelize = require('./index')
|
||||
|
||||
// const Event = require('./event')
|
||||
|
||||
class User extends Model {}
|
||||
|
||||
User.init({
|
||||
|
@ -36,8 +34,6 @@ User.init({
|
|||
}
|
||||
})
|
||||
|
||||
// User.hasMany(Event)
|
||||
|
||||
User.prototype.comparePassword = async function (pwd) {
|
||||
if (!this.password) { return false }
|
||||
const ret = await bcrypt.compare(pwd, this.password)
|
||||
|
|
|
@ -4,11 +4,11 @@ const debug = require('debug')('notifier')
|
|||
const fediverseHelpers = require('./federation/helpers')
|
||||
|
||||
const Event = require('./api/models/event')
|
||||
const Notification = require('./api/models/event')
|
||||
const EventNotification = require('./api/models/event')
|
||||
const User = require('./api/models/event')
|
||||
const Place = require('./api/models/event')
|
||||
const Tag = require('./api/models/event')
|
||||
const Notification = require('./api/models/notification')
|
||||
const EventNotification = require('./api/models/eventnotification')
|
||||
const User = require('./api/models/user')
|
||||
const Place = require('./api/models/place')
|
||||
const Tag = require('./api/models/tag')
|
||||
|
||||
const eventController = require('./api/controller/event')
|
||||
|
||||
|
@ -35,7 +35,7 @@ const notifier = {
|
|||
|
||||
async notifyEvent (action, eventId) {
|
||||
const event = await Event.findByPk(eventId, {
|
||||
include: [Tag, Place, Notification, { model: User }]
|
||||
include: [Tag, Place, Notification, User]
|
||||
})
|
||||
|
||||
debug('%s -> %s', action, event.title)
|
||||
|
@ -47,7 +47,7 @@ const notifier = {
|
|||
|
||||
const promises = event_notifications.map(async notification => {
|
||||
try {
|
||||
// await notification.event_notification.update({ status: 'sending' })
|
||||
await notification.event_notification.update({ status: 'sending' })
|
||||
await notifier.sendNotification(notification, event)
|
||||
notification.event_notification.status = 'sent'
|
||||
} catch (err) {
|
||||
|
@ -71,9 +71,9 @@ const notifier = {
|
|||
e.status = 'sent'
|
||||
return e.save()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
debug(err)
|
||||
e.status = 'error'
|
||||
// e.error = err
|
||||
e.error = err
|
||||
return e.save()
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue