From f6dcfc7dc4d4e996a987b9df3914c459dfae4005 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 28 Nov 2024 20:23:11 +0700 Subject: [PATCH 1/6] Don't require email templates presence for webpush notifications. Fixes #91. --- notification/method/webpush.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index cde21d7..0a01a45 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -97,7 +97,7 @@ public function get_type(): string */ public function is_available(type_interface $notification_type = null): bool { - return parent::is_available($notification_type) && $this->config['wpn_webpush_enable'] + return $this->config['wpn_webpush_enable'] && !empty($this->config['wpn_webpush_vapid_public']) && !empty($this->config['wpn_webpush_vapid_private']); } From a6b22fb1d1910eda214d36665e70887d2d8e2a1b Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 28 Nov 2024 22:26:11 +0700 Subject: [PATCH 2/6] Adjust code logic. --- notification/method/webpush.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index 0a01a45..e78fa64 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -98,7 +98,8 @@ public function get_type(): string public function is_available(type_interface $notification_type = null): bool { return $this->config['wpn_webpush_enable'] - && !empty($this->config['wpn_webpush_vapid_public']) && !empty($this->config['wpn_webpush_vapid_private']); + && $this->config['wpn_webpush_vapid_public'] + && $this->config['wpn_webpush_vapid_private']; } /** From 8c3dd7b479f601e879e57e9d1f6db583a27e1233 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 28 Nov 2024 22:50:25 +0700 Subject: [PATCH 3/6] Inherit from the base class instead of messenger_base --- notification/method/webpush.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index e78fa64..dd3c9ce 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -15,7 +15,6 @@ use phpbb\controller\helper; use phpbb\db\driver\driver_interface; use phpbb\log\log_interface; -use phpbb\notification\method\messenger_base; use phpbb\notification\type\type_interface; use phpbb\path_helper; use phpbb\user; @@ -27,7 +26,7 @@ * Web Push notification method class * This class handles sending push messages for notifications */ -class webpush extends messenger_base implements extended_method_interface +class webpush extends \phpbb\notification\method\base implements extended_method_interface { /** @var config */ protected $config; @@ -78,8 +77,11 @@ public function __construct(config $config, driver_interface $db, log_interface $this->config = $config; $this->db = $db; $this->log = $log; + $this->user_loader = $user_loader; $this->user = $user; $this->path_helper = $path_helper; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; $this->notification_webpush_table = $notification_webpush_table; $this->push_subscriptions_table = $push_subscriptions_table; } From 736c9f159c1bb5e0ae9fbc98041de474dae5389c Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 28 Nov 2024 22:57:37 +0700 Subject: [PATCH 4/6] Fix tests --- notification/method/webpush.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index dd3c9ce..a76b7c3 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -15,6 +15,7 @@ use phpbb\controller\helper; use phpbb\db\driver\driver_interface; use phpbb\log\log_interface; +use phpbb\notification\method\base; use phpbb\notification\type\type_interface; use phpbb\path_helper; use phpbb\user; @@ -26,7 +27,7 @@ * Web Push notification method class * This class handles sending push messages for notifications */ -class webpush extends \phpbb\notification\method\base implements extended_method_interface +class webpush extends base implements extended_method_interface { /** @var config */ protected $config; @@ -72,8 +73,6 @@ class webpush extends \phpbb\notification\method\base implements extended_method public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, path_helper $path_helper, string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table) { - parent::__construct($user_loader, $phpbb_root_path, $php_ext); - $this->config = $config; $this->db = $db; $this->log = $log; From a38a995bd846833e12818513789a45a28fbba8e3 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 30 Nov 2024 10:57:43 +0700 Subject: [PATCH 5/6] Use offsetGet() for config values check. --- notification/method/webpush.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index a76b7c3..b289612 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -98,9 +98,9 @@ public function get_type(): string */ public function is_available(type_interface $notification_type = null): bool { - return $this->config['wpn_webpush_enable'] - && $this->config['wpn_webpush_vapid_public'] - && $this->config['wpn_webpush_vapid_private']; + return $this->config->offsetGet('wpn_webpush_enable') + && $this->config->offsetGet('wpn_webpush_vapid_public') + && $this->config->offsetGet('wpn_webpush_vapid_private'); } /** From 591a08c51af425771d0cdcb8a85d373536c315be Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 30 Nov 2024 11:47:52 +0700 Subject: [PATCH 6/6] Add missing class property definitions --- notification/method/webpush.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/notification/method/webpush.php b/notification/method/webpush.php index b289612..8ecacd2 100644 --- a/notification/method/webpush.php +++ b/notification/method/webpush.php @@ -38,12 +38,21 @@ class webpush extends base implements extended_method_interface /** @var log_interface */ protected $log; + /** @var user_loader */ + protected $user_loader; + /** @var user */ protected $user; /** @var path_helper */ protected $path_helper; + /** @var string */ + protected $phpbb_root_path; + + /** @var string */ + protected $php_ext; + /** @var string Notification Web Push table */ protected $notification_webpush_table;