refactor: Extract is_all_privates().

I want to be able to easily test this without
having to simulate all the jQuery side effects.

This simply preserves the old logic, which seems
to handle one edge case without handling every
possible edge case.  The edge cases aren't super
important here, though, since the only thing it affects
is bolding "Private Messages", and when to do that
is somewhat up to personal tastes.

Having said that, we could definitely improve
this code and possibly should move some of this
logic to either narrow_state.js or filter.js.
This commit is contained in:
Steve Howell
2020-01-06 15:18:20 +00:00
committed by Tim Abbott
parent 5b168d0530
commit c22c796f1d
2 changed files with 54 additions and 14 deletions

View File

@@ -135,27 +135,31 @@ exports.rebuild_recent = function () {
resize.resize_stream_filters_container();
};
exports.is_all_privates = function () {
const filter = narrow_state.filter();
if (!filter) {
return false;
}
// Handle the edge case that somebody said pm-with:alice is:private.
// This should basically be treated like pm-with:alice.
const conversation = filter.operands('pm-with');
if (conversation.length !== 0) {
return false;
}
return _.contains(filter.operands('is'), "private");
};
exports.update_private_messages = function () {
if (!narrow_state.active()) {
return;
}
let is_pm_filter = false;
const filter = narrow_state.filter();
if (filter) {
const conversation = filter.operands('pm-with');
if (conversation.length === 0) {
is_pm_filter = _.contains(filter.operands('is'), "private");
}
// We don't support having two pm-with: operands in a search
// (Group PMs are represented as a single pm-with operand
// containing a list).
}
exports.rebuild_recent();
if (is_pm_filter) {
if (exports.is_all_privates()) {
$(".top_left_private_messages").addClass('active-filter');
}
};