prepare for foreground notifications

This commit is contained in:
or-else
2021-05-09 14:07:41 -07:00
parent eeb14cf752
commit 2c61ab26c8
5 changed files with 17 additions and 11 deletions
+9 -5
View File
@@ -301,10 +301,10 @@ class TinodeWeb extends React.Component {
} }
// Notifiy Tinode that a push message was received from the server. // Notifiy Tinode that a push message was received from the server.
handlePushMessage(payload) { handlePushMessage(data) {
if (payload.data.what == 'msg' && Tinode.isChannelTopicName(payload.data.topic)) { if (data.what == 'msg' && Tinode.isChannelTopicName(data.topic)) {
// The last argument is a fake user Id: otherwise the update is seen as one from the current user. // The last argument is a fake user Id: otherwise the update is seen as one from the current user.
this.tinode.oobNotification(payload.data.topic, payload.data.seq, 'fake-uid'); this.tinode.oobNotification(data.topic, data.seq, 'fake-uid');
} }
} }
@@ -330,8 +330,10 @@ class TinodeWeb extends React.Component {
this.requestPushToken(); this.requestPushToken();
}); });
// FCM pushes for channels have to be handled even when the app is in the foreground. // Handhe FCM pushes
this.fbPush.onMessage(this.handlePushMessage); // (a) for channels always,
// (b) pushes when the app is in foreground but has not focus.
this.fbPush.onMessage(payload => { this.handlePushMessage(payload.data); });
return reg; return reg;
}).catch((err) => { }).catch((err) => {
@@ -421,6 +423,8 @@ class TinodeWeb extends React.Component {
} }
handleOnline(online) { handleOnline(online) {
console.log("handleOnline", online);
if (online) { if (online) {
this.handleError(); this.handleError();
clearInterval(this.reconnectCountdown); clearInterval(this.reconnectCountdown);
+5 -3
View File
@@ -5056,9 +5056,9 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
return tinode; return tinode;
} }
handlePushMessage(payload) { handlePushMessage(data) {
if (payload.data.what == 'msg' && tinode_sdk__WEBPACK_IMPORTED_MODULE_5___default().isChannelTopicName(payload.data.topic)) { if (data.what == 'msg' && tinode_sdk__WEBPACK_IMPORTED_MODULE_5___default().isChannelTopicName(data.topic)) {
this.tinode.oobNotification(payload.data.topic, payload.data.seq, 'fake-uid'); this.tinode.oobNotification(data.topic, data.seq, 'fake-uid');
} }
} }
@@ -5193,6 +5193,8 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
} }
handleOnline(online) { handleOnline(online) {
console.log("handleOnline", online);
if (online) { if (online) {
this.handleError(); this.handleError();
clearInterval(this.reconnectCountdown); clearInterval(this.reconnectCountdown);
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long