mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix: Account for system messages in flag slack alert
This commit is contained in:
@@ -97,6 +97,23 @@ describe('slack', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('provides name for system message', () => {
|
||||||
|
message.uuid = 'system';
|
||||||
|
delete message.user;
|
||||||
|
|
||||||
|
slack.sendFlagNotification({
|
||||||
|
flagger,
|
||||||
|
group,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({
|
||||||
|
attachments: [sandbox.match({
|
||||||
|
author_name: 'System Message',
|
||||||
|
})],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('noops if no flagging url is provided', () => {
|
it('noops if no flagging url is provided', () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('SLACK:FLAGGING_URL').returns('');
|
sandbox.stub(nconf, 'get').withArgs('SLACK:FLAGGING_URL').returns('');
|
||||||
sandbox.stub(logger, 'error');
|
sandbox.stub(logger, 'error');
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ function sendFlagNotification ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let titleLink;
|
let titleLink;
|
||||||
|
let authorName;
|
||||||
let title = `Flag in ${group.name}`;
|
let title = `Flag in ${group.name}`;
|
||||||
let text = `${flagger.profile.name} (${flagger.id}) flagged a message`;
|
let text = `${flagger.profile.name} (${flagger.id}) flagged a message`;
|
||||||
|
|
||||||
@@ -36,12 +37,18 @@ function sendFlagNotification ({
|
|||||||
title += ` - (${group.privacy} ${group.type})`;
|
title += ` - (${group.privacy} ${group.type})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!message.user && message.uuid === 'system') {
|
||||||
|
authorName = 'System Message';
|
||||||
|
} else {
|
||||||
|
authorName = `${message.user} - ${message.uuid}`;
|
||||||
|
}
|
||||||
|
|
||||||
flagSlack.send({
|
flagSlack.send({
|
||||||
text,
|
text,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
fallback: 'Flag Message',
|
fallback: 'Flag Message',
|
||||||
color: 'danger',
|
color: 'danger',
|
||||||
author_name: `${message.user} - ${message.uuid}`,
|
author_name: authorName,
|
||||||
title,
|
title,
|
||||||
title_link: titleLink,
|
title_link: titleLink,
|
||||||
text: message.text,
|
text: message.text,
|
||||||
|
|||||||
Reference in New Issue
Block a user