Skip to content

Commit a9d0373

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

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
@@ -668,3 +668,24 @@ def _get_current_persona(self):
668668
if not self.env.user or self.env.user._is_public():
669669
return (self.env["res.users"], self.env["mail.guest"]._get_guest_from_context())
670670
return (self.env.user, self.env["mail.guest"])
671+
672+
def _webpush_notification(self, body, model, res_id, icon, title='Odoo', author=None, extra_payload=None):
673+
if extra_payload is None:
674+
extra_payload = {}
675+
devices, private_key, public_key = self.env['mail.thread']._web_push_get_partners_parameters(self.partner_id.ids)
676+
if devices:
677+
payload_webpush = {
678+
'title': title,
679+
'options': {
680+
'vibrate': [100, 50, 100],
681+
'tag': f'{model}_{res_id}',
682+
'body': body,
683+
'icon': icon or '/web/static/img/odoo-icon-192x192.png',
684+
'data': {
685+
'author_name': author.name if author and author.name else self.env.ref('base.partner_root').name,
686+
'model': model or 'res.users',
687+
'res_id': res_id or self.id,
688+
},
689+
}
690+
} | extra_payload
691+
self.env['mail.thread']._web_push_send_notification(devices, private_key, public_key, payload=payload_webpush)

0 commit comments

Comments
 (0)