2019-07-05 03:19:24 +08:00
|
|
|
import { isNonEmptyArray, isUnd } from 'Common/Utils';
|
|
|
|
import { EmailModel } from 'Model/Email';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Array.<EmailModel>} emails
|
|
|
|
* @param {boolean=} friendlyView = false
|
|
|
|
* @param {boolean=} wrapWithLink = false
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function emailArrayToString(emails, friendlyView = false, wrapWithLink = false) {
|
|
|
|
const result = [];
|
2019-07-05 03:19:24 +08:00
|
|
|
if (isNonEmptyArray(emails)) {
|
2020-07-28 18:35:41 +08:00
|
|
|
emails.forEach(email => result.push(email.toLine(friendlyView, wrapWithLink)));
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
return result.join(', ');
|
|
|
|
}
|
2016-05-23 01:35:09 +08:00
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {Array.<EmailModel>} emails
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function emailArrayToStringClear(emails) {
|
|
|
|
const result = [];
|
2019-07-05 03:19:24 +08:00
|
|
|
if (isNonEmptyArray(emails)) {
|
2020-07-28 18:35:41 +08:00
|
|
|
emails.forEach(email => {
|
2020-07-28 23:20:14 +08:00
|
|
|
if (email && email.email && email.name) {
|
2020-07-28 18:35:41 +08:00
|
|
|
result.push(email.email);
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
2020-07-28 18:35:41 +08:00
|
|
|
});
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
return result.join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Array} json
|
|
|
|
* @returns {Array.<EmailModel>}
|
|
|
|
*/
|
|
|
|
export function emailArrayFromJson(json) {
|
|
|
|
const result = [];
|
2019-07-05 03:19:24 +08:00
|
|
|
if (isNonEmptyArray(json)) {
|
2020-07-28 18:35:41 +08:00
|
|
|
json.forEach(email => {
|
|
|
|
email = EmailModel.newInstanceFromJson(email);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (email) {
|
2016-07-07 05:03:30 +08:00
|
|
|
result.push(email);
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
2020-07-28 18:35:41 +08:00
|
|
|
});
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
return result;
|
|
|
|
}
|
2016-05-23 01:35:09 +08:00
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {Array.<EmailModel>} inputEmails
|
|
|
|
* @param {Object} unic
|
|
|
|
* @param {Array} localEmails
|
|
|
|
*/
|
|
|
|
export function replyHelper(inputEmails, unic, localEmails) {
|
2020-07-28 18:35:41 +08:00
|
|
|
if (inputEmails) {
|
|
|
|
inputEmails.forEach(email => {
|
|
|
|
if (isUnd(unic[email.email])) {
|
|
|
|
unic[email.email] = true;
|
|
|
|
localEmails.push(email);
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
2020-07-28 18:35:41 +08:00
|
|
|
});
|
2016-05-23 01:35:09 +08:00
|
|
|
}
|
|
|
|
}
|