Skip to content

Commit 056eb2c

Browse files
Sven Scholzsmnandre
authored andcommitted
[Notify] Added body, icon, tag ,renotify to controller.js for mercure-notifier
Co-authored-by: Simon André <[email protected]>
1 parent 2a6c2dc commit 056eb2c

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/Notify/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.24.0
4+
5+
- Added `options` to Notification
6+
37
## 2.13.2
48

59
- Revert "Change JavaScript package to `type: module`"

src/Notify/assets/dist/controller.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export default class extends Controller {
1313
initialize(): void;
1414
connect(): void;
1515
disconnect(): void;
16-
_notify(content: string | undefined): void;
16+
_notify(title: string | undefined, options: NotificationOptions | undefined): void;
1717
private dispatchEvent;
1818
}

src/Notify/assets/dist/controller.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class default_1 extends Controller {
2626
return;
2727
}
2828
this.eventSources.forEach((eventSource) => {
29-
const listener = (event) => this._notify(JSON.parse(event.data).summary);
29+
const listener = (event) => {
30+
const { summary, content } = JSON.parse(event.data);
31+
this._notify(summary, content);
32+
};
3033
eventSource.addEventListener('message', listener);
3134
this.listeners.set(eventSource, listener);
3235
});
@@ -42,17 +45,17 @@ class default_1 extends Controller {
4245
});
4346
this.eventSources = [];
4447
}
45-
_notify(content) {
46-
if (!content)
48+
_notify(title, options) {
49+
if (!title)
4750
return;
4851
if ('granted' === Notification.permission) {
49-
new Notification(content);
52+
new Notification(title, options);
5053
return;
5154
}
5255
if ('denied' !== Notification.permission) {
5356
Notification.requestPermission().then((permission) => {
5457
if ('granted' === permission) {
55-
new Notification(content);
58+
new Notification(title, options);
5659
}
5760
});
5861
}

src/Notify/assets/src/controller.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ export default class extends Controller {
4949
}
5050

5151
this.eventSources.forEach((eventSource) => {
52-
const listener = (event: MessageEvent) => this._notify(JSON.parse(event.data).summary);
52+
const listener = (event: MessageEvent) => {
53+
const { summary, content } = JSON.parse(event.data);
54+
55+
this._notify(summary, content);
56+
};
57+
5358
eventSource.addEventListener('message', listener);
5459
this.listeners.set(eventSource, listener);
5560
});
@@ -70,19 +75,19 @@ export default class extends Controller {
7075
this.eventSources = [];
7176
}
7277

73-
_notify(content: string | undefined) {
74-
if (!content) return;
78+
_notify(title: string | undefined, options: NotificationOptions | undefined) {
79+
if (!title) return;
7580

7681
if ('granted' === Notification.permission) {
77-
new Notification(content);
82+
new Notification(title, options);
7883

7984
return;
8085
}
8186

8287
if ('denied' !== Notification.permission) {
8388
Notification.requestPermission().then((permission) => {
8489
if ('granted' === permission) {
85-
new Notification(content);
90+
new Notification(title, options);
8691
}
8792
});
8893
}

0 commit comments

Comments
 (0)