Refine, docs
This commit is contained in:
@@ -163,6 +163,12 @@ const handlePushUnknown = async (data) => {
|
|||||||
const handlePush = async (data) => {
|
const handlePush = async (data) => {
|
||||||
const { message } = data;
|
const { message } = data;
|
||||||
|
|
||||||
|
// This logic is (partially) duplicated in
|
||||||
|
// - Android: SubscriberService::onNotificationReceived()
|
||||||
|
// - Android: FirebaseService::onMessageReceived()
|
||||||
|
// - Web app: hooks.js:handleNotification()
|
||||||
|
// - Web app: sw.js:handleMessage(), sw.js:handleMessageClear(), ...
|
||||||
|
|
||||||
if (message.event === EVENT_MESSAGE) {
|
if (message.event === EVENT_MESSAGE) {
|
||||||
await handlePushMessage(data);
|
await handlePushMessage(data);
|
||||||
} else if (message.event === EVENT_MESSAGE_DELETE) {
|
} else if (message.event === EVENT_MESSAGE_DELETE) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Notifier {
|
|||||||
subscriptionId: subscription.id,
|
subscriptionId: subscription.id,
|
||||||
message: notification,
|
message: notification,
|
||||||
defaultTitle,
|
defaultTitle,
|
||||||
topicRoute: new URL(routes.forSubscription(subscription), window.location.origin).toString()
|
topicRoute: new URL(routes.forSubscription(subscription), window.location.origin).toString(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ class Notifier {
|
|||||||
console.log(`[Notifier] Cancelling notification with ${tag}`);
|
console.log(`[Notifier] Cancelling notification with ${tag}`);
|
||||||
const registration = await this.serviceWorkerRegistration();
|
const registration = await this.serviceWorkerRegistration();
|
||||||
const notifications = await registration.getNotifications({ tag });
|
const notifications = await registration.getNotifications({ tag });
|
||||||
notifications.forEach(n => n.close());
|
notifications.forEach((n) => n.close());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`[Notifier] Error cancelling notification`, e);
|
console.log(`[Notifier] Error cancelling notification`, e);
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ class Notifier {
|
|||||||
if (hasWebPushTopics) {
|
if (hasWebPushTopics) {
|
||||||
return pushManager.subscribe({
|
return pushManager.subscribe({
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: urlB64ToUint8Array(config.web_push_public_key)
|
applicationServerKey: urlB64ToUint8Array(config.web_push_public_key),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,11 @@ export const useConnectionListeners = (account, subscriptions, users, webPushTop
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleNotification = async (subscriptionId, notification) => {
|
const handleNotification = async (subscriptionId, notification) => {
|
||||||
// Note: This logic is duplicated in the Android app in SubscriberService::onNotificationReceived()
|
// This logic is (partially) duplicated in
|
||||||
// and FirebaseService::handleMessage().
|
// - Android: SubscriberService::onNotificationReceived()
|
||||||
|
// - Android: FirebaseService::onMessageReceived()
|
||||||
|
// - Web app: hooks.js:handleNotification()
|
||||||
|
// - Web app: sw.js:handleMessage(), sw.js:handleMessageClear(), ...
|
||||||
|
|
||||||
if (notification.event === EVENT_MESSAGE_DELETE && notification.sequence_id) {
|
if (notification.event === EVENT_MESSAGE_DELETE && notification.sequence_id) {
|
||||||
await subscriptionManager.deleteNotificationBySequenceId(subscriptionId, notification.sequence_id);
|
await subscriptionManager.deleteNotificationBySequenceId(subscriptionId, notification.sequence_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user