From 7040dbfce68c09540bf9870a72d2c4eafdef8831 Mon Sep 17 00:00:00 2001 From: ekzyis <27162016+ekzyis@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:06:38 +0100 Subject: [PATCH] Fix missing merge of FOLLOW push notifications (#596) * Use consistent lowercase titles * Fix missing merge of FOLLOW push notifications --------- Co-authored-by: ekzyis --- lib/push-notifications.js | 5 ++++- sw/eventListener.js | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/push-notifications.js b/lib/push-notifications.js index ffa78341..2f2b3af3 100644 --- a/lib/push-notifications.js +++ b/lib/push-notifications.js @@ -14,11 +14,14 @@ export const notifyUserSubscribers = async ({ models, item }) => { followee: true } }) + const subType = isPost ? 'POST' : 'COMMENT' + const tag = `FOLLOW-${item.userId}-${subType}` await Promise.allSettled(userSubs.map(({ followerId, followee }) => sendUserNotification(followerId, { title: `@${followee.name} ${isPost ? 'created a post' : 'replied to a post'}`, body: isPost ? item.title : item.text, item, - tag: 'FOLLOW' + data: { followeeName: followee.name, subType }, + tag }))) } catch (err) { console.error(err) diff --git a/sw/eventListener.js b/sw/eventListener.js index 58586f27..a090f58e 100644 --- a/sw/eventListener.js +++ b/sw/eventListener.js @@ -64,11 +64,11 @@ const mergeAndShowNotification = (sw, payload, currentNotification) => { const amount = currentNotification.data?.amount ? currentNotification.data.amount + 1 : 2 let title = '' - const newData = {} + let newData = {} if (tag === 'REPLY') { - title = `You have ${amount} new replies` + title = `you have ${amount} new replies` } else if (tag === 'MENTION') { - title = `You were mentioned ${amount} times` + title = `you were mentioned ${amount} times` } else if (tag === 'REFERRAL') { title = `${amount} stackers joined via your referral links` } else if (tag === 'INVITE') { @@ -79,6 +79,10 @@ const mergeAndShowNotification = (sw, payload, currentNotification) => { const newSats = currentSats + incomingSats title = `${numWithUnits(newSats, { abbreviate: false })} were deposited in your account` newData.sats = newSats + } else if (tag.split('-')[0] === 'FOLLOW') { + const { followeeName, subType } = incomingData + title = `@${followeeName} ${subType === 'POST' ? `created ${amount} posts` : `replied ${amount} times`}` + newData = incomingData } // close current notification before showing new one to "merge" notifications