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

This commit is contained in:
Juan Leyva 2023-04-17 13:23:36 +02:00
parent 862a9fb24c
commit cf76d1bf9f

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;
}