Skip to content

Commit 46c4e25

Browse files
authoredJul 14, 2024··
Feat/email notification revisited (#1110)
* getting better email notifications * completing basic email template for a new issue imported * fixing logo source because of non well support for base64 images * fixing logo in default email template * fixing logo * added preheader text * more email adjustments * adding a base statement template to use to migrate all emails for now * replacing mails with the new template * fixing issue with undefined content * fixing issue with undefined content
1 parent c9ce94f commit 46c4e25

18 files changed

+373
-201
lines changed
 

‎.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v17.9.1

‎locales/en.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@
129129
"mail.webhook.payment.transfer.finished.message": "<p>We transfered {{currency}} {{amount}} for your account and you are goint to see it in your transactions as a payment from Gitpay.</p><p>The transfer was finished at {{date}}</p>",
130130
"mail.webhook.github.issue.new.subject": "A new task from your issue was added on Gitpay: {{title}}",
131131
"mail.webhook.github.issue.new.message": "<p>Your issue <a href=\"{{issue}}\">{{issue}}</a> from your repo <a href=\"{{repo}}\">{{repo}}</a> was added on Gitpay and now you can add a bounty and assign developers interested in solving your tasks.</p><p>Here is the URL: <a href=\"{{task}}\">{{task}}</a> </p>",
132-
"mail.task.me.subject": "You created a new task on Gitpay",
132+
"mail.task.me.subject": "You imported a new issue to Gitpay",
133+
"mail.task.new.intro": "hi there!",
134+
"mail.task.new.subtitle1": "<p>You imported a new issue from {{provider}} on Gitpay: <br /><a href=\"{{providerUrl}}\">{{title}}</a></p><p>Now you can add a bounty or invite sponsors to fund your issue. You can invite colaborators to solve your issue too. The user who solve the issue and merge the PR will receive the bounties added to this issue.</p>",
135+
"mail.task.new.callToActionText": "See issue on Githpay",
136+
"mail.task.new.subtitle2": "<p></p>",
137+
"mail.task.new.footerMessage": "You received this message because you imported your issue to <a href=\"http://gitpay.me\" target=\"_blank\">Gitpay</a>",
133138
"mail.task.payment.subject": "A bounty of $ {{value}} for the task: {{title}} was added on Gitpay",
134139
"mail.task.payment.title": "A payment of $ {{value}} with credit card was added to the task",
135140
"mail.task.bounties.subject": "We have issues with bounties on Gitpay",

‎modules/app/controllers/task.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ exports.syncTask = (req, res) => {
7777
res.send(data)
7878
}).catch((error) => {
7979
// eslint-disable-next-line no-console
80-
console.log('error on task controller', error)
80+
console.log('error on sync task controller', error)
8181
// eslint-disable-next-line no-console
82-
console.log('error raw', error.raw)
83-
res.send({ error: error.raw })
82+
console.log('error raw', error)
83+
res.send({ error: error })
8484
})
8585
}
8686

‎modules/mail/assign.js

+58-62
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const moment = require('moment')
66
const ptLocale = require('moment/locale/pt-br')
77
const enLocale = require('moment/locale/en-gb')
88
const i18n = require('i18n')
9+
const emailTemplate = require('./templates/base-content')
910

1011
const setMomentLocale = (lang) => {
1112
if (lang === 'br') {
@@ -18,14 +19,14 @@ const setMomentLocale = (lang) => {
1819

1920
const AssignMail = {
2021
owner: {
21-
interested: (to, task, name, offer) => {},
22-
assigned: (to, task, name) => {},
22+
interested: (to, task, name, offer) => { },
23+
assigned: (to, task, name) => { },
2324
},
24-
messageInterested: (user, task, message) => {},
25-
notifyInterestedUser: (user, task) => {},
26-
interested: (to, task, name) => {},
27-
assigned: (to, task) => {},
28-
error: (msg) => {}
25+
messageInterested: (user, task, message) => { },
26+
notifyInterestedUser: (user, task) => { },
27+
interested: (to, task, name) => { },
28+
assigned: (to, task) => { },
29+
error: (msg) => { }
2930
}
3031

3132
if (constants.canSendEmail) {
@@ -34,29 +35,28 @@ if (constants.canSendEmail) {
3435
const language = user.language || 'en'
3536
i18n.setLocale(language)
3637
setMomentLocale(language)
37-
request(
38+
user?.receiveNotifications && request(
3839
to,
3940
i18n.__('mail.assign.owner.subject'),
4041
[
4142
{
4243
type: 'text/html',
43-
value: `
44-
<p>${i18n.__('mail.assign.owner.hello')},</p>
45-
<p>${i18n.__('mail.assign.owner.main', { email: interested.email, name: interested.name || interested.username, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
44+
value: emailTemplate.baseContentEmailTemplate(
45+
i18n.__('mail.assign.owner.hello'),
46+
`<p>${i18n.__('mail.assign.owner.main', { email: interested.email, name: interested.name || interested.username, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
4647
<p>${i18n.__('mail.assign.owner.suggest', { value: offer.value, suggestedDate: offer.suggestedDate ? offer.suggestedDate : i18n.__('mail.assigned.nodate'), learn: offer.learn ? i18n.__('mail.statement.yes') : i18n.__('mail.statement.no'), comment: offer.comment ? offer.comment : i18n.__('mail.offer.nocomment') })}</p>
4748
<p>${i18n.__('mail.assign.owner.sec')}</p>
4849
${Signatures.buttons(language, {
49-
primary: {
50-
label: 'mail.assign.owner.button.primary',
51-
title: task.title,
52-
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}/offers`
53-
},
54-
secondary: {
55-
label: 'mail.assign.owner.button.secondary',
56-
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}/interested`
57-
}
58-
})}
59-
<p>${Signatures.sign(language)}</p>`
50+
primary: {
51+
label: 'mail.assign.owner.button.primary',
52+
title: task.title,
53+
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}/offers`
54+
},
55+
secondary: {
56+
label: 'mail.assign.owner.button.secondary',
57+
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}/interested`
58+
}
59+
})}`)
6060
},
6161
]
6262
)
@@ -71,19 +71,18 @@ ${Signatures.buttons(language, {
7171
const deadlineFromNow = task.deadline ? moment(task.deadline).fromNow() : i18n.__('mail.assigned.anytime')
7272
i18n.setLocale(language)
7373
setMomentLocale(language)
74-
request(
74+
user?.receiveNotifications && request(
7575
to,
7676
i18n.__('mail.assign.owner.assigned.subject', { assignedName }),
7777
[
7878
{
7979
type: 'text/html',
80-
value: `
81-
<p>${i18n.__('mail.hello', { name })}</p>
82-
<p>${i18n.__('mail.assign.owner.assigned.main', { assignedName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
80+
value: emailTemplate.baseContentEmailTemplate(
81+
i18n.__('mail.hello', { name }),
82+
`<p>${i18n.__('mail.assign.owner.assigned.main', { assignedName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
8383
<p>${i18n.__('mail.assign.owner.assigned.deadline.date', { date: deadline })}</p>
8484
<p>${i18n.__('mail.assign.owner.assigned.deadline.days', { days: deadlineFromNow })}</p>
85-
<p>${i18n.__('mail.assign.owner.assigned.instructions')}</p>
86-
<p>${Signatures.sign(language)}</p>`
85+
<p>${i18n.__('mail.assign.owner.assigned.instructions')}</p>`)
8786
},
8887
]
8988
)
@@ -94,17 +93,17 @@ ${Signatures.buttons(language, {
9493
const language = user.language || 'en'
9594
i18n.setLocale(language)
9695
setMomentLocale(language)
97-
request(
96+
user?.receiveNotifications && request(
9897
to,
9998
i18n.__('mail.interested.owner.subject'),
10099
[
101100
{
102101
type: 'text/html',
103-
value: `
104-
<p>${i18n.__('mail.assign.owner.hello')},</p>
105-
<p>${i18n.__('mail.interested.main', { email: user.email, name: user.name || user.username, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
102+
value: emailTemplate.baseContentEmailTemplate(
103+
i18n.__('mail.assign.owner.hello'),
104+
`<p>${i18n.__('mail.interested.main', { email: user.email, name: user.name || user.username, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
106105
<p>${i18n.__('mail.interested.owner.sec')}</p>
107-
<p>${Signatures.sign(language)}</p>`
106+
`)
108107
},
109108
]
110109
)
@@ -118,27 +117,27 @@ ${Signatures.buttons(language, {
118117
i18n.setLocale(language)
119118
setMomentLocale(language)
120119

121-
request(
120+
user?.receiveNotifications && request(
122121
to,
123122
i18n.__('mail.assigned.subject'),
124123
[
125124
{
126125
type: 'text/html',
127-
value: `
128-
<p>${i18n.__('mail.hello', { name: name })}</p>
129-
<p>${i18n.__('mail.assigned.main', { name: name, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p> ${i18n.__('mail.assigned.message', { deadline: task.deadline ? dateFormat(task.deadline, constants.dateFormat) : i18n.__('mail.assigned.nodate'),
130-
deadlineFromNow: task.deadline ? moment(task.deadline).fromNow() : i18n.__('mail.assigned.anytime')
131-
})} ${Signatures.buttons(language, {
132-
primary: { label: 'mail.assigned.end.owner.button.primary',
133-
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}`
134-
},
135-
secondary: {
136-
label: 'mail.assigned.end.owner.button.secondary',
137-
url: `${task.url}`
138-
}
139-
})}
140-
<p>${Signatures.sign(language)}</p>`
141-
126+
value: emailTemplate.baseContentEmailTemplate(
127+
i18n.__('mail.hello', { name: name }),
128+
`<p>${i18n.__('mail.assigned.main', { name: name, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p> ${i18n.__('mail.assigned.message', {
129+
deadline: task.deadline ? dateFormat(task.deadline, constants.dateFormat) : i18n.__('mail.assigned.nodate'),
130+
deadlineFromNow: task.deadline ? moment(task.deadline).fromNow() : i18n.__('mail.assigned.anytime')
131+
})} ${Signatures.buttons(language, {
132+
primary: {
133+
label: 'mail.assigned.end.owner.button.primary',
134+
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}`
135+
},
136+
secondary: {
137+
label: 'mail.assigned.end.owner.button.secondary',
138+
url: `${task.url}`
139+
}
140+
})}`)
142141
}
143142
]
144143
)
@@ -151,18 +150,15 @@ ${Signatures.buttons(language, {
151150
const assignedUserName = assignedUser.name || assignedUser.username
152151
i18n.setLocale(language)
153152
setMomentLocale(language)
154-
request(
153+
user?.receiveNotifications && request(
155154
to,
156155
i18n.__('mail.interested.user.assigned.subject'),
157156
[
158157
{
159158
type: 'text/html',
160-
value: `
161-
<p>${i18n.__('mail.hello', { name: name })}</p>
162-
<p>${i18n.__('mail.interested.user.assigned.main', { username: assignedUserName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
163-
164-
<p>${Signatures.sign(language)}</p>`
165-
159+
value: emailTemplate.baseContentEmailTemplate(
160+
i18n.__('mail.hello', { name: name }),
161+
`<p>${i18n.__('mail.interested.user.assigned.main', { username: assignedUserName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`)
166162
}
167163
]
168164
)
@@ -176,16 +172,16 @@ ${Signatures.buttons(language, {
176172
const name = user.name || user.username
177173
i18n.setLocale(language)
178174
setMomentLocale(language)
179-
request(
175+
user?.receiveNotifications && request(
180176
to,
181177
i18n.__('mail.messageInterested.subject'),
182178
[
183179
{
184180
type: 'text/html',
185-
value: `
186-
<p>${i18n.__('mail.hello', { name: name })}</p>
187-
<p>${i18n.__('mail.messageInterested.intro', { name: senderName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
188-
${i18n.__('mail.messageInterested.message', { message })} <p>${Signatures.sign(language)}</p>`
181+
value: emailTemplate.baseContentEmailTemplate(
182+
i18n.__('mail.hello', { name: name }),
183+
`<p>${i18n.__('mail.messageInterested.intro', { name: senderName, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
184+
${i18n.__('mail.messageInterested.message', { message })} <p>${Signatures.sign(language)}</p>`)
189185
}],
190186
senderEmail
191187
)
@@ -198,7 +194,7 @@ ${i18n.__('mail.messageInterested.message', { message })} <p>${Signatures.sign(l
198194
[
199195
{
200196
type: 'text/html',
201-
value: msg
197+
value: emailTemplate.baseContentEmailTemplate(msg)
202198
},
203199
]
204200
)

‎modules/mail/content.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ${i18n.__('mail.sign.team')}
1414
1515
<p>
1616
https://gitpay.me (Web) <br />
17-
tarefas@gitpay.me (Email) <br />
17+
contact@gitpay.me (Email) <br />
1818
Worknenjoy Inc.,
1919
9450 SW Gemini Dr
2020
PMB 72684

‎modules/mail/deadline.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (constants.canSendEmail) {
3232
const to = user.email
3333
const language = user.language || 'en'
3434
i18n.setLocale(language)
35-
request(
35+
user?.receiveNotifications && request(
3636
to,
3737
i18n.__('mail.deadline.update.subject'),
3838
[
@@ -52,7 +52,7 @@ ${i18n.__('mail.assigned.update.message', { deadlineFromNow: task.deadline ? mom
5252
const to = user.email
5353
const language = user.language || 'en'
5454
i18n.setLocale(language)
55-
request(
55+
user?.receiveNotifications && request(
5656
to,
5757
i18n.__('mail.deadline.daysLeft.subject', { deadline: moment(task.deadline).fromNow() }),
5858
[
@@ -70,7 +70,7 @@ ${i18n.__('mail.assigned.update.message', { deadlineFromNow: task.deadline ? mom
7070
const to = user.email
7171
const language = user.language || 'en'
7272
i18n.setLocale(language)
73-
request(
73+
user?.receiveNotifications && request(
7474
to,
7575
i18n.__('mail.deadline.remember.subject', { deadline: moment(task.deadline).fromNow() }),
7676
[
@@ -90,7 +90,7 @@ ${i18n.__('mail.assigned.update.message', { deadlineFromNow: task.deadline ? mom
9090
// const urlExtend = `${process.env.FRONTEND_HOST}/task/${task.id}/interested/extend`
9191
i18n.setLocale(language)
9292
moment.locale(locales[language].label, locales[language].file)
93-
request(
93+
user?.receiveNotifications && request(
9494
to,
9595
i18n.__('mail.deadline.end.subject', { deadline: moment(task.deadline).fromNow() }),
9696
[
@@ -124,7 +124,7 @@ ${Signatures.buttons(language, {
124124
// const urlExtend = `${process.env.FRONTEND_HOST}/task/${task.id}/interested/extend`
125125
i18n.setLocale(language)
126126
moment.locale(locales[language].label, locales[language].file)
127-
request(
127+
user?.receiveNotifications && request(
128128
to,
129129
i18n.__('mail.deadline.end.owner.subject', { deadline: moment(task.deadline).fromNow() }),
130130
[

‎modules/mail/mail.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Signatures = require('./content')
22
const request = require('./request')
33
const constants = require('./constants')
44
const i18n = require('i18n')
5+
const emailTemplate = require('./templates/base-content')
56

67
const Sendmail = {
78
success: (user, subject, msg) => {},
@@ -13,14 +14,13 @@ if (constants.canSendEmail) {
1314
const to = user.email
1415
const language = user.language || 'en'
1516
i18n.setLocale(language)
16-
request(
17+
user?.receiveNotifications && request(
1718
to,
1819
subject,
1920
[
2021
{
2122
type: 'text/html',
22-
value: `${msg}
23-
${Signatures.sign()}`
23+
value: emailTemplate.baseContentEmailTemplate(msg)
2424
},
2525
]
2626
)
@@ -30,14 +30,13 @@ if (constants.canSendEmail) {
3030
const to = user.email
3131
const language = user.language || 'en'
3232
i18n.setLocale(language)
33-
request(
33+
user?.receiveNotifications && request(
3434
to,
3535
subject,
3636
[
3737
{
3838
type: 'text/html',
39-
value: `${msg}
40-
${Signatures.sign()}`
39+
value: emailTemplate.baseContentEmailTemplate(msg)
4140
},
4241
]
4342
)

‎modules/mail/order.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const request = require('./request')
22
const Signatures = require('./content')
33
const constants = require('./constants')
44
const i18n = require('i18n')
5+
const emailTemplate = require('./templates/base-content')
56

67
i18n.configure({
78
directory: process.env.NODE_ENV !== 'production' ? `${__dirname}/locales` : `${__dirname}/locales/result`,
@@ -18,25 +19,25 @@ const OrderMail = {
1819

1920
if(constants.canSendEmail) {
2021
OrderMail.expiredOrders = (order) => {
21-
const to = order.User.email
22-
const language = order.User.language || 'en'
22+
const { User: user } = order
23+
const to = user.email
24+
const language = user.language || 'en'
2325
const task = order.Task
2426
i18n.setLocale(language)
2527
const mailData = {
2628
title: task.title,
2729
url: `${process.env.FRONTEND_HOST}/#/task/${task.id}`,
2830
value: order.amount,
2931
}
30-
request(
32+
user?.receiveNotifications && request(
3133
to,
32-
i18n.__('mail.order.expiredOrders.subject') || 'Expired Orders',
34+
i18n.__('mail.order.expiredOrders.subject'),
3335
[
3436
{
3537
type: 'text/html',
36-
value: `
37-
<p>${i18n.__('mail.order.expiredOrders.content.main', mailData) ||
38-
`The pre authorized payment of $ ${mailData.value} for the issue <a href=\"${mailData.url}\">${mailData.title}</a> made using Paypal expired, and you need to make a new payment to keep the bounty available. Please visit https://gitpay.me/#/profile/payments to update your payment.`}</p>
39-
<p>${Signatures.sign(language)}</p>`
38+
value: emailTemplate.baseContentEmailTemplate(`
39+
<p>${i18n.__('mail.order.expiredOrders.content.main', mailData)}</p>`,
40+
`The pre authorized payment of $ ${mailData.value} for the issue <a href=\"${mailData.url}\">${mailData.title}</a> made using Paypal expired, and you need to make a new payment to keep the bounty available. Please visit https://gitpay.me/#/profile/payments to update your payment.`)
4041
},
4142
]
4243
)

‎modules/mail/payment.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Signatures = require('./content')
22
const request = require('./request')
33
const constants = require('./constants')
44
const i18n = require('i18n')
5+
const emailTemplate = require('./templates/base-content')
56

67
const PaymentMail = {
78
success: (user, task, value) => {},
@@ -17,30 +18,29 @@ if (constants.canSendEmail) {
1718
const to = user.email
1819
const language = user.language || 'en'
1920
i18n.setLocale(language)
20-
request(
21+
user?.receiveNotifications && request(
2122
to,
2223
i18n.__('mail.payment.success.subject'),
2324
[
2425
{
2526
type: 'text/html',
26-
value: `
27-
<p>${i18n.__('mail.payment.success.content.main', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
28-
<p>${Signatures.sign(language)}</p>`
27+
value: emailTemplate.baseContentEmailTemplate(`
28+
<p>${i18n.__('mail.payment.success.content.main', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`)
2929
},
3030
]
3131
)
3232
}
3333

3434
PaymentMail.support = (user, task, order) => {
3535
i18n.setLocale('en')
36-
request(
36+
user?.receiveNotifications && request(
3737
constants.notificationEmail,
3838
i18n.__('mail.payment.support'),
3939
[
4040
{
4141
type: 'text/html',
42-
value: `Support was requested by the user ${user.name}, (${user.email})
43-
for the task: ${task.id}, order: ${order.id}, for the value of ${order.amount}.`
42+
value: emailTemplate.baseContentEmailTemplate(`Support was requested by the user ${user.name}, (${user.email})
43+
for the task: ${task.id}, order: ${order.id}, for the value of ${order.amount}.`)
4444
},
4545
]
4646
)
@@ -50,16 +50,15 @@ if (constants.canSendEmail) {
5050
const to = user.email
5151
const language = user.language || 'en'
5252
i18n.setLocale(language)
53-
request(
53+
user?.receiveNotifications && request(
5454
to,
5555
i18n.__('mail.payment.assigned.subject'),
5656
[
5757
{
5858
type: 'text/html',
59-
value: `
60-
<p>${i18n.__('mail.payment.assigned.content.main', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
61-
<p>${i18n.__('mail.payment.assigned.content.secondary')}</p>
62-
<p>${Signatures.sign(language)}</p>`
59+
value: emailTemplate.baseContentEmailTemplate(`
60+
<p>${i18n.__('mail.payment.assigned.content.main', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`,
61+
`<p>${i18n.__('mail.payment.assigned.content.secondary')}</p>`)
6362
},
6463
]
6564
)
@@ -69,15 +68,15 @@ if (constants.canSendEmail) {
6968
const to = user.email
7069
const language = user.language || 'en'
7170
i18n.setLocale(language)
72-
request(
71+
user?.receiveNotifications && request(
7372
to,
7473
i18n.__('mail.payment.subject.error'),
7574
[
7675
{
7776
type: 'text/html',
78-
value: `
79-
<p>${i18n.__('mail.payment.content.error', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
80-
<p>${Signatures.sign(language)}</p>`
77+
value: emailTemplate.baseContentEmailTemplate(`
78+
<p>${i18n.__('mail.payment.content.error', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`
79+
)
8180
},
8281
]
8382
)
@@ -87,15 +86,14 @@ if (constants.canSendEmail) {
8786
const to = user.email
8887
const language = user.language || 'en'
8988
i18n.setLocale(language)
90-
request(
89+
user?.receiveNotifications && request(
9190
to,
9291
i18n.__('mail.payment.subject.cancel'),
9392
[
9493
{
9594
type: 'text/html',
96-
value: `
97-
<p>${i18n.__('mail.payment.content.cancel', { value: order.amount, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
98-
<p>${Signatures.sign(language)}</p>`
95+
value: emailTemplate.baseContentEmailTemplate(`
96+
<p>${i18n.__('mail.payment.content.cancel', { value: order.amount, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`)
9997
},
10098
]
10199
)
@@ -105,15 +103,13 @@ if (constants.canSendEmail) {
105103
const to = user.email
106104
const language = user.language || 'en'
107105
i18n.setLocale(language)
108-
request(
106+
user?.receiveNotifications && request(
109107
to,
110108
i18n.__('mail.payment.subject.refund'),
111109
[
112110
{
113111
type: 'text/html',
114-
value: `
115-
<p>${i18n.__('mail.payment.content.refund', { value: order.amount, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
116-
<p>${Signatures.sign(language)}</p>`
112+
value: emailTemplate.baseContentEmailTemplate(`<p>${i18n.__('mail.payment.content.refund', { value: order.amount, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>`)
117113
},
118114
]
119115
)

‎modules/mail/request.js

+8-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const handleResponse = require('./handleResponse')
44
const handleError = require('./handleError')
55
const Signatures = require('./content')
66
const { copyEmail, notificationEmail, fromEmail } = require('./constants')
7+
const emailTemplate = require('./templates/default')
78

89
module.exports = (to, subject, content, replyEmail) => {
910
// eslint-disable-next-line no-console
@@ -19,6 +20,12 @@ module.exports = (to, subject, content, replyEmail) => {
1920
console.log(content)
2021
// eslint-disable-next-line no-console
2122
console.log(' ----- end email content ---- ')
23+
// eslint-disable-next-line no-console
24+
console.log(' ----- start email full content ---- ')
25+
// eslint-disable-next-line no-console
26+
console.log(emailTemplate.defaultEmailTemplate(content[0].value))
27+
// eslint-disable-next-line no-console
28+
console.log(' ----- end email full content ---- ')
2229
return sendgrid.apiKey && sg.API(sg.emptyRequest({
2330
method: 'POST',
2431
path: '/v3/mail/send',
@@ -47,42 +54,7 @@ module.exports = (to, subject, content, replyEmail) => {
4754
content:
4855
[{
4956
type: content[0].type,
50-
value: `
51-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
52-
<html xmlns="http://www.w3.org/1999/xhtml">
53-
<head>
54-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
55-
<title>Gitpay mail notification</title>
56-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
57-
</head>
58-
59-
<body style="margin: 0; padding: 0;">
60-
<table color: #153643; font-family: Arial, sans-serif; font-size: 32px; cellpadding="0" cellspacing="0" width="100%">
61-
<tr>
62-
<td>
63-
${Signatures.header()}
64-
</td>
65-
</tr>
66-
<tr>
67-
<td bgcolor="#fff" style="padding: 40px 30px 40px 30px;">
68-
<table cellpadding="0" cellspacing="0" width="100%">
69-
<tr>
70-
<td>
71-
<h2>${subject}</h2>
72-
</td>
73-
</tr>
74-
<tr>
75-
<td>
76-
${content[0].value}
77-
</td>
78-
</tr>
79-
</table>
80-
</td>
81-
</tr>
82-
</table>
83-
</body>
84-
</html>
85-
`
57+
value: emailTemplate.defaultEmailTemplate(content[0].value)
8658
}]
8759
},
8860
})).then(handleResponse).catch(handleError)

‎modules/mail/status.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const constants = require('./constants')
55
const moment = require('moment')
66
const ptLocale = require('moment/locale/pt-br')
77
const i18n = require('i18n')
8+
const emailTemplate = require('./templates/base-content')
89

910
moment.locale('pt-br', ptLocale)
1011

@@ -28,17 +29,17 @@ if (constants.canSendEmail) {
2829
const to = user.email
2930
const language = user.language || 'en'
3031
i18n.setLocale(language)
31-
request(
32+
user?.receiveNotifications && request(
3233
to,
3334
i18n.__('mail.status.subject'),
3435
[
3536
{
3637
type: 'text/html',
37-
value: `
38-
<p>Olá ${i18n.__('mail.hello', { name: name })}</p>
39-
<p>${i18n.__('mail.status.message.first', { title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
38+
value: emailTemplate.baseContentEmailTemplate(
39+
i18n.__('mail.hello', { name: name }),
40+
`<p>${i18n.__('mail.status.message.first', { title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}</p>
4041
<p>${i18n.__('mail.status.message.second', { status: STATUSES[task.status] })}</p>
41-
<p>${Signatures.sign(language)}</p>`
42+
<p>${Signatures.sign(language)}</p>`)
4243
},
4344
]
4445
)
@@ -51,7 +52,7 @@ if (constants.canSendEmail) {
5152
[
5253
{
5354
type: 'text/html',
54-
value: msg
55+
value: emailTemplate.baseContentEmailTemplate(msg)
5556
},
5657
]
5758
)

‎modules/mail/task.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const i18n = require('i18n')
77
const constants = require('./constants')
88
const withTemplate = require('./template')
99
const models = require('../../models')
10+
const emailTemplate = require('./templates/main-content')
11+
12+
function capitalizeFirstLetter(string) {
13+
return string[0].toUpperCase() + string.slice(1);
14+
}
1015

1116
// moment.locale('pt-br', ptLocale)
1217

@@ -29,15 +34,46 @@ i18n.configure({
2934
i18n.init()
3035

3136
const TaskMail = {
32-
send: (user, data) => Promise.resolve({}),
37+
new: (user, task) => {},
38+
send: (user, task) => Promise.resolve({}),
3339
notify: (user, data) => Promise.resolve({}),
3440
weeklyBounties: (data) => Promise.resolve({}),
3541
weeklyLatest: () => Promise.resolve({}),
3642
notifyPayment: () => Promise.resolve({}),
37-
messageAuthor: (user, task, message) => Promise.resolve({})
43+
messageAuthor: (user, task, message) => {}
3844
}
3945

4046
if (constants.canSendEmail) {
47+
48+
TaskMail.new = (user, task) => {
49+
const to = user.email
50+
const language = user.language || 'en'
51+
i18n.setLocale(language)
52+
setMomentLocale(language)
53+
user?.receiveNotifications && request(
54+
to,
55+
i18n.__('mail.task.me.subject'),
56+
[
57+
{
58+
type: 'text/html',
59+
value: emailTemplate.mainContentEmailTemplate(
60+
i18n.__('mail.task.new.intro'),
61+
i18n.__('mail.task.new.subtitle1', {
62+
provider: capitalizeFirstLetter(task.provider),
63+
providerUrl: task.url,
64+
title: task.title,
65+
url: constants.taskUrl(task.id)
66+
}),
67+
i18n.__('mail.task.new.callToActionText'),
68+
constants.taskUrl(task.id),
69+
i18n.__('mail.task.new.subtitle2'),
70+
i18n.__('mail.task.new.footerMessage'),
71+
)
72+
}],
73+
constants.notificationEmail
74+
)
75+
}
76+
4177
TaskMail.send = (user, data) => {
4278
const to = user.email
4379
const language = user.language || 'en'
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports.baseContentEmailTemplate = (intro, content = '') => `
2+
<!-- START MAIN CONTENT AREA -->
3+
<tr>
4+
<td class="wrapper" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; box-sizing: border-box; padding: 24px;" valign="top">
5+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${intro}</p>
6+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${content}</p>
7+
</td>
8+
</tr>
9+
10+
<!-- END MAIN CONTENT AREA -->
11+
`;

‎modules/mail/templates/default.js

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
module.exports.defaultEmailTemplate = (content) => `
2+
<!doctype html>
3+
<html lang="en">
4+
<head>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>Simple Transactional Email</title>
8+
<style media="all" type="text/css">
9+
@media all {
10+
.btn-primary table td:hover {
11+
background-color: #2b5c45 !important;
12+
}
13+
14+
.btn-primary a:hover {
15+
background-color: #2b5c45 !important;
16+
border-color: #2b5c45 !important;
17+
}
18+
}
19+
@media only screen and (max-width: 640px) {
20+
.main p,
21+
.main td,
22+
.main span {
23+
font-size: 16px !important;
24+
}
25+
26+
.wrapper {
27+
padding: 8px !important;
28+
}
29+
30+
.content {
31+
padding: 0 !important;
32+
}
33+
34+
.container {
35+
padding: 0 !important;
36+
padding-top: 8px !important;
37+
width: 100% !important;
38+
}
39+
40+
.main {
41+
border-left-width: 0 !important;
42+
border-radius: 0 !important;
43+
border-right-width: 0 !important;
44+
}
45+
46+
.btn table {
47+
max-width: 100% !important;
48+
width: 100% !important;
49+
}
50+
51+
.btn a {
52+
font-size: 16px !important;
53+
max-width: 100% !important;
54+
width: 100% !important;
55+
}
56+
}
57+
@media all {
58+
.ExternalClass {
59+
width: 100%;
60+
}
61+
62+
.ExternalClass,
63+
.ExternalClass p,
64+
.ExternalClass span,
65+
.ExternalClass font,
66+
.ExternalClass td,
67+
.ExternalClass div {
68+
line-height: 100%;
69+
}
70+
71+
.apple-link a {
72+
color: inherit !important;
73+
font-family: inherit !important;
74+
font-size: inherit !important;
75+
font-weight: inherit !important;
76+
line-height: inherit !important;
77+
text-decoration: none !important;
78+
}
79+
80+
#MessageViewBody a {
81+
color: inherit;
82+
text-decoration: none;
83+
font-size: inherit;
84+
font-family: inherit;
85+
font-weight: inherit;
86+
line-height: inherit;
87+
}
88+
}
89+
</style>
90+
</head>
91+
<body style="font-family: Helvetica, sans-serif; -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.3; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; background-color: #f4f5f6; margin: 0; padding: 0;">
92+
<div style="width: 100%; text-align: center; margin: 0; padding: 20px 0 0;">
93+
<img width="200" src="https://docs.gitpay.me/assets/img/logo-complete.png" alt="Gitpay" />
94+
</div>
95+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f4f5f6; width: 100%;" width="100%" bgcolor="#f4f5f6">
96+
<tr>
97+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top">&nbsp;</td>
98+
<td class="container" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; max-width: 600px; padding: 0; padding-top: 24px; width: 600px; margin: 0 auto;" width="600" valign="top">
99+
<div class="content" style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 600px; padding: 0;">
100+
101+
<!-- START CENTERED WHITE CONTAINER -->
102+
<span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">We have updates for your issues imported on Gitpay.</span>
103+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #ffffff; border: 1px solid #eaebed; border-radius: 16px; width: 100%;" width="100%">
104+
${content}
105+
</table>
106+
107+
<!-- START FOOTER -->
108+
<div class="footer" style="clear: both; padding-top: 24px; text-align: center; width: 100%;">
109+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
110+
<tr>
111+
<td class="content-block" style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;" valign="top" align="center">
112+
<span class="apple-link" style="color: #9a9ea6; font-size: 16px; text-align: center;">
113+
https://gitpay.me (Web) <br />
114+
contact@gitpay.me (Email) <br />
115+
Worknenjoy Inc.,<br />
116+
9450 SW Gemini Dr<br />
117+
PMB 72684<br />
118+
Beaverton, Oregon 97008-7105 US (Mail) <br />
119+
</span>
120+
<br> Don't like these emails? <a href="https://gitpay.me/#/profile/user-account/settings" style="text-decoration: underline; color: #9a9ea6; font-size: 16px; text-align: center;">Change your e-mail notification settings in your account</a>.
121+
</td>
122+
</tr>
123+
<tr>
124+
<td class="content-block powered-by" style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;" valign="top" align="center">
125+
Powered by <a href="http://htmlemail.io" style="color: #9a9ea6; font-size: 16px; text-align: center; text-decoration: none;">HTMLemail.io</a>
126+
</td>
127+
</tr>
128+
</table>
129+
</div>
130+
131+
<!-- END FOOTER -->
132+
133+
<!-- END CENTERED WHITE CONTAINER --></div>
134+
</td>
135+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top">&nbsp;</td>
136+
</tr>
137+
</table>
138+
</body>
139+
</html>
140+
`;
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports.mainContentEmailTemplate = (intro, subtitle1, callToActionText, callToActionLink, subtitle2, footerMessage) => `
2+
<!-- START MAIN CONTENT AREA -->
3+
<tr>
4+
<td class="wrapper" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; box-sizing: border-box; padding: 24px;" valign="top">
5+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${intro}</p>
6+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${subtitle1}</p>
7+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; box-sizing: border-box; width: 100%; min-width: 100%;" width="100%">
8+
<tbody>
9+
<tr>
10+
<td align="center" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; padding-bottom: 16px;" valign="top">
11+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;">
12+
<tbody>
13+
<tr>
14+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; border-radius: 4px; text-align: center; background-color: #2b5c45;" valign="top" align="center" bgcolor="#0867ec"> <a href="${callToActionLink}" target="_blank" style="border: solid 2px #0867ec; border-radius: 4px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 16px; font-weight: bold; margin: 0; padding: 12px 24px; text-decoration: none; text-transform: capitalize; background-color: #2b5c45; border-color: #2b5c45; color: #ffffff;">${callToActionText}</a> </td>
15+
</tr>
16+
</tbody>
17+
</table>
18+
</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${subtitle2}</p>
23+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">${footerMessage}</p>
24+
</td>
25+
</tr>
26+
27+
<!-- END MAIN CONTENT AREA -->
28+
`;

‎modules/mail/transfer.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Signatures = require('./content')
22
const request = require('./request')
33
const constants = require('./constants')
44
const i18n = require('i18n')
5+
const emailTemplate = require('./templates/main-content')
56

67
const TransferMail = {
78
success: (to, task, value) => {},
@@ -17,15 +18,15 @@ if (constants.canSendEmail) {
1718
const to = user.email
1819
const language = user.language || 'en'
1920
i18n.setLocale(language)
20-
request(
21+
user?.receiveNotifications && request(
2122
to,
2223
i18n.__('mail.transfer.new.subject.success'),
2324
[
2425
{
2526
type: 'text/html',
26-
value: `
27-
<p>${i18n.__('mail.transfer.new.message.success', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>
28-
<p>${Signatures.sign(language)}</p>`
27+
value: emailTemplate.mainContentEmailTemplate(`
28+
<p>${i18n.__('mail.transfer.new.message.success', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>`
29+
)
2930
},
3031
]
3132
)
@@ -35,15 +36,14 @@ if (constants.canSendEmail) {
3536
const to = user.email
3637
const language = user.language || 'en'
3738
i18n.setLocale(language)
38-
request(
39+
user?.receiveNotifications && request(
3940
to,
4041
i18n.__('mail.transfer.notify.subject.success'),
4142
[
4243
{
4344
type: 'text/html',
44-
value: `
45-
<p>${i18n.__('mail.transfer.notify.message.success', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>
46-
<p>${Signatures.sign(language)}</p>`
45+
value: emailTemplate.mainContentEmailTemplate(
46+
`<p>${i18n.__('mail.transfer.notify.message.success', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>`)
4747
},
4848
]
4949
)
@@ -53,15 +53,14 @@ if (constants.canSendEmail) {
5353
const to = user.email
5454
const language = user.language || 'en'
5555
i18n.setLocale(language)
56-
request(
56+
user?.receiveNotifications && request(
5757
to,
5858
i18n.__('mail.transfer.error.subject'),
5959
[
6060
{
6161
type: 'text/html',
62-
value: `
63-
<p>${i18n.__('mail.transfer.error.message', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>
64-
<p>${Signatures.sign(language)}</p>`
62+
value: emailTemplate.mainContentEmailTemplate(`
63+
<p>${i18n.__('mail.transfer.error.message', { value: value, title: task.title, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}` })}<p>`)
6564
},
6665
]
6766
)
@@ -71,15 +70,13 @@ if (constants.canSendEmail) {
7170
const to = user.email
7271
const language = user.language || 'en'
7372
i18n.setLocale(language)
74-
request(
73+
user?.receiveNotifications && request(
7574
to,
7675
i18n.__('mail.transfer.missing.subject'),
7776
[
7877
{
7978
type: 'text/html',
80-
value: `
81-
<p>${i18n.__('mail.transfer.missing.message')}</p>
82-
<p>${Signatures.sign(language)}</p>`
79+
value: emailTemplate.mainContentEmailTemplate(`<p>${i18n.__('mail.transfer.missing.message')}</p>`)
8380
},
8481
]
8582
)
@@ -89,15 +86,15 @@ if (constants.canSendEmail) {
8986
const to = user.email
9087
const language = user.language || 'en'
9188
i18n.setLocale(language)
92-
request(
89+
user?.receiveNotifications && request(
9390
to,
9491
i18n.__('mail.transfer.missing.subject'),
9592
[
9693
{
9794
type: 'text/html',
98-
value: `
99-
<p>${i18n.__('mail.transfer.invalid.message')}</p>
100-
<p>${Signatures.sign(language)}</p>`
95+
value: emailTemplate.mainContentEmailTemplate(
96+
`<p>${i18n.__('mail.transfer.invalid.message')}</p>`
97+
)
10198
},
10299
]
103100
)
@@ -107,21 +104,20 @@ if (constants.canSendEmail) {
107104
const to = user.email
108105
const language = user.language || 'en'
109106
i18n.setLocale(language)
110-
request(
107+
user?.receiveNotifications && request(
111108
to,
112109
i18n.__('mail.transfer.bounty.subject'),
113110
[
114111
{
115112
type: 'text/html',
116-
value: `
113+
value: emailTemplate.mainContentEmailTemplate(`
117114
<p>${i18n.__('mail.transfer.bounty.message', {
118115
taskFromTitle: taskFrom.title,
119116
taskFromUrl: taskFrom.url,
120117
taskToTitle: taskTo.title,
121118
taskToUrl: taskTo.url,
122119
amount: order.amount
123-
})}</p>
124-
<p>${Signatures.sign(language)}</p>`
120+
})}</p>`)
125121
},
126122
]
127123
)

‎modules/mail/user.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const request = require('./request')
22
const constants = require('./constants')
33
const i18n = require('i18n')
4-
const UserAccountActivationTemplate = require('./templates/user-account-activation')
4+
const emailTemplate = require('./templates/main-content')
55

66
const UserMail = {
77
activation: (user, token) => {},
@@ -12,13 +12,13 @@ if (constants.canSendEmail) {
1212
const to = user.email
1313
const language = user.language || 'en'
1414
i18n.setLocale(language)
15-
request(
15+
user?.receiveNotifications && request(
1616
to,
1717
i18n.__('mail.user.activation.subject'),
1818
[
1919
{
2020
type: 'text/html',
21-
value: UserAccountActivationTemplate(i18n.__('mail.user.activation.message', { url: `${process.env.FRONTEND_HOST}/#/user/${user.id}/activate/${token}` }))
21+
value: emailTemplate.mainContentEmailTemplate(i18n.__('mail.user.activation.message', { url: `${process.env.FRONTEND_HOST}/#/user/${user.id}/activate/${token}` }))
2222
},
2323
]
2424
)

‎modules/tasks/taskBuilds.js

+10-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const secrets = require('../../config/secrets')
44
const url = require('url')
55
const requestPromise = require('request-promise')
66
const constants = require('../mail/constants')
7-
// const TaskMail = require('../mail/task')
8-
const Sendmail = require('../mail/mail')
7+
const TaskMail = require('../mail/task')
98
const roleExists = require('../roles').roleExists
109
const userExists = require('../users').userExists
1110
// const userOrganizations = require('../users/userOrganizations')
@@ -65,24 +64,15 @@ module.exports = Promise.method(async function taskBuilds (taskParameters) {
6564

6665
const taskData = task.dataValues
6766
const userData = await task.getUser()
68-
/*
69-
TaskMail.send(userData, {
70-
task: {
71-
title: taskData.title,
72-
issue_url: taskData.url,
73-
url: constants.taskUrl(taskData.id)
74-
}
75-
})
76-
TaskMail.notify(userData, {
77-
task: {
78-
title: taskData.title,
79-
issue_url: taskData.url,
80-
url: constants.taskUrl(taskData.id)
81-
}
82-
})
83-
*/
84-
Sendmail.success({ email: constants.fromEmail }, `A task ${taskData.url} was created`, `A task ${taskData.id} from ${userData.email} was created just now`)
85-
issueAddedComment(task)
67+
68+
try {
69+
if(userData.receiveNotifications) {
70+
TaskMail.new(userData, taskData)
71+
}
72+
issueAddedComment(task)
73+
} catch (e) {
74+
console.log('error on send email and post', e)
75+
}
8676
return { ...taskData, ProjectId: taskData.ProjectId }
8777
})
8878
})

0 commit comments

Comments
 (0)
Please sign in to comment.