editing: Fix live update of ability to edit messages.

Previously, we didn't check the organization-level settings when
rendering a message list; instead, we only checked it when putting
messages into the message_store.  That resulted in the state being
stale in the event that the setting controlling whether one can edit
messages was changed.

We remove some node tests, because revidving the node test for their
new home in message_list_view would be more work than we probably want
to do with an upcoming release.  We basically need to be better about
exporting functions like populate_group_from_message_container and
set_topic_edit_properties, so we can do fine grained testing.

When we get around to the node tests, rather than exporting these
functions, it might make sense to create a new module with a name
like message_container.js, which would have all of these
last-second type of data manipulations on message objects.  This
would be nice to split out of message_list_view.js.  MLV is our
biggest module, and it's mostly cohesive, but it's real job
should be about assembling messages into a DOM list, which is
probably 80% of the code now.  The 20% that I'd want to consider
splitting out is actually closer in spirit to message_store.js.

Thanks to Steve Howell for helping with the node tests.
This commit is contained in:
Tim Abbott
2017-08-22 19:41:43 -07:00
parent cf4444123a
commit 74c628b105
4 changed files with 18 additions and 50 deletions

View File

@@ -136,41 +136,12 @@ var message_store = require('js/message_store.js');
assert.equal(message.subject, typeahead_added.subject);
});
assert.equal(message.always_visible_topic_edit, true);
assert.equal(message.on_hover_topic_edit, false);
assert.deepEqual(message.stream, [me, cindy]);
assert.equal(message.reply_to, 'me@example.com');
assert.deepEqual(message.flags, []);
assert.equal(message.alerted, false);
override('compose.empty_topic_placeholder', function () {
return 'not_the_subject';
});
message = {
sender_id: me.user_id,
type: 'stream',
id: 2069,
display_recipient: [me],
sender_email: 'me@example.org',
};
message_store.add_message_metadata(message);
assert.equal(message.always_visible_topic_edit, false);
assert.equal(message.on_hover_topic_edit, true);
});
page_params.realm_allow_message_editing = false;
message = {
sender_id: me.user_id,
type: 'stream',
id: 2070,
display_recipient: [me],
sender_email: 'me@example.org',
};
message_store.add_message_metadata(message);
assert.equal(message.always_visible_topic_edit, false);
assert.equal(message.on_hover_topic_edit, false);
}());
(function test_errors() {

View File

@@ -197,7 +197,6 @@ exports.update_messages = function update_messages(events) {
msg.subject = event.subject;
msg.subject_links = event.subject_links;
message_store.set_topic_edit_properties(msg);
// Add the recent topics entry for the new topics; must
// be called after we update msg.subject

View File

@@ -85,6 +85,22 @@ function add_display_time(group, message_container, prev) {
}
}
function set_topic_edit_properties(group, message) {
group.always_visible_topic_edit = false;
group.on_hover_topic_edit = false;
if (!page_params.realm_allow_message_editing) {
return;
}
// Messages with no topics should always have an edit icon visible
// to encourage updating them. Admins can also edit any topic.
if (message.subject === compose.empty_topic_placeholder()) {
group.always_visible_topic_edit = true;
} else if (page_params.is_admin) {
group.on_hover_topic_edit = true;
}
}
function populate_group_from_message_container(group, message_container) {
group.is_stream = message_container.msg.is_stream;
group.is_private = message_container.msg.is_private;
@@ -112,10 +128,10 @@ function populate_group_from_message_container(group, message_container) {
group.display_reply_to = message_store.get_pm_full_names(message_container.msg);
}
group.display_recipient = message_container.msg.display_recipient;
group.always_visible_topic_edit = message_container.msg.always_visible_topic_edit;
group.on_hover_topic_edit = message_container.msg.on_hover_topic_edit;
group.subject_links = message_container.msg.subject_links;
set_topic_edit_properties(group, message_container.msg);
var time = new XDate(message_container.msg.timestamp * 1000);
var today = new XDate();
var date_element = timerender.render_date(time, undefined, today)[0];

View File

@@ -90,22 +90,6 @@ exports.insert_recent_private_message = (function () {
};
}());
exports.set_topic_edit_properties = function (message) {
message.always_visible_topic_edit = false;
message.on_hover_topic_edit = false;
if (!page_params.realm_allow_message_editing) {
return;
}
// Messages with no topics should always have an edit icon visible
// to encourage updating them. Admins can also edit any topic.
if (message.subject === compose.empty_topic_placeholder()) {
message.always_visible_topic_edit = true;
} else if (page_params.is_admin) {
message.on_hover_topic_edit = true;
}
};
exports.set_message_booleans = function (message, flags) {
function convert_flag(flag_name) {
return flags.indexOf(flag_name) >= 0;
@@ -160,8 +144,6 @@ exports.add_message_metadata = function (message) {
message_id: message.id,
});
exports.set_topic_edit_properties(message);
recent_senders.process_message_for_senders(message);
break;