fix #27, fix #25, fix #26, fix #20, fix #19

This commit is contained in:
lesion
2019-03-18 01:42:42 +01:00
parent b93cf91dbd
commit 7111b4578b
31 changed files with 270 additions and 70 deletions

View File

@@ -14,7 +14,7 @@ async function sendNotification (notification, event, eventNotification) {
const p = mail.send(notification.email, 'event', { event })
promises.push(p)
break
case 'mail_admin':
case 'admin_email':
const admins = await User.findAll({ where: { is_admin: true } })
promises.push(admins.map(admin =>
mail.send(admin.email, 'event', { event, to_confirm: true, notification })))
@@ -26,7 +26,7 @@ async function sendNotification (notification, event, eventNotification) {
promises.push(b)
}
// user publish
if (event.user && event.user.mastodon_auth) {
if (event.user && event.user.mastodon_auth && event.user.mastodon_auth.access_token) {
const b = bot.post(event.user.mastodon_auth, event).then(ret => {
event.activitypub_id = ret.id
return event.save()
@@ -45,17 +45,24 @@ async function sendNotification (notification, event, eventNotification) {
async function loop () {
settings = await settingsController.settings()
// get all event notification in queue
const eventNotifications = await EventNotification.findAll()
const eventNotifications = await EventNotification.findAll({ where: { status: 'new' } })
const promises = eventNotifications.map(async e => {
const event = await Event.findByPk(e.eventId, { include: [User, Place, Tag] })
if (!event.place) return
const notification = await Notification.findByPk(e.notificationId)
await sendNotification(notification, event, e)
e.destroy()
try {
await sendNotification(notification, event, e)
e.status = 'sent'
e.save()
} catch (e) {
console.error(e)
e.status = 'error'
return e.save()
}
})
return Promise.all(promises)
}
setInterval(loop, 20000)
setInterval(loop, 260000)
loop()