Skip to content

Commit e1223e9

Browse files
authored
Merge pull request #51 from rxu/backport-mobile-mozilla-fix
Handle mozilla not properly handling webpush padding (core PR backport)
2 parents 35266fd + 73c2b68 commit e1223e9

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

notification/method/webpush.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class webpush extends messenger_base implements extended_method_interface
5151
/** @var string Notification push subscriptions table */
5252
protected $push_subscriptions_table;
5353

54+
/** @var int Fallback size for padding if endpoint is mozilla, see https://github.com/web-push-libs/web-push-php/issues/108#issuecomment-2133477054 */
55+
const MOZILLA_FALLBACK_PADDING = 2820;
56+
5457
/**
5558
* Notification Method Web Push constructor
5659
*
@@ -202,12 +205,6 @@ protected function notify_using_webpush(): void
202205

203206
$web_push = new \Minishlink\WebPush\WebPush($auth);
204207

205-
// Fix encryption payload size for Firefox on Android
206-
if (preg_match('/android.*firefox/i', $this->user->browser))
207-
{
208-
$web_push->setAutomaticPadding(2000);
209-
}
210-
211208
$number_of_notifications = 0;
212209
$remove_subscriptions = [];
213210

@@ -237,6 +234,7 @@ protected function notify_using_webpush(): void
237234
{
238235
try
239236
{
237+
$this->set_endpoint_padding($web_push, $subscription['endpoint']);
240238
$push_subscription = Subscription::create([
241239
'endpoint' => $subscription['endpoint'],
242240
'keys' => [
@@ -462,7 +460,7 @@ protected function clean_expired_subscriptions(array $user_subscription_map, arr
462460
* @param string $avatar
463461
* @return array 'src' => Absolute path to avatar image
464462
*/
465-
protected function prepare_avatar($avatar)
463+
protected function prepare_avatar($avatar): array
466464
{
467465
$pattern = '/src=["\']?([^"\'>]+)["\']?/';
468466

@@ -489,4 +487,21 @@ protected function get_board_url()
489487

490488
return $board_url;
491489
}
490+
491+
/**
492+
* Set web push padding for endpoint
493+
*
494+
* @param \Minishlink\WebPush\WebPush $web_push
495+
* @param string $endpoint
496+
*
497+
* @return void
498+
* @throws \Exception
499+
*/
500+
protected function set_endpoint_padding(\Minishlink\WebPush\WebPush $web_push, string $endpoint): void
501+
{
502+
if (strpos($endpoint, 'mozilla.com') || strpos($endpoint, 'mozaws.net'))
503+
{
504+
$web_push->setAutomaticPadding(self::MOZILLA_FALLBACK_PADDING);
505+
}
506+
}
492507
}

0 commit comments

Comments
 (0)