Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export async function processEmailNotifications(
const timeoutMillis = 14400000
const timeout = time + timeoutMillis

/* eslint-disable no-constant-condition */
while (true) {
const now = Date.now()
if (now > timeout) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://apps.apple.com/us/app/audius-music/id1491270519" target="_blank"><img src="https://download.audius.co/emails/buyer-purchase/20KN9wbGZmcEz9pzRwW3motfhSWXkr.png" width="142" border="0" style="min-width:142px; width:142px;
height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://play.google.com/store/apps/details?id=co.audius.app&hl=en_US&gl=US" target="_blank"><img src="https://download.audius.co/emails/buyer-purchase/Cw2foDCCSHAnIULYxGJqHPtxituaW5.png" width="166" border="0" style="min-width:166px; width:166px;
height: auto; display: block;"></a></td>
</tr>
Expand Down Expand Up @@ -706,9 +706,9 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://www.audius.co" target="_blank"><img src="https://download.audius.co/emails/buyer-purchase/hMFNHWWoe8UKpFf3aubdR09hRUoxL0.png" width="168" border="0" style="min-width:168px; width:168px;
border-radius:2px; height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" style="width:168px;"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td class="stack-column-center" style="width:168px;"></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -832,7 +832,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -868,7 +868,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" width="48.86%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -462,9 +462,9 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://www.audius.co"><img src="https://download.audius.co/static-resources/email/grayLogoHorizontal.png" width="168" border="0" style="width: 100%;
border-radius:2px; height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" style="width:168px;"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td class="stack-column-center" style="width:168px;"></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" width="31.82%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -588,7 +588,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -624,7 +624,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://apps.apple.com/us/app/audius-music/id1491270519" target="_blank"><img src="https://download.audius.co/emails/seller-purchase/ZyaXDdkvSOGZdvxy5wnGI0zmuPcVZE.png" width="142" border="0" style="min-width:142px; width:142px;
height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://play.google.com/store/apps/details?id=co.audius.app&hl=en_US&gl=US" target="_blank"><img src="https://download.audius.co/emails/seller-purchase/8T06wW79Jme6gKnznUEfSef6IeuZV8.png" width="166" border="0" style="min-width:166px; width:166px;
height: auto; display: block;"></a></td>
</tr>
Expand Down Expand Up @@ -676,9 +676,9 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a href="https://www.audius.co" target="_blank"><img src="https://download.audius.co/emails/seller-purchase/o4yFhS0z6ny9G5NfleAhDjtWGqj7cT.png" width="168" border="0" style="min-width:168px; width:168px;
border-radius:2px; height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" style="width:168px;"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td class="stack-column-center" style="width:168px;"></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -802,7 +802,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -838,7 +838,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://apps.apple.com/us/app/audius-music/id1491270519"><img src="https://download.audius.co/emails/transfer/XSShP2c68DczmwiHpr5mUv4t7Od1dL.png" width="142" border="0" style="min-width:142px; width:142px;
height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://play.google.com/store/apps/details?id=co.audius.app&hl=en_US&gl=US"><img src="https://download.audius.co/emails/transfer/RIExgLjh8wZIVtsUv8Chbcskqwizaw.png" width="166" border="0" style="min-width:166px; width:166px;
height: auto; display: block;"></a></td>
</tr>
Expand Down Expand Up @@ -461,9 +461,9 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://www.audius.co"><img src="https://download.audius.co/emails/transfer/HQsDwSXBDcUHH0nmUGTFHNFbYr01wI.png" width="168" border="0" style="min-width:168px; width:168px;
border-radius:2px; height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" style="width:168px;"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td class="stack-column-center" style="width:168px;"></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -587,7 +587,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -623,7 +623,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://apps.apple.com/us/app/audius-music/id1491270519"><img src="https://download.audius.co/emails/withdrawal/oxyCkIsHBvNleiZLGnyXvV7j9yM9KE.png" width="142" border="0" style="min-width:142px; width:142px;
height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://play.google.com/store/apps/details?id=co.audius.app&hl=en_US&gl=US"><img src="https://download.audius.co/emails/withdrawal/q1evAW5GIFOanhNG9Tf8GGyFeQE4AX.png" width="166" border="0" style="min-width:166px; width:166px;
height: auto; display: block;"></a></td>
</tr>
Expand Down Expand Up @@ -448,9 +448,9 @@ export const email = ({
<tr>
<td style="vertical-align: middle;" class="stack-column-center" align="center"><a target="_blank" href="https://www.audius.co"><img src="https://download.audius.co/emails/withdrawal/NQYOVr4BMjSzOkhCNPtzsCUxMFeq1w.png" width="168" border="0" style="min-width:168px; width:168px;
border-radius:2px; height: auto; display: block;"></a></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" style="width:168px;"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"> </td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td class="stack-column-center" style="width:168px;"></td>
<td class="stack-column-center" height="12" style="width:12px; min-width:12px; height:12px; min-height:12px;" width="12"></td>
<td style="vertical-align: middle;" align="center" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -574,7 +574,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down Expand Up @@ -610,7 +610,7 @@ export const email = ({
</tr>
</table>
</td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"> </td>
<td class="stack-column-center" height="8" style="width:8px; min-width:8px; height:8px; min-height:8px;" width="8"></td>
<td style="vertical-align: middle;" align="center" width="32.32%" class="stack-column-center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const notificationTypeMapping = {
tip_receive: MappingVariable.PushTipRceive,
tip_send: MappingVariable.PushTipSend,
challenge_reward: MappingVariable.PushChallengeReward,
claimable_reward: MappingVariable.PushClaimableReward,
track_added_to_playlist: MappingVariable.PushTrackAddedToPlaylist,
create: MappingVariable.PushCreate,
trending: MappingVariable.PushTrending,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import { ClaimableRewardNotification } from '../../types/notifications'
import { BaseNotification } from './base'
import { logger } from '../../logger'
import { sendTransactionalEmail } from '../../email/notifications/sendEmail'
import { buildUserNotificationSettings } from './userNotificationSettings'
import {
buildUserNotificationSettings,
Device
} from './userNotificationSettings'
import { email } from '../../email/notifications/preRendered/claimableReward'
import { formatImageUrl, formatProfileUrl } from '../../utils/format'
import { sendBrowserNotification } from '../../web'
import { disableDeviceArns } from '../../utils/disableArnEndpoint'
import { sendPushNotification } from '../../sns'

type ClaimableRewardRow = Omit<NotificationRow, 'data'> & {
data: ClaimableRewardNotification
}

const messages = {
readyToClaim: 'You have $AUDIO rewards ready to claim! '
}
export class ClaimableReward extends BaseNotification<ClaimableRewardRow> {
userId: number
amount: string
Expand All @@ -29,18 +38,63 @@ export class ClaimableReward extends BaseNotification<ClaimableRewardRow> {
}
}

async processNotification() {
async processNotification({ isBrowserPushEnabled }) {
const users = await this.getUsersBasicInfo([this.userId])
const user = users[this.userId]
if (!user) {
logger.error(`Could not find user for notification ${this.userId}`)
return
}

// Get the user's notification setting from identity service
const userNotificationSettings = await buildUserNotificationSettings(
this.identityDB,
[user.user_id]
)
const title = 'Claim Your Rewards!'

await sendBrowserNotification(
isBrowserPushEnabled,
userNotificationSettings,
this.userId,
title,
messages.readyToClaim
)

if (
userNotificationSettings.shouldSendPushNotification({
receiverUserId: this.userId
})
) {
const devices: Device[] = userNotificationSettings.getDevices(this.userId)
const pushes = await Promise.all(
devices.map((device) => {
return sendPushNotification(
{
type: device.type,
badgeCount:
userNotificationSettings.getBadgeCount(this.userId) + 1,
targetARN: device.awsARN
},
{
title,
body: messages.readyToClaim,
data: {
id: `timestamp:${this.getNotificationTimestamp()}:group_id:${
this.notification.group_id
}`,
type: 'ClaimableReward',
entityId: this.userId
}
}
)
})
)

await disableDeviceArns(this.identityDB, pushes)
await this.incrementBadgeCount(this.userId)
}

await sendTransactionalEmail({
email: userNotificationSettings.getUserEmail(user.user_id),
html: email({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum MappingVariable {
PushTipSend = 'push_tip_send',
PushTastemaker = 'push_tastemaker',
PushChallengeReward = 'push_challenge_reward',
PushClaimableReward = 'push_claimable_reward',
PushTrackAddedToPlaylist = 'push_track_added_to_playlist',
PushCreate = 'push_create',
PushTrending = 'push_trending',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export interface RpcLogRow {
from_wallet: string
relayed_at: Date
relayed_by: string
rpc: Object
rpc: object
sig: string
}
export interface SaveRow {
Expand Down