From cf76d1bf9fea780ba5793db2cad547e3bdd9fbcc Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 17 Apr 2023 13:23:36 +0200 Subject: [PATCH] MDL-77893 airnotifier: Apply payload size optimisation to all push --- .../airnotifier/message_output_airnotifier.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/message/output/airnotifier/message_output_airnotifier.php b/message/output/airnotifier/message_output_airnotifier.php index 1873326b7d2..677dbaf1ff2 100644 --- a/message/output/airnotifier/message_output_airnotifier.php +++ b/message/output/airnotifier/message_output_airnotifier.php @@ -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; }