From 0820ab591aa93e29140dca6088dbff9dbf6e94be Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Tue, 31 May 2016 14:24:58 +0200 Subject: [PATCH] Refresh page when message with /me is edited. Fixes: #163. Thanks to Catherine Nguyen (@cnguye11) for her work on this. --- frontend_tests/casper_tests/09-edit.js | 24 ++++++++++++++++++++++++ static/js/message_list_view.js | 22 +++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/frontend_tests/casper_tests/09-edit.js b/frontend_tests/casper_tests/09-edit.js index 818e8954fa..ee8898655d 100644 --- a/frontend_tests/casper_tests/09-edit.js +++ b/frontend_tests/casper_tests/09-edit.js @@ -47,6 +47,30 @@ casper.waitForSelector(".message_edit_notice", function () { casper.test.assertSelectorHasText(".last_message .message_content", "test edited"); }); +common.then_send_message('stream', { + stream: 'Verona', + subject: 'edits', + content: '/me test editing one line with me' +}); + +casper.waitForText("test editing one line with me"); +wait_for_message_actually_sent(); + +then_edit_last_message(); + +casper.then(function () { + casper.evaluate(function () { + var msg = $('#zhome .message_row:last'); + msg.find('.message_edit_topic').val("edited"); + msg.find('.message_edit_content').val("/me test edited one line with me"); + msg.find('.message_edit_save').click(); + }); +}); + +casper.waitForSelector(".message_edit_notice", function () { + casper.test.assertSelectorHasText(".last_message .sender-status", "test edited one line with me"); +}); + common.then_send_message('private', { recipient: "cordelia@zulip.com", content: "test editing pm" diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 0902e9ca77..1a759656c8 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -196,15 +196,7 @@ MessageListView.prototype = { message_container.contains_mention = notifications.speaking_at_me(message_container.msg); message_container.msg.unread = unread.message_unread(message_container.msg); - - if (message_container.msg.is_me_message) { - // Slice the '

/me ' off the front, and '

' off the end - message_container.status_message = message_container.msg.content.slice(4 + 3, -4); - message_container.include_sender = true; - } - else { - message_container.status_message = false; - } + self._maybe_format_me_message(message_container); prev = message_container; }); @@ -752,6 +744,7 @@ MessageListView.prototype = { // Re-render just this one message this._add_msg_timestring(message_container); + this._maybe_format_me_message(message_container); var msg_to_render = _.extend(message_container, {table_name: this.table_name}); var rendered_msg = $(templates.render('single_message', msg_to_render)); @@ -893,6 +886,17 @@ MessageListView.prototype = { this.message_containers[new_id] = message_container; } + }, + + _maybe_format_me_message: function MessageListView__maybe_format_me_message(message_container) { + if (message_container.msg.is_me_message) { + // Slice the '

/me ' off the front, and '

' off the end + message_container.status_message = message_container.msg.content.slice(4 + 3, -4); + message_container.include_sender = true; + } + else { + message_container.status_message = false; + } } };