diff --git a/connect/notificationServices/email.js b/connect/notificationServices/email.js index 3078f95..40a64a5 100644 --- a/connect/notificationServices/email.js +++ b/connect/notificationServices/email.js @@ -245,7 +245,33 @@ function handler(topicName, messageJSON, notification) { }; eventMessage.data[eventMessage.data.type] = true; _.assign(eventMessage.data, notification.contents); + + // message service may return tags + // to understand if post notification is regarding phases or no, we will try to get phaseId from the tags + const tags = _.get(notification.contents, 'tags', []) + const PHASE_ID_REGEXP = /phase#(\d+)/ + const phaseIds = tags.map((tag) => _.get(tag.match(PHASE_ID_REGEXP), '1', null)) + const phaseId = _.find(phaseIds, (phaseId) => phaseId !== null) + if (phaseId) { + eventMessage.data.phaseId = phaseId; + } + + // if the notification is regarding topic: dashboard topic, dashboard post or phase post + // we build a link to the post + if (eventMessage.data.topicId) { + // phase post + if (eventMessage.data.phaseId) { + eventMessage.data.postURL = `${config.CONNECT_URL}/projects/${eventMessage.data.projectId}/plan#phase-${eventMessage.data.phaseId}-posts-${eventMessage.data.postId}`; + + // dashboard post + } else if (eventMessage.data.postId) { + eventMessage.data.postURL = `${config.CONNECT_URL}/projects/${eventMessage.data.projectId}#comment-${eventMessage.data.postId}`; + // dashboard topic + } else { + eventMessage.data.postURL = `${config.CONNECT_URL}/projects/${eventMessage.data.projectId}#feed-${eventMessage.data.topicId}`; + } + } // default values that get overridden when the notification is about topics/posts updates let reference = 'project'; diff --git a/emails/src/partials/topics_and_posts.html b/emails/src/partials/topics_and_posts.html index bf81861..f7b6751 100644 --- a/emails/src/partials/topics_and_posts.html +++ b/emails/src/partials/topics_and_posts.html @@ -170,7 +170,7 @@ - + View post on Connect @@ -196,7 +196,7 @@ - +
{{@root.connectURL}}/projects/{{notifications.[0].projectId}}#feed-{{notifications.[0].topicId}}
{{notifications.[0].postURL}}