Skip to content

Commit

Permalink
merge upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanakram3 committed Jan 9, 2024
1 parent c12764b commit 65a46d4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
20 changes: 14 additions & 6 deletions src/mail-scheduler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ export async function deliverEmails() {
for (const notificationDelivery of newEmailDeliveries) {
const toAccount = notificationDelivery.notification.account
let content
let subject
if (process.env.TESTING !== 'true' && process.env.TESTING !== '1') {
content = await createMailContent(em, appName, notificationDelivery.notification)
const { subject: notificationSuject, content: notificationContent } = await createMailContent(
em,
appName,
notificationDelivery.notification
)
content = notificationContent
subject = notificationSuject
}
const attempts = notificationDelivery.attempts
const status = content
? await executeMailDelivery(appName, em, toAccount, content)
: new EmailFailure({
errorStatus: 'Failure in Creating mail content',
})
const status =
content && subject
? await executeMailDelivery(appName, em, toAccount, subject, content)
: new EmailFailure({
errorStatus: 'Failure in Creating mail content',
})

const newAttempt = new EmailDeliveryAttempt({
id: uniqueId(),
Expand Down
45 changes: 24 additions & 21 deletions src/mail-scheduler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export async function executeMailDelivery(
appName: string,
em: EntityManager,
toAccount: Account,
subject: string,
content: string
): Promise<DeliveryStatus> {
const resp = await sendGridSend({
from: await config.get(ConfigVariable.SendgridFromEmail, em),
to: toAccount.email,
subject: `New notification from ${appName}`,
subject: subject || `New notification from ${appName}`,
content,
})
const className = Object.prototype.toString.call(resp)
Expand All @@ -41,7 +42,10 @@ export async function createMailContent(
em: EntityManager,
appName: string,
notification: Notification
): Promise<string | undefined> {
): Promise<{
content: string
subject: string
}> {
const appRoot = `https://${await config.get(ConfigVariable.AppRootDomain, em)}`

const appKey = notification.recipient.isTypeOf === 'MemberRecipient' ? 'viewer' : 'studio'
Expand All @@ -59,25 +63,24 @@ export async function createMailContent(
const logosAssetsRoot = `${appAssetStorage}/logos/${appName.toLowerCase()}`
const appNameAlt = await config.get(ConfigVariable.AppNameAlt, em)

try {
const content = notificationEmailContent({
...(await getMessage(em, notification)),
app: {
name,
nameAlt: appNameAlt,
logo: `${logosAssetsRoot}/header-${appKey}.png`,
logoAlt: `${logosAssetsRoot}/footer.png`,
homeLink: appRoot,
notificationLink,
unsubscribeLink,
},
notification: await getNotificationData(em, notification),
})
return content
} catch (error) {
console.log(error)
console.log('no content produced')
return undefined
const notificationData = await getNotificationData(em, notification)

const content = notificationEmailContent({
...(await getMessage(em, notification)),
app: {
name,
nameAlt: appNameAlt,
logo: `${logosAssetsRoot}/header-${appKey}.png`,
logoAlt: `${logosAssetsRoot}/footer.png`,
homeLink: appRoot,
notificationLink,
unsubscribeLink,
},
notification: notificationData,
})
return {
content,
subject: notificationData.subject,
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/utils/notification/notificationsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type NotificationData = {
link: string
avatar: string
text: string
subject: string
}

export const getNotificationData = async (
Expand All @@ -32,6 +33,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'channel-page', [channelId]),
avatar: await getNotificationAvatar(em, 'channelId', channelId),
text: `New channel created: “${channelTitle}“`,
subject: 'New channel',
}
}

Expand All @@ -43,6 +45,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'video-page', [videoId, commentId]),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} replied to your comment under the video: “${videoTitle}”`,
subject: `New comment`,
}
}
case 'ReactionToComment': {
Expand All @@ -52,6 +55,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'video-page', [videoId, commentId]),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} reacted to your comment on the video: “${videoTitle}”`,
subject: `New reaction`,
}
}

Expand All @@ -63,6 +67,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'video-page', [videoId]),
avatar: await getNotificationAvatar(em, 'channelId', channelId),
text: `${channelTitle} posted a new video: “${videoTitle}”`,
subject: `New video`,
}
}
case 'NewNftOnSale': {
Expand All @@ -72,6 +77,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'channelId', channelId),
text: `${channelTitle} started the sale of NFT: “${videoTitle}”`,
subject: `New NFT sale`,
}
}
case 'NewAuction': {
Expand All @@ -81,6 +87,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'channelId', channelId),
text: `${channelTitle} started an auction for NFT: “${videoTitle}”`,
subject: 'New NFT auction',
}
}

Expand All @@ -92,6 +99,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', newBidderId),
text: `${newBidderHandle} placed a higher bid in the timed auction for NFT: “${videoTitle}”`,
subject: 'You got outbid',
}
}
case 'AuctionWon': {
Expand All @@ -102,6 +110,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', recipientId),
text: `You won ${auctionText} auction for NFT: “${videoTitle}”`,
subject: 'Action won',
}
}
case 'AuctionLost': {
Expand All @@ -112,6 +121,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', recipientId),
text: `You lost ${auctionText} auction for NFT: “${videoTitle}”. Withdraw your bid`,
subject: 'Auction lost',
}
}

Expand All @@ -127,6 +137,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'term-of-sevice-page'),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `Your channel “${channelTitle}” is excluded from App`,
subject: 'Channel excluded',
}
}
case 'VideoExcluded': {
Expand All @@ -136,6 +147,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'term-of-sevice-page'),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `Your video is excluded from App: “${videoTitle}”`,
subject: 'Video excluded',
}
}
case 'NftFeaturedOnMarketPlace': {
Expand All @@ -145,6 +157,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'marketplace-page'),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `Your NFT was featured in the marketplace featured section: “${videoTitle}”`,
subject: 'NFT featured',
}
}

Expand All @@ -156,6 +169,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'member-page', [followerId]),
avatar: await getNotificationAvatar(em, 'membershipId', followerId),
text: `${followerHandle} followed your channel`,
subject: 'New follower',
}
}
case 'CommentPostedToVideo': {
Expand All @@ -165,6 +179,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} left a comment on your video: “${videoTitle}”`,
subject: 'New comment',
}
}
case 'VideoLiked': {
Expand All @@ -174,6 +189,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'video-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} liked your video: “${videoTitle}”`,
subject: 'New video like',
}
}
case 'VideoDisliked': {
Expand All @@ -183,6 +199,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'video-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} disliked your video: “${videoTitle}”`,
subject: 'New video dislike',
}
}

Expand All @@ -193,6 +210,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'ypp-dashboard'),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `Your channel got verified in our Youtube Partnership Program`,
subject: 'Channel verified',
}
}
case 'ChannelSuspended': {
Expand All @@ -201,6 +219,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'ypp-dashboard'),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `Your channel got suspended in our Youtube Partnership Program`,
subject: 'Channel suspended',
}
}

Expand All @@ -212,6 +231,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', buyerId),
text: `${buyerHandle} purchased for ${formatJOY(price)} your NFT: “${videoTitle}”`,
subject: 'New NFT purchase',
}
}
case 'NftRoyaltyPaid': {
Expand All @@ -221,6 +241,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'channelId', recipientId),
text: `You received ${formatJOY(amount)} royalties from your NFT: “${videoTitle}”`,
subject: 'New NFT royalty',
}
}
case 'CreatorReceivesAuctionBid': {
Expand All @@ -230,6 +251,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipId', bidderId),
text: `${bidderHandle} placed a bid of ${formatJOY(amount)} for your NFT: “${videoTitle}”`,
subject: 'New NFT bid',
}
}

Expand All @@ -241,6 +263,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'member-page', [payerId]),
avatar: await getNotificationAvatar(em, 'membershipId', payerId),
text: `${payerHandle} transferred ${formatJOY(amount)} to your channel`,
subject: 'New payment',
}
}
case 'ChannelFundsWithdrawn': {
Expand All @@ -250,6 +273,7 @@ export const getNotificationData = async (
link: await getNotificationLink(em, 'payments-page'),
avatar: await getNotificationAvatar(em, 'membershipId', recipientId),
text: `${formatJOY(amount)} were withdrawn from your channel account`,
subject: 'Funds withdrawn',
}
}
}
Expand Down

0 comments on commit 65a46d4

Please sign in to comment.