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