clean up pushes
This commit is contained in:
+9
-5
@@ -67,7 +67,7 @@ fbMessaging.onBackgroundMessage((payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notify webapp that a message was received.
|
// Notify webapp that a message was received.
|
||||||
if (webAppChannel || payload.data.what == 'read') {
|
if (webAppChannel) {
|
||||||
webAppChannel.postMessage(payload.data);
|
webAppChannel.postMessage(payload.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +97,14 @@ self.addEventListener('install', event => {
|
|||||||
// This code handles a click on notification: takes
|
// This code handles a click on notification: takes
|
||||||
// the user to the browser tab with the chat or opens a new tab.
|
// the user to the browser tab with the chat or opens a new tab.
|
||||||
self.addEventListener('notificationclick', event => {
|
self.addEventListener('notificationclick', event => {
|
||||||
const notification = event.notification;
|
const data = event.notification.data;
|
||||||
notification.close();
|
event.notification.close();
|
||||||
|
if (!data) {
|
||||||
|
console.info("Missing 'data' in notification", event.notification);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const urlHash = '#/' + notification.data.topic;
|
const urlHash = '#/' + data.topic;
|
||||||
|
|
||||||
event.waitUntil(self.clients.matchAll({
|
event.waitUntil(self.clients.matchAll({
|
||||||
type: 'window',
|
type: 'window',
|
||||||
@@ -109,7 +113,7 @@ self.addEventListener('notificationclick', event => {
|
|||||||
let anyClient = null;
|
let anyClient = null;
|
||||||
for (let i = 0; i < windowClients.length; i++) {
|
for (let i = 0; i < windowClients.length; i++) {
|
||||||
const url = new URL(windowClients[i].url);
|
const url = new URL(windowClients[i].url);
|
||||||
if (url.hash.includes(notification.data.topic)) {
|
if (url.hash.includes(data.topic)) {
|
||||||
// Found the Tinode tab with the right topic open.
|
// Found the Tinode tab with the right topic open.
|
||||||
return windowClients[i].focus();
|
return windowClients[i].focus();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -316,7 +316,8 @@ class TinodeWeb extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tinode received a push notification from the server.
|
// Tinode received a push notification from the server.
|
||||||
handlePushMessage(data) {
|
handlePushMessage(payload) {
|
||||||
|
const data = payload.data || {};
|
||||||
switch (data.what) {
|
switch (data.what) {
|
||||||
case 'msg':
|
case 'msg':
|
||||||
if (Tinode.isChannelTopicName(data.topic)) {
|
if (Tinode.isChannelTopicName(data.topic)) {
|
||||||
@@ -367,7 +368,7 @@ class TinodeWeb extends React.Component {
|
|||||||
// Handhe FCM pushes
|
// Handhe FCM pushes
|
||||||
// (a) for channels always,
|
// (a) for channels always,
|
||||||
// (b) pushes when the app is in foreground but has no focus.
|
// (b) pushes when the app is in foreground but has no focus.
|
||||||
firebaseOnMessage(this.fcm, (payload) => { this.handlePushMessage(payload.data); });
|
firebaseOnMessage(this.fcm, (payload) => { this.handlePushMessage(payload); });
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
// SW registration or FCM has failed :(
|
// SW registration or FCM has failed :(
|
||||||
onError(err);
|
onError(err);
|
||||||
|
|||||||
+4
-2
@@ -7642,7 +7642,9 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
|||||||
return tinode;
|
return tinode;
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePushMessage(data) {
|
handlePushMessage(payload) {
|
||||||
|
const data = payload.data || {};
|
||||||
|
|
||||||
switch (data.what) {
|
switch (data.what) {
|
||||||
case 'msg':
|
case 'msg':
|
||||||
if (tinode_sdk__WEBPACK_IMPORTED_MODULE_4___default().isChannelTopicName(data.topic)) {
|
if (tinode_sdk__WEBPACK_IMPORTED_MODULE_4___default().isChannelTopicName(data.topic)) {
|
||||||
@@ -7712,7 +7714,7 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
|||||||
}
|
}
|
||||||
|
|
||||||
(0,firebase_messaging__WEBPACK_IMPORTED_MODULE_3__.onMessage)(this.fcm, payload => {
|
(0,firebase_messaging__WEBPACK_IMPORTED_MODULE_3__.onMessage)(this.fcm, payload => {
|
||||||
this.handlePushMessage(payload.data);
|
this.handlePushMessage(payload);
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
onError(err);
|
onError(err);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user