Fix missing merge of FOLLOW push notifications (#596)

* Use consistent lowercase titles

* Fix missing merge of FOLLOW push notifications

---------

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-11-05 22:06:38 +01:00 committed by GitHub
parent e24e2a6b20
commit 7040dbfce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -14,11 +14,14 @@ export const notifyUserSubscribers = async ({ models, item }) => {
followee: true followee: true
} }
}) })
const subType = isPost ? 'POST' : 'COMMENT'
const tag = `FOLLOW-${item.userId}-${subType}`
await Promise.allSettled(userSubs.map(({ followerId, followee }) => sendUserNotification(followerId, { await Promise.allSettled(userSubs.map(({ followerId, followee }) => sendUserNotification(followerId, {
title: `@${followee.name} ${isPost ? 'created a post' : 'replied to a post'}`, title: `@${followee.name} ${isPost ? 'created a post' : 'replied to a post'}`,
body: isPost ? item.title : item.text, body: isPost ? item.title : item.text,
item, item,
tag: 'FOLLOW' data: { followeeName: followee.name, subType },
tag
}))) })))
} catch (err) { } catch (err) {
console.error(err) console.error(err)

View File

@ -64,11 +64,11 @@ const mergeAndShowNotification = (sw, payload, currentNotification) => {
const amount = currentNotification.data?.amount ? currentNotification.data.amount + 1 : 2 const amount = currentNotification.data?.amount ? currentNotification.data.amount + 1 : 2
let title = '' let title = ''
const newData = {} let newData = {}
if (tag === 'REPLY') { if (tag === 'REPLY') {
title = `You have ${amount} new replies` title = `you have ${amount} new replies`
} else if (tag === 'MENTION') { } else if (tag === 'MENTION') {
title = `You were mentioned ${amount} times` title = `you were mentioned ${amount} times`
} else if (tag === 'REFERRAL') { } else if (tag === 'REFERRAL') {
title = `${amount} stackers joined via your referral links` title = `${amount} stackers joined via your referral links`
} else if (tag === 'INVITE') { } else if (tag === 'INVITE') {
@ -79,6 +79,10 @@ const mergeAndShowNotification = (sw, payload, currentNotification) => {
const newSats = currentSats + incomingSats const newSats = currentSats + incomingSats
title = `${numWithUnits(newSats, { abbreviate: false })} were deposited in your account` title = `${numWithUnits(newSats, { abbreviate: false })} were deposited in your account`
newData.sats = newSats 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 // close current notification before showing new one to "merge" notifications