Skip to content

Commit

Permalink
Add subscribe button to notification dropdown
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <[email protected]>
  • Loading branch information
iMattPro committed May 27, 2024
1 parent 301ff6b commit 9b88475
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- '@phpbb.wpn.form_helper'
- '@language'
- '@template'
- '@notification_manager'
tags:
- { name: event.listener }

Expand Down
26 changes: 18 additions & 8 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
use phpbb\controller\helper as controller_helper;
use phpbb\webpushnotifications\form\form_helper;
use phpbb\language\language;
use phpbb\notification\manager;
use phpbb\template\template;

/**
* Event listener
*/
class listener implements EventSubscriberInterface
{
/**
* @var manager
*/
private $phpbb_notifications;

public static function getSubscribedEvents()
{
return [
'core.ucp_notifications_output_notification_types_modify_template_vars' => 'load_template_data',
'core.ucp_display_module_before' => 'load_language',
'core.acp_main_notice' => 'compatibility_notice',
'core.page_header_after' => 'service_worker_url',
'core.page_header_after' => [['load_template_data'], ['service_worker_url']],
];
}

Expand All @@ -53,25 +58,30 @@ public static function getSubscribedEvents()
* @param form_helper $form_helper Form helper object
* @param language $language Language object
* @param template $template Template object
* @param manager $phpbb_notifications Notifications manager object
*/
public function __construct(controller_helper $controller_helper, form_helper $form_helper, language $language, template $template)
public function __construct(controller_helper $controller_helper, form_helper $form_helper, language $language, template $template, manager $phpbb_notifications)
{
$this->controller_helper = $controller_helper;
$this->form_helper = $form_helper;
$this->language = $language;
$this->template = $template;
$this->phpbb_notifications = $phpbb_notifications;
}

/**
* Load template data
*
* @param \phpbb\event\data $event
*/
public function load_template_data($event)
public function load_template_data()
{
if ($event['method_data']['id'] === 'notification.method.phpbb.wpn.webpush')
$methods = $this->phpbb_notifications->get_subscription_methods();
if (array_key_exists('notification.method.phpbb.wpn.webpush', $methods))
{
$template_ary = $event['method_data']['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
if (!$this->language->is_set('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH'))
{
$this->language->add_lang('webpushnotifications_module_ucp', 'phpbb/webpushnotifications');
}
$template_ary = $methods['notification.method.phpbb.wpn.webpush']['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
$this->template->assign_vars($template_ary);
}
}
Expand Down
2 changes: 2 additions & 0 deletions language/en/webpushnotifications_module_ucp.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

$lang = array_merge($lang, [
'NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH' => 'Web Push',
'NOTIFY_WEBPUSH_ENABLE_SHORT' => 'Enable Web Push notifications',
'NOTIFY_WEBPUSH_ENABLE' => 'Enable receiving Web Push notifications',
'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enable receiving browser-based push notifications.<br>The notifications can be turned off at any time in your browser settings, by unsubscribing, or by disabling the push notifications below.',
'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Subscribe',
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Unsubscribe',
'NOTIFY_WEBPUSH_SUBSCRIBED' => 'Subscribed',
]);
12 changes: 12 additions & 0 deletions styles/prosilver/theme/phpbb_wpn.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@
.button.hidden {
display: none;
}

.wpn-notification-dropdown-footer {
font-size: 12px;
border-top: solid 1px #b9b9b9;
display: flex;
justify-content: space-evenly;
padding: 5px;
}

.wpn-notification-dropdown-footer button:disabled {
opacity: 0.7;
}

0 comments on commit 9b88475

Please sign in to comment.