Skip to content

Commit

Permalink
Fix twice notification
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Oct 14, 2024
1 parent 3c82533 commit 4c25069
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 30 deletions.
7 changes: 0 additions & 7 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public static function onServiceWorkerControllerInit($event): void
apiKey: "{$module->getConfigureForm()->firebaseApiKey}",
appId: "{$module->getConfigureForm()->firebaseAppId}"
});
firebase.messaging().onBackgroundMessage(function(payload) {
return self.registration.showNotification(payload.notification.title, {
body: payload.notification.body,
image: payload.notification.image
});
});
JS;
}

Expand Down
23 changes: 0 additions & 23 deletions resources/js/humhub.firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,10 @@ humhub.module('firebase', function (module, require, $) {
appId: module.config.appId,
});
this.messaging = firebase.messaging();

this.messaging.onMessage(function (payload) {
module.log.info("Received FCM Push Notification", payload);
});

// Callback fired if Instance ID token is updated.
// TODO: It is commented because of the error: "Could not initialize module:
// humhub.modules.firebase FirebaseError: Messaging: This method is available
// in a service worker context. (messaging/only-available-in-sw)."
// this.messaging.onBackgroundMessage(function () {
// this.messaging.getToken().then(function (refreshedToken) {
// this.deleteTokenLocalStore();
// this.sendTokenToServer(refreshedToken);
// }).catch(function (err) {
// console.log('Unable to retrieve refreshed token ', err);
// });
// });
}
};

const afterServiceWorkerRegistration = function (registration) {
//console.log("After Service Worker Registration");
//console.log(registration);

const that = this;

this.messaging.swRegistration = registration;
Expand All @@ -48,7 +28,6 @@ humhub.module('firebase', function (module, require, $) {
serviceWorkerRegistration: registration,
}).then(function (currentToken) {
if (currentToken) {
//console.log('Token: ' + currentToken);
that.sendTokenToServer(currentToken);
} else {
module.log.info('No Instance ID token available. Request permission to generate one.');
Expand Down Expand Up @@ -78,8 +57,6 @@ humhub.module('firebase', function (module, require, $) {
that.setTokenLocalStore(token);
}
});
} else {
//console.log('Token already sent to server so won\'t send it again unless it changes');
}
};

Expand Down

0 comments on commit 4c25069

Please sign in to comment.