Skip to content

Commit e36efb5

Browse files
committed
Merge branch 'main' into Release-1.0.0
Signed-off-by: Matt Friedman <maf675@gmail.com> # Conflicts: # CHANGELOG.md # composer.json
2 parents 92fbc48 + bf25224 commit e36efb5

File tree

11 files changed

+157
-11
lines changed

11 files changed

+157
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Changelog
22

3-
### 1.0.0 - 2024-06-05
3+
### 1.0.0 - 2024-06-16
44

55
- First official release.
66

7+
### 1.0.0-RC9 - 2024-06-16
8+
9+
- The subscribe toggle in the notification dropdown has been optimized for better mobile usability.
10+
- Notifications missed by logged-out users will now be delivered once they log back in.
11+
- Users who are unable to subscribe due to previously denying notifications in their browser settings will now see an alert message.
12+
713
### 1.0.0-RC8 - 2024-06-05
814

915
- Fixed (for real this time) an issue where push notifications failed on Android devices using Firefox.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "phpbb/webpushnotifications",
33
"type": "phpbb-extension",
44
"description": "An official phpBB extension that allows board users to receive browser-based push notifications.",
5-
"homepage": "https://www.phpbb.com",
5+
"homepage": "https://www.phpbb.com/customise/db/extension/webpushnotifications/",
66
"version": "1.0.0",
77
"license": "GPL-2.0-only",
88
"authors": [

language/en/webpushnotifications_module_ucp.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@
4646
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Unsubscribe',
4747
'NOTIFY_WEBPUSH_SUBSCRIBED' => 'Subscribed',
4848
'NOTIFY_WEBPUSH_DROPDOWN_TITLE' => 'Visit notifications settings to set your preferred push notifications.',
49+
'NOTIFY_WEBPUSH_DENIED' => 'You have denied notifications from this site. To subscribe, please allow notifications in your browser settings.',
4950
]);

language/ru/webpushnotifications_module_ucp.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@
4646
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Отписаться',
4747
'NOTIFY_WEBPUSH_SUBSCRIBED' => 'Включено',
4848
'NOTIFY_WEBPUSH_DROPDOWN_TITLE' => 'Посетите настройки уведомлений, чтобы установить предпочтительные push-уведомления.',
49+
'NOTIFY_WEBPUSH_DENIED' => 'Вы запретили браузерные уведомления для даного сайта. Для того, чтобы подписаться, необходимо их разрешить в настройках браузера.',
50+
4951
]);

migrations/add_webpush_token.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
*
4+
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\webpushnotifications\migrations;
12+
13+
use phpbb\db\migration\migration;
14+
15+
class add_webpush_token extends migration
16+
{
17+
public static function depends_on()
18+
{
19+
return ['\phpbb\webpushnotifications\migrations\add_webpush'];
20+
}
21+
22+
public function effectively_installed(): bool
23+
{
24+
return $this->db_tools->sql_column_exists($this->table_prefix . 'wpn_notification_push', 'push_token');
25+
}
26+
27+
public function update_schema(): array
28+
{
29+
return [
30+
'add_columns' => [
31+
$this->table_prefix . 'wpn_notification_push' => [
32+
'push_token' => ['VCHAR', ''],
33+
],
34+
],
35+
];
36+
}
37+
38+
public function revert_schema(): array
39+
{
40+
return [
41+
'drop_columns' => [
42+
$this->table_prefix . 'wpn_notification_push' => [
43+
'push_token',
44+
],
45+
],
46+
];
47+
}
48+
}

notification/method/webpush.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class webpush extends messenger_base implements extended_method_interface
5454
/** @var int Fallback size for padding if endpoint is mozilla, see https://github.com/web-push-libs/web-push-php/issues/108#issuecomment-2133477054 */
5555
public const MOZILLA_FALLBACK_PADDING = 2820;
5656

57+
/** @var array Map for storing push token between db insertion and sending of notifications */
58+
private $push_token_map = [];
59+
5760
/**
5861
* Notification Method Web Push constructor
5962
*
@@ -150,9 +153,11 @@ public function notify()
150153
'avatar' => $this->prepare_avatar($notification->get_avatar()),
151154
]),
152155
'notification_time' => time(),
156+
'push_token' => hash('sha256', random_bytes(32))
153157
];
154158
$data = self::clean_data($data);
155159
$insert_buffer->insert($data);
160+
$this->push_token_map[$notification->notification_type_id][$notification->item_id] = $data['push_token'];
156161
}
157162

158163
$insert_buffer->flush();
@@ -226,7 +231,9 @@ protected function notify_using_webpush(): void
226231
$data = [
227232
'item_id' => $notification->item_id,
228233
'type_id' => $notification->notification_type_id,
234+
'user_id' => $notification->user_id,
229235
'version' => $this->config['assets_version'],
236+
'token' => hash('sha256', $user['user_form_salt'] . $this->push_token_map[$notification->notification_type_id][$notification->item_id]),
230237
];
231238
$json_data = json_encode($data);
232239

@@ -342,6 +349,7 @@ public static function clean_data(array $data): array
342349
'item_parent_id' => null,
343350
'user_id' => null,
344351
'push_data' => null,
352+
'push_token' => null,
345353
'notification_time' => null,
346354
];
347355

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %}
22
<div class="wpn-notification-dropdown-footer" title="{{ lang('NOTIFY_WEBPUSH_DROPDOWN_TITLE') }}">
33
<span class="ellipsis-text">{{ lang('NOTIFY_WEBPUSH_ENABLE_SHORT') ~ lang('COLON') }}</span>
4-
<button id="subscribe_webpush" name="subscribe_webpush"><i class="icon fa-toggle-off fa-fw icon-lightgray"></i><span>{{ lang('NOTIFY_WEBPUSH_SUBSCRIBE') }}</span></button>
5-
<button id="unsubscribe_webpush" name="unsubscribe_webpush" class="hidden"><i class="icon fa-toggle-on fa-fw icon-blue"></i><span>{{ lang('NOTIFY_WEBPUSH_SUBSCRIBED') }}</span></button>
4+
<button id="subscribe_webpush" name="subscribe_webpush" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}">
5+
<i class="icon fa-toggle-off fa-fw icon-lightgray"></i><span>{{ lang('NOTIFY_WEBPUSH_SUBSCRIBE') }}</span>
6+
</button>
7+
<button id="unsubscribe_webpush" name="unsubscribe_webpush" class="hidden">
8+
<i class="icon fa-toggle-on fa-fw icon-blue"></i><span>{{ lang('NOTIFY_WEBPUSH_SUBSCRIBED') }}</span>
9+
</button>
610
</div>
711
{% endif %}

styles/all/template/push_worker.js.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ self.addEventListener('push', event => {
2323

2424
let itemId = 0;
2525
let typeId = 0;
26-
let notificationVersion = 5;
26+
let userId = 0;
27+
let notificationVersion = 0;
28+
let pushToken = '';
2729
try {
2830
const notificationData = event.data.json();
2931
itemId = notificationData.item_id;
3032
typeId = notificationData.type_id;
33+
userId = notificationData.user_id;
3134
notificationVersion = parseInt(notificationData.version, 10);
35+
pushToken = notificationData.token;
3236
} catch {
3337
self.registration.showNotification(event.data.text());
3438
return;
@@ -45,6 +49,8 @@ self.addEventListener('push', event => {
4549
const formData = new FormData();
4650
formData.append('item_id', itemId.toString(10));
4751
formData.append('type_id', typeId.toString(10));
52+
formData.append('user_id', userId.toString(10));
53+
formData.append('token', pushToken);
4854

4955
fetch(getNotificationUrl, {
5056
method: 'POST',

styles/all/template/webpush.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function PhpbbWebpush() {
150150
// Prevent the user from clicking the subscribe button multiple times.
151151
const result = await Notification.requestPermission();
152152
if (result === 'denied') {
153+
phpbb.alert(subscribeButton.getAttribute('data-l-err'), subscribeButton.getAttribute('data-l-msg'));
153154
return;
154155
}
155156

styles/prosilver/template/event/ucp_notifications_content_before.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<dl>
66
<dt><label for="subscribe_webpush">{{ lang('NOTIFY_WEBPUSH_ENABLE') ~ lang('COLON') }}</label><br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span></dt>
77
<dd>
8-
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_SUBSCRIBE') }}" class="button1 button button-form">
8+
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_SUBSCRIBE') }}" class="button1 button button-form" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}">
99
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_UNSUBSCRIBE') }}" class="button1 button button-form hidden">
1010
</dd>
1111
</dl>

0 commit comments

Comments
 (0)