Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
pm_list: Handle narrow functions separately for pm_section.
jai220146b289cbda53
diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.jsindex e6282fead6a..09e7042cb38 100644--- a/frontend_tests/node_tests/top_left_corner.js+++ b/frontend_tests/node_tests/top_left_corner.js@@ -30,7 +30,7 @@ run_test("narrowing", ({override}) => {assert.ok(!pm_expanded);let filter = new Filter([{operator: "is", operand: "private"}]);- top_left_corner.handle_narrow_activated(filter);+ pm_list.handle_narrow_activated(filter);assert.ok(pm_expanded);const alice = {@@ -49,23 +49,23 @@ run_test("narrowing", ({override}) => {pm_expanded = false;filter = new Filter([{operator: "pm-with", operand: "[email protected]"}]);- top_left_corner.handle_narrow_activated(filter);+ pm_list.handle_narrow_activated(filter);assert.ok(pm_expanded);pm_expanded = false;filter = new Filter([{operator: "pm-with", operand: "[email protected],[email protected]"}]);- top_left_corner.handle_narrow_activated(filter);+ pm_list.handle_narrow_activated(filter);assert.ok(pm_expanded);pm_expanded = false;filter = new Filter([{operator: "pm-with", operand: "[email protected]"}]);- top_left_corner.handle_narrow_activated(filter);+ pm_list.handle_narrow_activated(filter);assert.ok(!pm_expanded);pm_expanded = false;people.deactivate(alice);filter = new Filter([{operator: "pm-with", operand: "[email protected]"}]);- top_left_corner.handle_narrow_activated(filter);+ pm_list.handle_narrow_activated(filter);assert.ok(pm_expanded);filter = new Filter([{operator: "is", operand: "mentioned"}]);@@ -84,6 +84,7 @@ run_test("narrowing", ({override}) => {pm_closed = false;top_left_corner.handle_narrow_deactivated();+ pm_list.handle_narrow_deactivated();assert.ok($(".top_left_all_messages").hasClass("active-filter"));assert.ok(!$(".top_left_mentions").hasClass("active-filter"));diff --git a/static/js/narrow.js b/static/js/narrow.jsindex f05409311ff..9e956022c92 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -25,6 +25,7 @@ import * as narrow_state from "./narrow_state";import * as notifications from "./notifications";import {page_params} from "./page_params";import * as people from "./people";+import * as pm_list from "./pm_list";import * as recent_topics_ui from "./recent_topics_ui";import * as recent_topics_util from "./recent_topics_util";import * as resize from "./resize";@@ -570,6 +571,7 @@ export function activate(raw_operators, opts) {const current_filter = narrow_state.filter();top_left_corner.handle_narrow_activated(current_filter);+ pm_list.handle_narrow_activated(current_filter);stream_list.handle_narrow_activated(current_filter);typing_events.render_notifications_for_narrow();message_view_header.initialize();@@ -980,6 +982,7 @@ function handle_post_narrow_deactivate_processes() {}top_left_corner.handle_narrow_deactivated();+ pm_list.handle_narrow_deactivated();stream_list.handle_narrow_deactivated();compose_closed_ui.update_buttons_for_stream();message_edit.handle_narrow_deactivated();diff --git a/static/js/pm_list.js b/static/js/pm_list.jsindex 038cefce485..7eb6ce49420 100644--- a/static/js/pm_list.js+++ b/static/js/pm_list.js@@ -1,6 +1,7 @@import $ from "jquery";import * as narrow_state from "./narrow_state";+import * as people from "./people";import * as pm_list_data from "./pm_list_data";import * as pm_list_dom from "./pm_list_dom";import * as stream_popover from "./stream_popover";@@ -74,3 +75,36 @@ export function update_dom_with_unread_counts(counts) {update_private_messages();set_count(counts.private_message_count);}++function should_expand_pm_list(filter) {+ const op_is = filter.operands("is");++ if (op_is.length >= 1 && op_is.includes("private")) {+ return true;+ }++ const op_pm = filter.operands("pm-with");++ if (op_pm.length !== 1) {+ return false;+ }++ const emails_strings = op_pm[0];+ const emails = emails_strings.split(",");++ const has_valid_emails = people.is_valid_bulk_emails_for_compose(emails);++ return has_valid_emails;+}++export function handle_narrow_activated(filter) {+ if (should_expand_pm_list(filter)) {+ expand();+ } else {+ close();+ }+}++export function handle_narrow_deactivated() {+ close();+}diff --git a/static/js/top_left_corner.js b/static/js/top_left_corner.jsindex d9504665268..fa4731ff49b 100644--- a/static/js/top_left_corner.js+++ b/static/js/top_left_corner.js@@ -1,6 +1,5 @@import $ from "jquery";-import * as people from "./people";import * as pm_list from "./pm_list";import * as resize from "./resize";import * as ui_util from "./ui_util";@@ -36,27 +35,6 @@ function deselect_top_left_corner_items() {remove($(".top_left_recent_topics"));}-function should_expand_pm_list(filter) {- const op_is = filter.operands("is");-- if (op_is.length >= 1 && op_is.includes("private")) {- return true;- }-- const op_pm = filter.operands("pm-with");-- if (op_pm.length !== 1) {- return false;- }-- const emails_strings = op_pm[0];- const emails = emails_strings.split(",");-- const has_valid_emails = people.is_valid_bulk_emails_for_compose(emails);-- return has_valid_emails;-}-export function handle_narrow_activated(filter) {deselect_top_left_corner_items();@@ -84,17 +62,10 @@ export function handle_narrow_activated(filter) {$filter_li.addClass("active-filter");}}-- if (should_expand_pm_list(filter)) {- pm_list.expand();- } else {- pm_list.close();- }}export function handle_narrow_deactivated() {deselect_top_left_corner_items();- pm_list.close();const $filter_li = $(".top_left_all_messages");$filter_li.addClass("active-filter");