Skip to content

Commit 25099f3

Browse files
committed
Enhanced push notifications
1 parent b235399 commit 25099f3

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

public/firebase-messaging-sw.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ firebase.initializeApp(firebaseConfig);
5353
const messaging = firebase.messaging();
5454

5555
self.addEventListener('notificationclick', function (event) {
56+
console.log('clicking worked');
5657
const clickedNotification = event.notification;
5758

5859
const promiseChain = clients.matchAll({
@@ -64,19 +65,17 @@ self.addEventListener('notificationclick', function (event) {
6465

6566
for (let i = 0; i < windowClients.length; i++) {
6667
const windowClient = windowClients[i];
67-
if (windowClient.url === self.location.origin) {
68+
if (windowClient.url === `${self.location.origin}/`) {
6869
matchingClient = windowClient;
6970
break;
7071
}
7172
}
7273

7374
if (matchingClient) {
74-
matchingClient.focus();
75-
7675
matchingClient.postMessage({
7776
url: clickedNotification.data.url,
7877
});
79-
return;
78+
return matchingClient.focus();
8079
} else {
8180
return clients.openWindow(self.location.origin);
8281
}

src/Components/Home/Room/Single.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ const Single = ({
7373
if (snapShot === undefined) return '';
7474
const hash = hashTable.includes(snapShot.slug);
7575
if (snapShot.generated === false && snapShot.from === user.uid && !hash) {
76-
console.log(snapShot.bobPublicKey);
7776
const e2e = new E2E();
7877
e2e
7978
.setPrivateKey(

src/Store/Actions/Firestore.js

-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ export const addSlug = () => (dispatch, getState) => {
4949
const e2e = new E2E();
5050
const { Publickey, PrivateKey } = e2e.generateKeys();
5151

52-
console.log(PrivateKey, Publickey, slug);
5352

5453
await ddb.slug.add({ id: slug, PrivateKey });
55-
console.log({ id: slug, PrivateKey });
5654

5755
root
5856
.doc(e.id)
@@ -121,7 +119,6 @@ export const addChannel = (slug) => async (dispatch, getState) => {
121119
.get();
122120
const e2e = new E2E();
123121
const bobPublicKey = e2e.generateSharedSecret(secretKey.data().Publickey);
124-
console.log('BobPublic', bobPublicKey);
125122
obj.bobPublicKey = bobPublicKey;
126123

127124
const channelId = await db.collection('channel').add(obj);

src/Store/Actions/Message.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ export const sendmessage = (message, details) => async (dispatch, getState) => {
2323
) {
2424
lastMessageObj = {
2525
showDateInfo: true,
26-
rendered: true,
2726
};
2827
}
2928

3029
// Case 2: If there is no messages
3130
if (hasInMap && typeof getInMap.message === 'undefined') {
3231
lastMessageObj = {
3332
showDateInfo: true,
34-
rendered: true,
35-
3633
};
3734
}
3835

@@ -165,7 +162,7 @@ export const RecieveMessage = () => (dispatch) => {
165162
channel: message.channel,
166163
to: message.to,
167164
...parsed,
168-
showDateInfo: message.showDateInfo || null,
165+
showDateInfo: message.showDateInfo,
169166
};
170167
await db.message.add(final);
171168
const locatioHref = window.location.href;
@@ -180,19 +177,23 @@ export const RecieveMessage = () => (dispatch) => {
180177
messageTone.play();
181178
if (notificationPermission === 'granted') {
182179
try {
183-
const notificationTitle = `${message.displayName}`;
184-
const notificationOptions = {
185-
body: parsed.message,
186-
icon: message.photoURL,
187-
vibrate: [100, 50, 100],
188-
data: { url: `https://relp.now.sh/r/${message.channel}` },
189-
actions: [{ action: 'open_url', title: 'Read Message' }],
190-
click_action: `https://relp.now.sh/r/${message.channel}`,
191-
};
192-
navigator.serviceWorker.getRegistrations()
193-
.then((req) => {
194-
req.showNotification(notificationTitle, notificationOptions);
195-
});
180+
navigator.serviceWorker.ready.then((registration) => {
181+
const notificationTitle = `${message.displayName}`;
182+
const notificationOptions = {
183+
body: parsed.message,
184+
icon: message.photoURL,
185+
vibrate: [500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500],
186+
actions: [{ action: 'open_url', title: 'Read Message' }],
187+
click_action: `https://relp.now.sh/r/${message.channel}`,
188+
tag: parsed.channel,
189+
renotify: true,
190+
requireInteraction: true,
191+
};
192+
registration.getRegistrations()
193+
.then((req) => {
194+
req.showNotification(notificationTitle, notificationOptions);
195+
});
196+
});
196197
} catch (err) {
197198
console.log(err);
198199
}

0 commit comments

Comments
 (0)