Skip to content

Commit a60b6b3

Browse files
committed
[WIP] voip: jambonz
1 parent 9131466 commit a60b6b3

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

addons/mail/models/mail_thread.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,40 +3915,40 @@ def _web_push_send_notification(self, devices, private_key, public_key, payload_
39153915
:param payload: JSON serializable dict following the notification api specs https://notifications.spec.whatwg.org/#api
39163916
:param payload_by_lang a dict mapping payload by lang, either this or payload must be provided
39173917
"""
3918-
if len(devices) < MAX_DIRECT_PUSH:
3919-
session = Session()
3920-
devices_to_unlink = set()
3921-
for device in devices:
3922-
try:
3923-
push_to_end_point(
3924-
base_url=self.get_base_url(),
3925-
device={
3926-
'id': device.id,
3927-
'endpoint': device.endpoint,
3928-
'keys': device.keys
3929-
},
3930-
payload=json.dumps(payload_by_lang and payload_by_lang[device.partner_id.lang] or payload),
3931-
vapid_private_key=private_key,
3932-
vapid_public_key=public_key,
3933-
session=session,
3934-
)
3935-
except DeviceUnreachableError:
3936-
devices_to_unlink.add(device.id)
3937-
except Exception as e: # pylint: disable=broad-except
3938-
# Avoid blocking the whole request just for a notification
3939-
_logger.error('An error occurred while contacting the endpoint: %s', e)
3940-
3941-
# clean up obsolete devices
3942-
if devices_to_unlink:
3943-
devices_list = list(devices_to_unlink)
3944-
self.env['mail.push.device'].sudo().browse(devices_list).unlink()
3945-
3946-
else:
3947-
self.env['mail.push'].sudo().create([{
3948-
'mail_push_device_id': device.id,
3949-
'payload': json.dumps(payload_by_lang and payload_by_lang[device.partner_id.lang] or payload),
3950-
} for device in devices])
3951-
self.env.ref('mail.ir_cron_web_push_notification')._trigger()
3918+
# if len(devices) < MAX_DIRECT_PUSH:
3919+
session = Session()
3920+
devices_to_unlink = set()
3921+
for device in devices:
3922+
try:
3923+
push_to_end_point(
3924+
base_url=self.get_base_url(),
3925+
device={
3926+
'id': device.id,
3927+
'endpoint': device.endpoint,
3928+
'keys': device.keys
3929+
},
3930+
payload=json.dumps(payload_by_lang and payload_by_lang[device.partner_id.lang] or payload),
3931+
vapid_private_key=private_key,
3932+
vapid_public_key=public_key,
3933+
session=session,
3934+
)
3935+
except DeviceUnreachableError:
3936+
devices_to_unlink.add(device.id)
3937+
except Exception as e: # pylint: disable=broad-except
3938+
# Avoid blocking the whole request just for a notification
3939+
_logger.error('An error occurred while contacting the endpoint: %s', e)
3940+
3941+
# clean up obsolete devices
3942+
if devices_to_unlink:
3943+
devices_list = list(devices_to_unlink)
3944+
self.env['mail.push.device'].sudo().browse(devices_list).unlink()
3945+
3946+
# else:
3947+
# self.env['mail.push'].sudo().create([{
3948+
# 'mail_push_device_id': device.id,
3949+
# 'payload': json.dumps(payload_by_lang and payload_by_lang[device.partner_id.lang] or payload),
3950+
# } for device in devices])
3951+
# self.env.ref('mail.ir_cron_web_push_notification')._trigger()
39523952

39533953
def _notify_by_web_push_prepare_payload(self, message, msg_vals=False, force_record_name=False):
39543954
""" Returns dictionary containing message information for a browser device.

addons/mail/tools/web_push.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def push_to_end_point(base_url, device, payload, vapid_private_key, vapid_public
168168
# are not received on Edge with TTL ='0'.
169169
# Using the TTL '0' , the microsoft endpoint returns a 400 bad request error.
170170
# and we are sure that the notification will be received
171-
'TTL': '60',
171+
'TTL': '0',
172172
}
173173

174174
response = session.post(endpoint, headers=headers, data=payload, timeout=5)

0 commit comments

Comments
 (0)