Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/send.js
Show First 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | async function preparePushNotif(input: { | ||||
const threadInfo = threadInfos[threadID]; | const threadInfo = threadInfos[threadID]; | ||||
const parentThreadInfo = threadInfo.parentThreadID | const parentThreadInfo = threadInfo.parentThreadID | ||||
? threadInfos[threadInfo.parentThreadID] | ? threadInfos[threadInfo.parentThreadID] | ||||
: null; | : null; | ||||
const updateBadge = threadInfo.currentUser.subscription.home; | const updateBadge = threadInfo.currentUser.subscription.home; | ||||
const displayBanner = threadInfo.currentUser.subscription.pushNotifs; | const displayBanner = threadInfo.currentUser.subscription.pushNotifs; | ||||
const username = userInfos[userID] && userInfos[userID].username; | const username = userInfos[userID] && userInfos[userID].username; | ||||
let resolvedUsername; | |||||
if (getENSNames) { | |||||
const userInfosWithENSNames = await getENSNames([userInfos[userID]]); | |||||
resolvedUsername = userInfosWithENSNames[0].username; | |||||
} | |||||
const userWasMentioned = | const userWasMentioned = | ||||
username && | username && | ||||
threadInfo.currentUser.role && | threadInfo.currentUser.role && | ||||
oldValidUsernameRegex.test(username) && | oldValidUsernameRegex.test(username) && | ||||
newMessageInfos.some(newMessageInfo => { | newMessageInfos.some(newMessageInfo => { | ||||
const unwrappedMessageInfo = | const unwrappedMessageInfo = | ||||
newMessageInfo.type === messageTypes.SIDEBAR_SOURCE | newMessageInfo.type === messageTypes.SIDEBAR_SOURCE | ||||
? newMessageInfo.sourceMessage | ? newMessageInfo.sourceMessage | ||||
: newMessageInfo; | : newMessageInfo; | ||||
return ( | return ( | ||||
unwrappedMessageInfo.type === messageTypes.TEXT && | unwrappedMessageInfo.type === messageTypes.TEXT && | ||||
isUserMentioned(username, unwrappedMessageInfo.text) | (isUserMentioned(username, unwrappedMessageInfo.text) || | ||||
(resolvedUsername && | |||||
isUserMentioned(resolvedUsername, unwrappedMessageInfo.text))) | |||||
); | ); | ||||
}); | }); | ||||
if (!updateBadge && !displayBanner && !userWasMentioned) { | if (!updateBadge && !displayBanner && !userWasMentioned) { | ||||
return null; | return null; | ||||
} | } | ||||
const badgeOnly = !displayBanner && !userWasMentioned; | const badgeOnly = !displayBanner && !userWasMentioned; | ||||
const notifTargetUserInfo = { id: userID, username }; | const notifTargetUserInfo = { id: userID, username }; | ||||
▲ Show 20 Lines • Show All 1,554 Lines • Show Last 20 Lines |