From ff44fb6fcfc795c0ac388be4122673bd446d26a6 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 11 Mar 2014 09:07:23 -0400 Subject: [PATCH] For topic changes, set the compose subject outside the loop. If we get a topic change, we can change the subject outside the loop, since we are passed in event.orig_subject. Doing it inside the loop was mostly harmless, since after you encountered the first message with the old topic, the condition to change the subject evaluated to false, but it was still technically O(N), and it was kind of confusing. This commit changes behavior in the edge case that you have the compose box open for a changing subject, but you are in a narrow that does not have any of the affected messages. After this commit, the topic in the compose box will still change, which I believe is the correct behavior. (imported from commit 2363e432ebe7ae8e07379324ee0bfb52051428e6) --- static/js/message_store.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/static/js/message_store.js b/static/js/message_store.js index e60b168f87..175b0b9dfe 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -239,16 +239,17 @@ exports.update_messages = function update_messages(events) { // event.message_ids. event.message_id is still the first message // where the user initiated the edit. topic_edited = true; + + if (event.orig_subject === compose.subject()) { + compose.subject(event.subject); + } + _.each(event.message_ids, function (id) { var msg = message_store.get(id); if (msg === undefined) { return; } - if (msg.subject === compose.subject()) { - compose.subject(event.subject); - } - // Remove the recent subjects entry for the old subject; // must be called before we update msg.subject exports.process_message_for_recent_subjects(msg, true);