Skip to content

Commit 69376d3

Browse files
res-odoobrboi
authored andcommitted
[IMP] mail: add on user a direct method to send webpush notif
1 parent ed0d4e2 commit 69376d3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

addons/mail/models/res_users.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,24 @@ def action_test_outgoing_mail_server(self):
662662
@api.model
663663
def _get_mail_server_setup_end_action(self, smtp_server):
664664
raise NotImplementedError()
665+
666+
def _webpush_notification(self, body, model, res_id, icon, title='Odoo', author=None, extra_payload=None):
667+
if extra_payload is None:
668+
extra_payload = {}
669+
devices, private_key, public_key = self.env['mail.thread']._web_push_get_partners_parameters(self.partner_id.ids)
670+
if devices:
671+
payload_webpush = {
672+
'title': title,
673+
'options': {
674+
'vibrate': [100, 50, 100],
675+
'tag': f'{model}_{res_id}',
676+
'body': body,
677+
'icon': icon or '/web/static/img/odoo-icon-192x192.png',
678+
'data': {
679+
'author_name': author.name if author and author.name else self.env.ref('base.partner_root').name,
680+
'model': model or 'res.users',
681+
'res_id': res_id or self.id,
682+
},
683+
}
684+
} | extra_payload
685+
self.env['mail.thread']._web_push_send_notification(devices, private_key, public_key, payload=payload_webpush)

0 commit comments

Comments
 (0)