Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 One more notification email fix #254

Merged
merged 2 commits into from
Nov 27, 2023
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
4 changes: 2 additions & 2 deletions scripts/generate-emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const gleevRoot = 'https://gleev.xyz'
const contexts = {
gleev: {
title: 'Hi alice,',
subTitle: 'You have a new notifications:',
subTitle: 'You have a new notification:',

app: {
name: 'Gleev',
Expand All @@ -38,7 +38,7 @@ const contexts = {
get studio() {
return merge({}, this.gleev, {
title: 'Your channel “Joyblocks”,',
subTitle: 'Has a new notifications:',
subTitle: 'Has a new notification:',
app: {
name: 'Studio',
logo: `${gleevLogos}/header-studio.png`,
Expand Down
162 changes: 80 additions & 82 deletions src/auth-server/emails/templates/mjml/notification.html.mst.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,38 @@
</mj-attributes>
</mj-head>

<mj-body>
<!-- Header -->
<mj-section padding="24px 0 0">
<mj-column>
<mj-image
src="{{ app.logo }}"
alt="{{ app.name }}"
width="194px"
height="96px"
padding="4px"
></mj-image>
</mj-column>
</mj-section>

<!-- Main -->
<mj-wrapper padding="40px 16px" background-color="#FFFFFF">
<!-- Greeting -->
<mj-section padding="0">
<mj-body background-color="#FFFFFF">
<mj-wrapper border="1px solid #d6dee7" padding="0">
<!-- Header -->
<mj-section padding="24px 0 0">
<mj-column>
<mj-text mj-class="bold" padding="0" font-size="24px" line-height="24px">
{{ title }}
</mj-text>
<mj-text mj-class="big" padding="8px 0 24px 0">{{ subTitle }}</mj-text>
<mj-image
src="{{ app.logo }}"
alt="{{ app.name }}"
width="194px"
height="96px"
padding="4px"
></mj-image>
</mj-column>
</mj-section>

<!-- Greeting -->
<mj-section padding="24px 16px" text-align="center">
<mj-group width="440px">
<mj-column>
<mj-text mj-class="bold" padding="0" font-size="24px" line-height="24px">
{{ title }}
</mj-text>
<mj-text mj-class="big" padding="8px 0 0">{{ subTitle }}</mj-text>
</mj-column>
</mj-group>
</mj-section>

<!-- Notification -->
<mj-section background-color="#DAE2EB" border-radius="4px" padding="16px" text-align="left">
<mj-group>
<mj-section padding="0 16px" text-align="center">
<mj-group background-color="#DAE2EB" width="440px">
<!-- Avatar -->
<mj-column vertical-align="middle" width="10%">
<mj-column vertical-align="middle" width="10%" border-radius="4px" padding="16px">
<mj-button mj-class="link" href="{{ notification.link }}" align="center" padding="0">
<div
style="width: 40px; height: 40px; border-radius: 50%; display: inline-block; background-image: url({{ notification.avatar }}); background-size: contain; background-repeat: no-repeat; background-color: #4038FF;"
Expand All @@ -74,7 +75,7 @@
</mj-column>

<!-- Text -->
<mj-column vertical-align="middle" width="90%">
<mj-column vertical-align="middle" width="90%" padding="16px">
<mj-button
mj-class="link"
href="{{ notification.link }}"
Expand All @@ -97,66 +98,63 @@
</mj-section>

<!-- App link -->
<mj-section padding="24px 0 0">
<mj-column>
<mj-button
mj-class="big bold"
href="{{ app.notificationLink }}"
padding="0"
inner-padding="16px"
background-color="#4038FF"
color="#FFFFFF"
border-radius="2px"
>
View on {{ app.name }}
</mj-button>
<mj-section padding="24px 16px 40px" text-align="center">
<mj-group width="440px">
<mj-column>
<mj-button
mj-class="big bold"
href="{{ app.notificationLink }}"
padding="0"
inner-padding="16px"
background-color="#4038FF"
color="#FFFFFF"
border-radius="2px"
>
View on {{ app.name }}
</mj-button>
</mj-column>
</mj-group>
</mj-section>

<!-- Footer -->
<mj-section padding="0" background-color="#DAE2EB" full-width="full-width">
<mj-column background-color="#DAE2EB">
<mj-image
src="{{ app.logoAlt }}"
alt="{{ app.name }}"
width="35px"
height="30px"
padding="24px 0 10px"
></mj-image>
</mj-column>
</mj-section>
</mj-wrapper>

<!-- Footer -->
<mj-section padding="0" background-color="#DAE2EB" full-width="full-width">
<mj-column background-color="#DAE2EB">
<mj-image
src="{{ app.logoAlt }}"
alt="{{ app.name }}"
width="35px"
height="30px"
padding="24px 0 10px"
></mj-image>
</mj-column>
</mj-section>
<mj-section padding="0" background-color="#DAE2EB">
<mj-group>
<mj-column>
<mj-button mj-class="link footer-link" href="{{ app.homeLink }}" align="right">
{{ app.nameAlt }}
</mj-button>
</mj-column>
<mj-column>
<mj-button mj-class="link footer-link" href="https://www.joystream.org/">
Joystream.org
</mj-button>
</mj-column>
</mj-group>
</mj-section>

<mj-section padding="0" background-color="#DAE2EB" full-width="full-width">
<mj-group>
<mj-column>
<mj-button
mj-class="link footer-link"
href="{{ app.homeLink }}"
align="right"
border-right="solid 1px #C2E0FF33"
>
{{ app.nameAlt }}
</mj-button>
</mj-column>
<mj-column>
<mj-button mj-class="link footer-link" href="https://www.joystream.org/">
Joystream.org
</mj-button>
<mj-section padding="0 0 24px" background-color="#DAE2EB" full-width="full-width">
<mj-column background-color="#DAE2EB" padding="16px 16px 24px">
<mj-text color="#343D44" align="center" padding="0">
You can
<a href="{{ app.unsubscribeLink }}" target="_blank" style="color: currentColor">
unsubscribe
</a>
anytime.
</mj-text>
</mj-column>
</mj-group>
</mj-section>

<mj-section padding="0 0 24px" background-color="#DAE2EB" full-width="full-width">
<mj-column background-color="#DAE2EB" padding="16px 16px 24px">
<mj-text color="#343D44" align="center" padding="0">
You can
<a href="{{ app.unsubscribeLink }}" target="_blank" style="color: currentColor">
unsubscribe
</a>
anytime.
</mj-text>
</mj-column>
</mj-section>
</mj-section>
</mj-wrapper>
</mj-body>
</mjml>
4 changes: 2 additions & 2 deletions src/mail-scheduler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ async function getMessage(
const member = await em.getRepository(Membership).findOneBy({ id: recipient.membership })
return {
title: `Hi ${member?.handle ?? ''}`,
subTitle: 'You have a new notifications:',
subTitle: 'You have a new notification:',
}
}
case 'ChannelRecipient': {
const channel = await em.getRepository(Channel).findOneBy({ id: recipient.channel })
return {
title: `Your channel “${channel?.title}”,`,
subTitle: 'Has a new notifications:',
subTitle: 'Has a new notification:',
}
}
}
Expand Down
39 changes: 23 additions & 16 deletions src/utils/notification/notificationAvatars.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import { EntityManager } from 'typeorm'
import { Channel, MemberMetadata } from '../../model'
import { Channel, MemberMetadata, StorageDataObject } from '../../model'
import { ConfigVariable, config } from '../config'

export const getNotificationAvatar = async (
em: EntityManager,
type: 'channelId' | 'membershipId',
param: string
): Promise<string> => {
if (type === 'channelId') {
const channel = await em.getRepository(Channel).findOneBy({ id: param })
const avatar = channel?.avatarPhoto
switch (type) {
case 'channelId': {
const channel = await em.getRepository(Channel).findOneBy({ id: param })

if (!avatar || !avatar.isAccepted || !avatar.resolvedUrls[0]) {
const notificationAssetRoot = await config.get(ConfigVariable.AppAssetStorage, em)
return `${notificationAssetRoot}/placeholder/avatar.png`
if (!channel?.avatarPhotoId) break

const avatar = await em
.getRepository(StorageDataObject)
.findOneBy({ id: channel.avatarPhotoId })

if (!avatar || !avatar.isAccepted || !avatar.resolvedUrls[0]) break

return avatar.resolvedUrls[0]
}

return avatar.resolvedUrls[0]
}
case 'membershipId': {
const member = await em.getRepository(MemberMetadata).findOneBy({ id: param })
const avatar = member?.avatar

const member = await em.getRepository(MemberMetadata).findOneBy({ id: param })
const avatar = member?.avatar
// AvatarObject is not yet supported
if (!avatar || avatar.isTypeOf !== 'AvatarUri') break

// AvatarObject is not yet supported
if (!avatar || avatar.isTypeOf === 'AvatarObject') {
const notificationAssetRoot = await config.get(ConfigVariable.AppAssetStorage, em)
return `${notificationAssetRoot}/placeholder/avatar.png`
return avatar.avatarUri
}
}

return avatar.avatarUri
// Fallback to a placeholder
const notificationAssetRoot = await config.get(ConfigVariable.AppAssetStorage, em)
return `${notificationAssetRoot}/placeholder/avatar.png`
}
Loading