From 8deac44a548b2dac2df4be25cb31fc3a02a869f4 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 15 Feb 2020 15:51:37 +0000 Subject: [PATCH] markdown: Use early-exit code style for mentions. --- static/js/markdown.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/static/js/markdown.js b/static/js/markdown.js index 8b82717b42..291fad79eb 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -115,20 +115,29 @@ exports.apply_markdown = function (message) { } } - if (person !== undefined) { - if (people.my_current_user_id() === person.user_id && !silently) { - message.mentioned = true; - message.mentioned_me_directly = true; - } - let str = ''; - if (silently) { - str += ''; - } else { - str += '@'; - } - return str + _.escape(person.full_name) + ''; + if (!person) { + // This is nothing to be concerned about--the users + // are allowed to hand-type mentions and they may + // have had a typo in the name. + return; } - return; + + // HAPPY PATH! Note that we not only need to return the + // appropriate HTML snippet here; we also want to update + // flags on the message itself that get used by the message + // view code and possibly our filtering code. + + if (people.my_current_user_id() === person.user_id && !silently) { + message.mentioned = true; + message.mentioned_me_directly = true; + } + let str = ''; + if (silently) { + str += ''; + } else { + str += '@'; + } + return str + _.escape(person.full_name) + ''; }, groupMentionHandler: function (name) { const group = user_groups.get_user_group_from_name(name);