MDL-78072 airnotifier: Apply payload size optimisation to all push

Backport of MDL-77893.

Co-authored by: Andrew Lyons <andrew@nicols.co.uk>
This commit is contained in:
Juan Leyva 2023-04-17 13:23:36 +02:00 committed by Andrew Nicols
parent 1af4ace4d6
commit d838917d28
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14

View File

@ -133,6 +133,15 @@ class message_output_airnotifier extends message_output {
$extra->encrypted = $encryptnotifications;
$extra = $this->encrypt_payload($extra, $devicetoken);
// We use Firebase to deliver all Push Notifications, and for all device types.
// Firebase has a 4KB payload limit.
// https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
// If the message is over that limit we remove unneeded fields and replace the title with a simple message.
if (\core_text::strlen(json_encode($extra), '8bit') > 4000) {
$extra->smallmessage = get_string('view_notification', 'message_airnotifier');
}
$params = array(
'device' => $devicetoken->platform,
'token' => $devicetoken->pushid,
@ -203,14 +212,6 @@ class message_output_airnotifier extends message_output {
unset($payload->attachment);
unset($payload->attachname);
// We use Firebase to deliver all Push Notifications, and for all device types.
// Firebase has a 4KB payload limit.
// https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
// If the message is over that limit we remove unneeded fields and replace the title with a simple message.
if (\core_text::strlen(json_encode($payload), '8bit') > 4000) {
$payload->smallmessage = get_string('view_notification', 'message_airnotifier');
}
return $payload;
}