mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
refactor "formatUser" to show the correct user and displayname
This commit is contained in:
@@ -32,6 +32,18 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param formatObj.name userName
|
||||||
|
* @param formatObj.displayName displayName
|
||||||
|
* @param formatObj.email email
|
||||||
|
* @param formatObj.uuid uuid
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function formatUser (formatObj) {
|
||||||
|
return `@${formatObj.name} ${formatObj.displayName} (${formatObj.email}; ${formatObj.uuid}`;
|
||||||
|
}
|
||||||
|
|
||||||
function sendFlagNotification ({
|
function sendFlagNotification ({
|
||||||
authorEmail,
|
authorEmail,
|
||||||
flagger,
|
flagger,
|
||||||
@@ -67,7 +79,12 @@ function sendFlagNotification ({
|
|||||||
if (!message.user && message.uuid === 'system') {
|
if (!message.user && message.uuid === 'system') {
|
||||||
authorName = 'System Message';
|
authorName = 'System Message';
|
||||||
} else {
|
} else {
|
||||||
authorName = `${message.user} - ${authorEmail} - ${message.uuid}`;
|
authorName = formatUser({
|
||||||
|
name: message.username,
|
||||||
|
displayName: message.user,
|
||||||
|
email: authorEmail,
|
||||||
|
uuid: message.uuid,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamp = `${moment(message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`;
|
const timestamp = `${moment(message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`;
|
||||||
@@ -89,10 +106,6 @@ function sendFlagNotification ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatUser (name, email, uuid) {
|
|
||||||
return `${name} (${email}; ${uuid}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendInboxFlagNotification ({
|
function sendInboxFlagNotification ({
|
||||||
authorEmail,
|
authorEmail,
|
||||||
flagger,
|
flagger,
|
||||||
@@ -102,7 +115,7 @@ function sendInboxFlagNotification ({
|
|||||||
if (SKIP_FLAG_METHODS) {
|
if (SKIP_FLAG_METHODS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let titleLink;
|
let titleLink = '';
|
||||||
let authorName;
|
let authorName;
|
||||||
let title = `Flag in ${flagger.profile.name}'s Inbox`;
|
let title = `Flag in ${flagger.profile.name}'s Inbox`;
|
||||||
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a PM`;
|
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a PM`;
|
||||||
@@ -116,8 +129,18 @@ function sendInboxFlagNotification ({
|
|||||||
let sender = '';
|
let sender = '';
|
||||||
let recipient = '';
|
let recipient = '';
|
||||||
|
|
||||||
const flaggerFormat = formatUser(flagger.profile.name, flagger.auth.local.email, flagger._id);
|
const flaggerFormat = formatUser({
|
||||||
const messageUserFormat = formatUser(message.user, authorEmail, message.uuid);
|
displayName: flagger.profile.name,
|
||||||
|
name: flagger.auth.local.username,
|
||||||
|
email: flagger.auth.local.email,
|
||||||
|
uuid: flagger._id,
|
||||||
|
});
|
||||||
|
const messageUserFormat = formatUser({
|
||||||
|
displayName: message.user,
|
||||||
|
name: message.username,
|
||||||
|
email: authorEmail,
|
||||||
|
uuid: message.uuid,
|
||||||
|
});
|
||||||
|
|
||||||
if (message.sent) {
|
if (message.sent) {
|
||||||
sender = flaggerFormat;
|
sender = flaggerFormat;
|
||||||
@@ -193,7 +216,12 @@ function sendSlurNotification ({
|
|||||||
title += ` - (${group.privacy} ${group.type})`;
|
title += ` - (${group.privacy} ${group.type})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
authorName = `${author.profile.name} - ${authorEmail} - ${author.id}`;
|
authorName = formatUser({
|
||||||
|
name: author.auth.local.username,
|
||||||
|
displayName: author.profile.name,
|
||||||
|
email: authorEmail,
|
||||||
|
uuid: author.id,
|
||||||
|
});
|
||||||
|
|
||||||
flagSlack.send({
|
flagSlack.send({
|
||||||
text,
|
text,
|
||||||
@@ -216,4 +244,5 @@ module.exports = {
|
|||||||
sendInboxFlagNotification,
|
sendInboxFlagNotification,
|
||||||
sendSubscriptionNotification,
|
sendSubscriptionNotification,
|
||||||
sendSlurNotification,
|
sendSlurNotification,
|
||||||
|
formatUser,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user