PM sidebar: Expand PM sidebar for huddles.

This fixes a regression from here:

    88b4a9f2d7

The fix didn't account for how huddles are
represented as comma-delimited strings.

We also simplify the logic by extracting a
function and doing early-exit for simple
cases.
This commit is contained in:
Steve Howell
2018-10-20 22:04:46 +00:00
committed by Tim Abbott
parent 328e2ff316
commit c58a99b156
2 changed files with 38 additions and 8 deletions

View File

@@ -29,8 +29,15 @@ run_test('narrowing', () => {
user_id: 1,
full_name: 'Alice Smith',
};
people.add(alice);
const bob = {
email: 'bob@example.com',
user_id: 2,
full_name: 'Bob Patel',
};
people.add_in_realm(alice);
people.add_in_realm(bob);
pm_expanded = false;
filter = new Filter([
{operator: 'pm-with', operand: 'alice@example.com'},
@@ -38,6 +45,13 @@ run_test('narrowing', () => {
top_left_corner.handle_narrow_activated(filter);
assert(pm_expanded);
pm_expanded = false;
filter = new Filter([
{operator: 'pm-with', operand: 'bob@example.com,alice@example.com'},
]);
top_left_corner.handle_narrow_activated(filter);
assert(pm_expanded);
pm_expanded = false;
filter = new Filter([
{operator: 'pm-with', operand: 'not@valid.com'},

View File

@@ -73,19 +73,35 @@ exports.handle_narrow_activated = function (filter) {
}
}
var op_is = filter.operands('is');
var op_pm = filter.operands('pm-with');
if (op_is.length >= 1 && _.contains(op_is, "private") || op_pm.length >= 1) {
if (!people.is_valid_bulk_emails_for_compose(op_pm)) {
// Don't go into the else statement and close the pm_list.
return;
}
if (exports.should_expand_pm_list(filter)) {
var op_pm = filter.operands('pm-with');
pm_list.expand(op_pm);
} else {
pm_list.close();
}
};
exports.should_expand_pm_list = function (filter) {
var op_is = filter.operands('is');
if (op_is.length >= 1 && _.contains(op_is, "private")) {
return true;
}
var op_pm = filter.operands('pm-with');
if (op_pm.length !== 1) {
return false;
}
var emails_strings = op_pm[0];
var emails = emails_strings.split(',');
var has_valid_emails = people.is_valid_bulk_emails_for_compose(emails);
return has_valid_emails;
};
exports.handle_narrow_deactivated = function () {
deselect_top_left_corner_items();
pm_list.close();