markdown: Move code related to @mentions to markdown.js.

For consistency, we should keep all the code that works with
@mentions in markdown.js. In this case, message_list_view was
rewriting the contents of the mentions in cases where users'
names had been changed since we rendered their mention.
This commit is contained in:
Rohitt Vashishtha
2019-02-15 22:24:26 +00:00
committed by Tim Abbott
parent 44ec83ef28
commit 92658d2ac9
3 changed files with 19 additions and 5 deletions

View File

@@ -542,3 +542,12 @@ run_test('katex_throws_unexpected_exceptions', () => {
assert(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
});
run_test('misc_helpers', () => {
const elem = $('.user-mention');
markdown.set_name_in_mention_element(elem, 'Aaron');
assert.equal(elem.text(), '@Aaron');
elem.addClass('silent');
markdown.set_name_in_mention_element(elem, 'Aaron, but silent');
assert.equal(elem.text(), 'Aaron, but silent');
});

View File

@@ -36,6 +36,15 @@ var backend_only_markdown_re = [
/[^\s]*(?:twitter|youtube).com\/[^\s]*/,
];
// Helper function to update a mentioned user's name.
exports.set_name_in_mention_element = function (element, name) {
if ($(element).hasClass('silent')) {
$(element).text(name);
} else {
$(element).text("@" + name);
}
};
exports.contains_backend_only_syntax = function (content) {
// Try to guess whether or not a message has bugdown in it
// If it doesn't, we can immediately render it client-side

View File

@@ -525,11 +525,7 @@ MessageListView.prototype = {
if (person !== undefined) {
// Note that person might be undefined in some
// unpleasant corner cases involving data import.
if ($(this).hasClass('silent')) {
$(this).text(person.full_name);
} else {
$(this).text("@" + person.full_name);
}
markdown.set_name_in_mention_element(this, person.full_name);
}
}
});