markdown: Reduce mentions inside blockquotes to silent-mentions.

On the backend, we extend the BlockQuoteProcessor's clean function that
just removes '>' from the start of each line to convert each mention to
have the silent mention syntax, before UserMentionPattern is invoked.

The frontend, however, has an edge case where if you are mentioned in
some message and you quote it while having mentioned yourself above
the quoted message, you wouldn't see the red highlight till we get the
final rendered message from the backend.

This is such a subtle glitch that it's likely not worth worrying about.

Fixes #8025.
This commit is contained in:
Rohitt Vashishtha
2019-01-08 10:30:13 +00:00
committed by Tim Abbott
parent 988af1c803
commit 96aa1d4b37
5 changed files with 68 additions and 6 deletions

View File

@@ -105,6 +105,20 @@ exports.apply_markdown = function (message) {
}
return;
},
silencedMentionHandler: function (quote) {
// Silence quoted mentions.
var user_mention_re = /<span.*user-mention.*data-user-id="(\d+|\*)"[^>]*>/gm;
quote = quote.replace(user_mention_re, function (match) {
return match.replace(/"user-mention"/g, '"user-mention silent"');
});
// In most cases, if you are being mentioned in the message you're quoting, you wouldn't
// mention yourself outside of the blockquote (and, above it). If that you do that, the
// following mentioned status is false; the backend rendering is authoritative and the
// only side effect is the lack red flash on immediately sending the message.
message.mentioned = false;
message.mentioned_me_directly = false;
return quote;
},
};
message.content = marked(message.raw_content + '\n\n', options).trim();
message.is_me_message = exports.is_status_message(message.raw_content, message.content);