sendInboxFlagNotification (for private message flag content)

This commit is contained in:
negue
2018-06-02 19:27:28 +02:00
parent 5a0eed7eae
commit ca5927fe73
2 changed files with 81 additions and 23 deletions

View File

@@ -44,7 +44,7 @@ function sendFlagNotification ({
let titleLink;
let authorName;
let title = `Flag in ${group.name}`;
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a message`;
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a group message`;
if (userComment) {
text += ` and commented: ${userComment}`;
@@ -81,6 +81,66 @@ function sendFlagNotification ({
});
}
function sendInboxFlagNotification ({
authorEmail,
flagger,
message,
userComment,
}) {
if (SKIP_FLAG_METHODS) {
return;
}
let titleLink;
let authorName;
let title = `Flag in ${flagger.profile.name}'s Inbox`;
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a PM`;
if (userComment) {
text += ` and commented: ${userComment}`;
}
if (!message.user && message.uuid === 'system') {
authorName = 'System Message';
} else {
authorName = `${message.user} - ${authorEmail} - ${message.uuid}`;
}
let messageText = message.text;
if (flagger.id === message.uuid) {
messageText += `: ${flagger.profile.name} is writing to itself.`;
} else {
let sender = '';
let recipient = '';
if (message.sent) {
sender = flagger.profile.name;
recipient = message.user;
} else {
sender = message.user;
recipient = flagger.profile.name;
}
messageText += `: ${sender} is writing this message to ${recipient}.`;
}
flagSlack.send({
text,
attachments: [{
fallback: 'Flag Message',
color: 'danger',
author_name: authorName,
title,
title_link: titleLink,
text: messageText,
footer: `<${SLACK_FLAGGING_FOOTER_LINK}?groupId=privateMessages&chatId=${message.id}|Flag this message>`,
mrkdwn_in: [
'text',
],
}],
});
}
function sendSubscriptionNotification ({
buyer,
recipient,
@@ -150,6 +210,7 @@ function sendSlurNotification ({
module.exports = {
sendFlagNotification,
sendInboxFlagNotification,
sendSubscriptionNotification,
sendSlurNotification,
};