add support for Gotify push notifications
This commit is contained in:
@@ -142,6 +142,39 @@ const template = `
|
||||
<button class="btn btn-sm btn-success" @click="on_mfa_recovery_generate">{{ t['profile.regenerate_recovery'] }}</button>
|
||||
</span>
|
||||
</li>
|
||||
<li class="list-group-item" v-if="notify_loaded">
|
||||
<h4>{{ t['profile.notifications'] }}</h4>
|
||||
<p v-html="t['profile.notify_explainer_1'].replace(/APP_NAME/g, app_name)"></p>
|
||||
<p>{{ t['profile.notify_explainer_2'].replace(/APP_NAME/g, app_name) }}</p>
|
||||
<div class="row">
|
||||
<div class="col-12 form-group">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
:placeholder="t['profile.example_gateway_url']"
|
||||
id="coreid-profile-notify-gateway-url"
|
||||
v-model="notify_gateway_url"
|
||||
>
|
||||
</div>
|
||||
<div class="col-12 form-group">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
:placeholder="t['profile.app_key']"
|
||||
id="coreid-profile-notify-app-key"
|
||||
v-model="notify_app_key"
|
||||
>
|
||||
</div>
|
||||
<div class="col-12 mt-2">
|
||||
<button class="btn btn-sm btn-primary" @click="on_notifications_save">{{ t['profile.save_notify'] }}</button>
|
||||
<button
|
||||
class="btn btn-sm btn-secondary"
|
||||
v-if="notify_app_key && notify_gateway_url && notify_enabled"
|
||||
@click="send_test_notification"
|
||||
>{{ t['profile.test_notify'] }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<coreid-form-app-password
|
||||
@@ -178,6 +211,12 @@ export default class EditProfileComponent extends Component {
|
||||
has_mfa = false
|
||||
ready = false
|
||||
|
||||
notify_gateway_url = ''
|
||||
notify_app_key = ''
|
||||
notify_enabled = false
|
||||
notify_created_on = ''
|
||||
notify_loaded = false
|
||||
|
||||
app_passwords = []
|
||||
app_name = ''
|
||||
t = {}
|
||||
@@ -221,7 +260,14 @@ export default class EditProfileComponent extends Component {
|
||||
'profile.app_pw_3',
|
||||
'profile.mfa_1',
|
||||
'profile.mfa_2',
|
||||
'mfa.enable'
|
||||
'mfa.enable',
|
||||
'profile.notifications',
|
||||
'profile.notify_explainer_1',
|
||||
'profile.notify_explainer_2',
|
||||
'profile.app_key',
|
||||
'profile.example_gateway_url',
|
||||
'profile.save_notify',
|
||||
'profile.test_notify'
|
||||
)
|
||||
|
||||
this.app_name = session.get('app.name')
|
||||
@@ -291,6 +337,20 @@ export default class EditProfileComponent extends Component {
|
||||
this.profile_email = result.email
|
||||
this.profile_tagline = result.tagline
|
||||
|
||||
const notify_config = await profile_service.get_notify(this.user_id || 'me')
|
||||
if ( !notify_config || !notify_config.has_config ) {
|
||||
this.notify_app_key = ''
|
||||
this.notify_enabled = false
|
||||
this.notify_created_on = ''
|
||||
this.notify_gateway_url = ''
|
||||
} else if ( notify_config && notify_config.has_config ) {
|
||||
this.notify_app_key = notify_config.config.application_key
|
||||
this.notify_enabled = notify_config.config.active
|
||||
this.notify_created_on = notify_config.config.created_on
|
||||
this.notify_gateway_url = notify_config.config.gateway_url
|
||||
}
|
||||
this.notify_loaded = true
|
||||
|
||||
if ( !this.user_id || this.user_id === 'me' ) {
|
||||
const reset = (await password_service.get_resets()).reverse()[0]
|
||||
if (reset && reset.reset_on) {
|
||||
@@ -421,5 +481,20 @@ export default class EditProfileComponent extends Component {
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
async on_notifications_save() {
|
||||
const data = {
|
||||
user_id: this.user_id || 'me',
|
||||
app_key: this.notify_app_key,
|
||||
gateway_url: this.notify_gateway_url,
|
||||
}
|
||||
|
||||
await profile_service.update_notify(data)
|
||||
await this.load()
|
||||
}
|
||||
|
||||
async send_test_notification() {
|
||||
await profile_service.test_notify({ user_id: this.user_id || 'me' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,23 @@ class ProfileService {
|
||||
if ( results && results.data && results.data.data ) return results.data.data
|
||||
}
|
||||
|
||||
async get_notify(user_id = 'me') {
|
||||
const results = await axios.get(`/api/v1/profile/${user_id}/notify`)
|
||||
if ( results && results.data && results.data.data ) return results.data.data
|
||||
}
|
||||
|
||||
async update_profile({ user_id, first_name, last_name, email, tagline = undefined }) {
|
||||
await axios.patch(`/api/v1/profile/${user_id}`, { first_name, last_name, email, tagline })
|
||||
}
|
||||
|
||||
async update_notify({ user_id = 'me', app_key, gateway_url }) {
|
||||
await axios.patch(`/api/v1/profile/${user_id}/notify`, { app_key, gateway_url })
|
||||
}
|
||||
|
||||
async test_notify({ user_id = 'me' }) {
|
||||
await axios.post(`/api/v1/profile/${user_id}/notify/test`)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const profile_service = new ProfileService()
|
||||
|
||||
Reference in New Issue
Block a user