mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
markdown: Remove redundant checks from /me.
If a message begins with /me, we do not have any cases where the rendered content would not begin with `<p>/me`. Thus, we can safely remove the redundant checks both on the backend and frontend.
This commit is contained in:
committed by
Tim Abbott
parent
3df18c365d
commit
85c669e366
@@ -1503,10 +1503,9 @@ run_test('on_events', () => {
|
||||
};
|
||||
}
|
||||
|
||||
function setup_mock_markdown_is_status_message(msg_content, msg_rendered, return_val) {
|
||||
markdown.is_status_message = function (content, rendered) {
|
||||
function setup_mock_markdown_is_status_message(msg_content, return_val) {
|
||||
markdown.is_status_message = function (content) {
|
||||
assert.equal(content, msg_content);
|
||||
assert.equal(rendered, msg_rendered);
|
||||
return return_val;
|
||||
};
|
||||
}
|
||||
@@ -1572,7 +1571,7 @@ run_test('on_events', () => {
|
||||
$("#compose-textarea").val('```foobarfoobar```');
|
||||
setup_visibilities();
|
||||
setup_mock_markdown_contains_backend_only_syntax('```foobarfoobar```', true);
|
||||
setup_mock_markdown_is_status_message('```foobarfoobar```', 'Server: foobarfoobar', false);
|
||||
setup_mock_markdown_is_status_message('```foobarfoobar```', false);
|
||||
loading.make_indicator = function (spinner) {
|
||||
assert.equal(spinner.selector, "#markdown_preview_spinner");
|
||||
make_indicator_called = true;
|
||||
@@ -1588,7 +1587,7 @@ run_test('on_events', () => {
|
||||
$("#compose-textarea").val('foobarfoobar');
|
||||
setup_visibilities();
|
||||
setup_mock_markdown_contains_backend_only_syntax('foobarfoobar', false);
|
||||
setup_mock_markdown_is_status_message('foobarfoobar', 'Server: foobarfoobar', false);
|
||||
setup_mock_markdown_is_status_message('foobarfoobar', false);
|
||||
mock_channel_post('foobarfoobar');
|
||||
markdown.apply_markdown = function (msg) {
|
||||
assert.equal(msg.raw_content, 'foobarfoobar');
|
||||
|
||||
@@ -729,7 +729,7 @@ exports.render_and_show_preview = function (preview_spinner, preview_content_box
|
||||
// and will be undefined in case of errors
|
||||
let rendered_preview_html;
|
||||
if (raw_content !== undefined &&
|
||||
markdown.is_status_message(raw_content, rendered_content)) {
|
||||
markdown.is_status_message(raw_content)) {
|
||||
// Handle previews of /me messages
|
||||
rendered_preview_html = "<p><strong>" + page_params.full_name + "</strong>" + rendered_content.slice("<p>/me".length);
|
||||
} else {
|
||||
|
||||
@@ -129,7 +129,7 @@ exports.apply_markdown = function (message) {
|
||||
};
|
||||
// Our python-markdown processor appends two \n\n to input
|
||||
message.content = marked(message.raw_content + '\n\n', options).trim();
|
||||
message.is_me_message = exports.is_status_message(message.raw_content, message.content);
|
||||
message.is_me_message = exports.is_status_message(message.raw_content);
|
||||
};
|
||||
|
||||
exports.add_topic_links = function (message) {
|
||||
@@ -168,10 +168,8 @@ exports.add_topic_links = function (message) {
|
||||
util.set_topic_links(message, links);
|
||||
};
|
||||
|
||||
exports.is_status_message = function (raw_content, content) {
|
||||
return raw_content.indexOf('/me ') === 0 &&
|
||||
content.indexOf('<p>') === 0 &&
|
||||
content.indexOf('</p>') !== -1;
|
||||
exports.is_status_message = function (raw_content) {
|
||||
return raw_content.indexOf('/me ') === 0;
|
||||
};
|
||||
|
||||
function make_emoji_span(codepoint, title, alt_text) {
|
||||
|
||||
@@ -1723,10 +1723,10 @@ class Message(AbstractMessage):
|
||||
@staticmethod
|
||||
def is_status_message(content: str, rendered_content: str) -> bool:
|
||||
"""
|
||||
Returns True if content and rendered_content are from 'me_message'
|
||||
"status messages" start with /me and have special rendering:
|
||||
/me loves chocolate -> Full Name loves chocolate
|
||||
"""
|
||||
if content.startswith('/me '):
|
||||
if rendered_content.startswith('<p>') and '</p>' in rendered_content:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -1020,11 +1020,6 @@ class BugdownTest(ZulipTestCase):
|
||||
)
|
||||
self.assertTrue(Message.is_status_message(content, rendered_content))
|
||||
|
||||
# Add an artificial test to fail the check:
|
||||
content = '/me takes a walk'
|
||||
rendered_content = '<h1>/me takes a walk</h1>'
|
||||
self.assertFalse(Message.is_status_message(content, rendered_content))
|
||||
|
||||
def test_alert_words(self) -> None:
|
||||
user_profile = self.example_user('othello')
|
||||
do_set_alert_words(user_profile, ["ALERTWORD", "scaryword"])
|
||||
|
||||
Reference in New Issue
Block a user