frontend: Simplify saving collapsed/uncollapsed flags.

We now make direct calls to `send_flags_update` for
seting collapsed/uncollapsed, rather than going through
the `batched_updaters` mechanism.

Also the methods in `message_flags` to set
collapsed/uncollapsed now take a single message.
This commit is contained in:
Steve Howell 2017-12-15 17:32:36 -05:00 committed by showell
parent d52552dcc3
commit 7a362861d0
2 changed files with 16 additions and 22 deletions

View File

@ -31,7 +31,7 @@ exports.uncollapse = function (row) {
// [Condense] link if necessary.
var message = current_msg_list.get(rows.id(row));
message.collapsed = false;
message_flags.send_collapsed([message], false);
message_flags.save_uncollapsed(message.id);
var process_row = function process_row(row) {
var content = row.find(".message_content");
@ -66,7 +66,16 @@ exports.collapse = function (row) {
// [Condense] link if necessary.
var message = current_msg_list.get(rows.id(row));
message.collapsed = true;
message_flags.send_collapsed([message], true);
if (message.locally_echoed) {
// Trying to collapse a locally echoed message is
// very rare, and in our current implementation the
// server response overwrites the flag, so we just
// punt for now.
return;
}
message_flags.save_collapsed(message.id);
var process_row = function process_row(row) {
row.find(".message_content").addClass("collapsed");

View File

@ -13,8 +13,6 @@ function send_flag_update(message, flag, op) {
});
}
var batched_updaters = {};
function batched_updater(flag, op, immediate) {
var queue = [];
var on_success;
@ -85,25 +83,12 @@ function batched_updater(flag, op, immediate) {
exports.send_read = batched_updater('read', 'add');
function send_flag(messages, flag_name, set_flag) {
var op = set_flag ? 'add' : 'remove';
var flag_key = flag_name + '_' + op;
var updater;
exports.save_collapsed = function (message) {
send_flag_update(message, 'collapsed', true);
};
if (batched_updaters.hasOwnProperty(flag_key)) {
updater = batched_updaters[flag_key];
} else {
updater = batched_updater(flag_name, op, true);
batched_updaters[flag_key] = updater;
}
_.each(messages, function (message) {
updater(message);
});
}
exports.send_collapsed = function send_collapse(messages, value) {
send_flag(messages, "collapsed", value);
exports.save_uncollapsed = function (message) {
send_flag_update(message, 'collapsed', true);
};
exports.toggle_starred = function (message) {