From d5b5ca441b81b1cfd854729790f378207fba4d92 Mon Sep 17 00:00:00 2001 From: Vitor Hugo Date: Fri, 9 Aug 2024 09:12:34 -0300 Subject: [PATCH 1/3] Fix email templates (#496) * use handle if exists * adjust template layout * add missing prop * also exclude user who commented, because he dont need to receive notification --- server/common/comments/post.ts | 23 +++++---- .../email-comment-template-compiler.ts | 3 +- .../templates/emails/comment-subscriber.hbs | 48 ++++++++++--------- server/templates/emails/comment.hbs | 40 ++++++++-------- server/templates/partials/styles.hbs | 5 +- 5 files changed, 66 insertions(+), 53 deletions(-) diff --git a/server/common/comments/post.ts b/server/common/comments/post.ts index 95ed47ed39..ebc7bf478e 100644 --- a/server/common/comments/post.ts +++ b/server/common/comments/post.ts @@ -3,6 +3,8 @@ import {IncludeOptions, Op, Sequelize, WhereOptions} from "sequelize"; import models from "db/models"; +import { truncateAddress } from "helpers/truncate-address"; + import {HttpBadRequestError, HttpConflictError, HttpNotFoundError} from "server/errors/http-errors"; import {Push} from "server/services/push/push"; import {AnalyticEventName, AnalyticEvents} from "server/services/push/types"; @@ -78,6 +80,8 @@ export default async function post(req: NextApiRequest, res: NextApiResponse) { const pushEvents: AnalyticEvents = []; await subscribeUserToTask(+issueId, user.id); + const creatorLabel = user.handle ? `@${user.handle}` : truncateAddress(user.address); + if (replyId) { const repliedComment = await models.comments.findOne({ where: { @@ -98,7 +102,7 @@ export default async function post(req: NextApiRequest, res: NextApiResponse) { type: name, data: { comment, - creator: user.address, + creator: creatorLabel, taskId: issueId, deliverableId: deliverableId, proposalId: proposalId, @@ -186,8 +190,8 @@ export default async function post(req: NextApiRequest, res: NextApiResponse) { entryId: deliverableId || proposalId, taskId: issueId, comment, - madeBy: user.handle || user.address, - creator: user.address, + madeBy: creatorLabel, + creator: creatorLabel, marketplace, }; @@ -211,10 +215,13 @@ export default async function post(req: NextApiRequest, res: NextApiResponse) { { email: { [Op.not]: "" } }, { id: { - [Op.notIn]: pushEvents.flatMap(event => event.params.target.map(target => target.id)) + [Op.notIn]: [ + bounty.userId, + user.id, + ...pushEvents.flatMap(event => event.params.target.map(target => target.id)) + ] } - }, - { id: { [Op.ne]: bounty.userId } } + } ] }, include: [ @@ -237,8 +244,8 @@ export default async function post(req: NextApiRequest, res: NextApiResponse) { entryId: deliverableId || proposalId, taskId: issueId, comment, - madeBy: user.handle || user.address, - creator: user.address, + madeBy: creatorLabel, + creator: creatorLabel, marketplace: bounty.network.name, }; diff --git a/server/templates/compilers/email-comment-template-compiler.ts b/server/templates/compilers/email-comment-template-compiler.ts index d1d562bd4f..2d44b45e5f 100644 --- a/server/templates/compilers/email-comment-template-compiler.ts +++ b/server/templates/compilers/email-comment-template-compiler.ts @@ -35,7 +35,8 @@ export class EmailCommentTemplateCompiler extends Template { pageTitle: title, comment: payload.data.comment, type, - actionHref: `${publicRuntimeConfig.urls.home}/${actionUrlPart}/?fromEmail=${payload.uuid}` + actionHref: `${publicRuntimeConfig.urls.home}/${actionUrlPart}/?fromEmail=${payload.uuid}`, + commentCreator: payload.data.creator, }; super.registerPartials(); diff --git a/server/templates/emails/comment-subscriber.hbs b/server/templates/emails/comment-subscriber.hbs index 327adf5816..6275dfe366 100644 --- a/server/templates/emails/comment-subscriber.hbs +++ b/server/templates/emails/comment-subscriber.hbs @@ -5,29 +5,31 @@ {{> headLinks}} {{> styles}} - - - - + +
- {{> logo}} - {{#if isTaskType}} -

You have a new comment on a subscribed task

- {{else}} -

You have a new comment on a {{type}} of a subscribed task

- {{/if}} + +
+ + + - -
+ {{> logo}} + {{#if isTaskType}} +

You have a new comment on a subscribed task

+ {{else}} +

You have a new comment on a {{type}} of a subscribed task

+ {{/if}} - - - - -
-

{{commentCreator}} commented:

-

{{comment}}

- View comment -
- {{> appLinks}} -
+ + + + +
+

{{commentCreator}} commented:

+

{{comment}}

+ View comment +
+ {{> appLinks}} +
+ diff --git a/server/templates/emails/comment.hbs b/server/templates/emails/comment.hbs index f4274e7c38..5bec933daf 100644 --- a/server/templates/emails/comment.hbs +++ b/server/templates/emails/comment.hbs @@ -5,24 +5,26 @@ {{> headLinks}} {{> styles}} - - - - - -
- {{> logo}} -

You have a new comment on your {{type}}

- - - - -
-

{{commentCreator}} Commented on your {{type}}:

-

{{comment}}

- View comment -
- {{> appLinks}} -
+ +
+ + + + +
+ {{> logo}} +

You have a new comment on your {{type}}

+ + + + +
+

{{commentCreator}} commented on your {{type}}:

+

{{comment}}

+ View comment +
+ {{> appLinks}} +
+
diff --git a/server/templates/partials/styles.hbs b/server/templates/partials/styles.hbs index ec05aa5853..68196189c0 100644 --- a/server/templates/partials/styles.hbs +++ b/server/templates/partials/styles.hbs @@ -1,12 +1,13 @@