add support for Gotify push notifications
This commit is contained in:
@@ -7,6 +7,7 @@ const PasswordReset = require('./PasswordReset.model')
|
||||
const AppAuthorization = require('./AppAuthorization.model')
|
||||
const AppPassword = require('./AppPassword.model')
|
||||
const uuid = require('uuid').v4
|
||||
const NotifyConfig = require('../system/NotifyConfig.model')
|
||||
|
||||
/*
|
||||
* Auth user model. This inherits fields and methods from the default
|
||||
@@ -36,6 +37,7 @@ class User extends AuthUser {
|
||||
create_date: {type: Date, default: () => new Date},
|
||||
photo_file_id: String,
|
||||
trap: String,
|
||||
notify_config: NotifyConfig,
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
42
app/models/system/NotifyConfig.model.js
Normal file
42
app/models/system/NotifyConfig.model.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
|
||||
class NotifyConfigModel extends Model {
|
||||
static get services() {
|
||||
return [...super.services, 'notify', 'configs', 'jobs']
|
||||
}
|
||||
|
||||
static get schema() {
|
||||
return {
|
||||
user_id: String,
|
||||
gateway_url: String,
|
||||
application_key: String,
|
||||
created_on: { type: Date, default: () => new Date },
|
||||
active: { type: Boolean, default: true },
|
||||
}
|
||||
}
|
||||
|
||||
async to_api() {
|
||||
return {
|
||||
user_id: this.user_id,
|
||||
gateway_url: this.gateway_url,
|
||||
application_key: this.application_key,
|
||||
created_on: this.created_on,
|
||||
active: this.active,
|
||||
}
|
||||
}
|
||||
|
||||
async send({ title = '', message, priority = 5 }) {
|
||||
if ( !title ) title = this.configs.get('app.name')
|
||||
this.notify.host = this.gateway_url
|
||||
await this.notify.send_one(this.application_key, title, message, priority)
|
||||
this.notify.host = false
|
||||
}
|
||||
|
||||
async log({ title = '', message, priority = 5 }) {
|
||||
await this.jobs.queue('notifications').add('PushNotify', {
|
||||
title, message, priority, user_id: this.user_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = NotifyConfigModel
|
||||
Reference in New Issue
Block a user