Add custom unsubscribe option in a campaign
This commit is contained in:
parent
44fe8882b8
commit
68cb8384f7
9 changed files with 52 additions and 15 deletions
26
lib/tools.js
26
lib/tools.js
|
@ -181,7 +181,7 @@ function validateEmail(address, checkBlocked, callback) {
|
|||
|
||||
function getMessageLinks(serviceUrl, campaign, list, subscription) {
|
||||
return {
|
||||
LINK_UNSUBSCRIBE: urllib.resolve(serviceUrl, '/subscription/' + list.cid + '/unsubscribe/' + subscription.cid + '?c=' + campaign.cid),
|
||||
LINK_UNSUBSCRIBE: campaign.unsubscribe ? campaign.unsubscribe : urllib.resolve(serviceUrl, '/subscription/' + list.cid + '/unsubscribe/' + subscription.cid + '?c=' + campaign.cid),
|
||||
LINK_PREFERENCES: urllib.resolve(serviceUrl, '/subscription/' + list.cid + '/manage/' + subscription.cid),
|
||||
LINK_BROWSER: urllib.resolve(serviceUrl, '/archive/' + campaign.cid + '/' + list.cid + '/' + subscription.cid),
|
||||
CAMPAIGN_ID: campaign.cid,
|
||||
|
@ -195,7 +195,7 @@ function formatMessage(serviceUrl, campaign, list, subscription, message, filter
|
|||
|
||||
let links = getMessageLinks(serviceUrl, campaign, list, subscription);
|
||||
|
||||
let getValue = key => {
|
||||
let getTagValue = key => {
|
||||
key = (key || '').toString().toUpperCase().trim();
|
||||
if (links.hasOwnProperty(key)) {
|
||||
return links[key];
|
||||
|
@ -211,15 +211,19 @@ function formatMessage(serviceUrl, campaign, list, subscription, message, filter
|
|||
return false;
|
||||
};
|
||||
|
||||
return message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
|
||||
identifier = identifier.toUpperCase();
|
||||
let value = getValue(identifier);
|
||||
if (value === false) {
|
||||
return match;
|
||||
}
|
||||
value = (value || fallback || '').trim();
|
||||
return filter(value);
|
||||
});
|
||||
let tagReplace = message => {
|
||||
return message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
|
||||
identifier = identifier.toUpperCase();
|
||||
let value = getTagValue(identifier);
|
||||
if (value === false) {
|
||||
return match;
|
||||
}
|
||||
value = (value || fallback || '').trim();
|
||||
return filter(value);
|
||||
});
|
||||
};
|
||||
|
||||
return tagReplace(tagReplace(message));
|
||||
}
|
||||
|
||||
function prepareHtml(html, callback) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue