pm_list: Handle narrow functions separately for pm_section.

This commit is a preparatory commit which introduces
`handle_narrow_deactivated` and `handle_narrow_activated`
functions in pm_list.js, separately from top_left_corner.js,
to reduce the complexity of handling private messages section
separately.
This commit is contained in:
jai2201
2022-05-02 11:08:15 +05:30
committed by Tim Abbott
parent 45c53d217e
commit 46b289cbda
4 changed files with 43 additions and 34 deletions

View File

@@ -30,7 +30,7 @@ run_test("narrowing", ({override}) => {
assert.ok(!pm_expanded); assert.ok(!pm_expanded);
let filter = new Filter([{operator: "is", operand: "private"}]); 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); assert.ok(pm_expanded);
const alice = { const alice = {
@@ -49,23 +49,23 @@ run_test("narrowing", ({override}) => {
pm_expanded = false; pm_expanded = false;
filter = new Filter([{operator: "pm-with", operand: "alice@example.com"}]); filter = new Filter([{operator: "pm-with", operand: "alice@example.com"}]);
top_left_corner.handle_narrow_activated(filter); pm_list.handle_narrow_activated(filter);
assert.ok(pm_expanded); assert.ok(pm_expanded);
pm_expanded = false; pm_expanded = false;
filter = new Filter([{operator: "pm-with", operand: "bob@example.com,alice@example.com"}]); filter = new Filter([{operator: "pm-with", operand: "bob@example.com,alice@example.com"}]);
top_left_corner.handle_narrow_activated(filter); pm_list.handle_narrow_activated(filter);
assert.ok(pm_expanded); assert.ok(pm_expanded);
pm_expanded = false; pm_expanded = false;
filter = new Filter([{operator: "pm-with", operand: "not@valid.com"}]); filter = new Filter([{operator: "pm-with", operand: "not@valid.com"}]);
top_left_corner.handle_narrow_activated(filter); pm_list.handle_narrow_activated(filter);
assert.ok(!pm_expanded); assert.ok(!pm_expanded);
pm_expanded = false; pm_expanded = false;
people.deactivate(alice); people.deactivate(alice);
filter = new Filter([{operator: "pm-with", operand: "alice@example.com"}]); filter = new Filter([{operator: "pm-with", operand: "alice@example.com"}]);
top_left_corner.handle_narrow_activated(filter); pm_list.handle_narrow_activated(filter);
assert.ok(pm_expanded); assert.ok(pm_expanded);
filter = new Filter([{operator: "is", operand: "mentioned"}]); filter = new Filter([{operator: "is", operand: "mentioned"}]);
@@ -84,6 +84,7 @@ run_test("narrowing", ({override}) => {
pm_closed = false; pm_closed = false;
top_left_corner.handle_narrow_deactivated(); top_left_corner.handle_narrow_deactivated();
pm_list.handle_narrow_deactivated();
assert.ok($(".top_left_all_messages").hasClass("active-filter")); assert.ok($(".top_left_all_messages").hasClass("active-filter"));
assert.ok(!$(".top_left_mentions").hasClass("active-filter")); assert.ok(!$(".top_left_mentions").hasClass("active-filter"));

View File

@@ -25,6 +25,7 @@ import * as narrow_state from "./narrow_state";
import * as notifications from "./notifications"; import * as notifications from "./notifications";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; 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_ui from "./recent_topics_ui";
import * as recent_topics_util from "./recent_topics_util"; import * as recent_topics_util from "./recent_topics_util";
import * as resize from "./resize"; import * as resize from "./resize";
@@ -570,6 +571,7 @@ export function activate(raw_operators, opts) {
const current_filter = narrow_state.filter(); const current_filter = narrow_state.filter();
top_left_corner.handle_narrow_activated(current_filter); top_left_corner.handle_narrow_activated(current_filter);
pm_list.handle_narrow_activated(current_filter);
stream_list.handle_narrow_activated(current_filter); stream_list.handle_narrow_activated(current_filter);
typing_events.render_notifications_for_narrow(); typing_events.render_notifications_for_narrow();
message_view_header.initialize(); message_view_header.initialize();
@@ -980,6 +982,7 @@ function handle_post_narrow_deactivate_processes() {
} }
top_left_corner.handle_narrow_deactivated(); top_left_corner.handle_narrow_deactivated();
pm_list.handle_narrow_deactivated();
stream_list.handle_narrow_deactivated(); stream_list.handle_narrow_deactivated();
compose_closed_ui.update_buttons_for_stream(); compose_closed_ui.update_buttons_for_stream();
message_edit.handle_narrow_deactivated(); message_edit.handle_narrow_deactivated();

View File

@@ -1,6 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import * as narrow_state from "./narrow_state"; 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_data from "./pm_list_data";
import * as pm_list_dom from "./pm_list_dom"; import * as pm_list_dom from "./pm_list_dom";
import * as stream_popover from "./stream_popover"; import * as stream_popover from "./stream_popover";
@@ -74,3 +75,36 @@ export function update_dom_with_unread_counts(counts) {
update_private_messages(); update_private_messages();
set_count(counts.private_message_count); 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();
}

View File

@@ -1,6 +1,5 @@
import $ from "jquery"; import $ from "jquery";
import * as people from "./people";
import * as pm_list from "./pm_list"; import * as pm_list from "./pm_list";
import * as resize from "./resize"; import * as resize from "./resize";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
@@ -36,27 +35,6 @@ function deselect_top_left_corner_items() {
remove($(".top_left_recent_topics")); 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) { export function handle_narrow_activated(filter) {
deselect_top_left_corner_items(); deselect_top_left_corner_items();
@@ -84,17 +62,10 @@ export function handle_narrow_activated(filter) {
$filter_li.addClass("active-filter"); $filter_li.addClass("active-filter");
} }
} }
if (should_expand_pm_list(filter)) {
pm_list.expand();
} else {
pm_list.close();
}
} }
export function handle_narrow_deactivated() { export function handle_narrow_deactivated() {
deselect_top_left_corner_items(); deselect_top_left_corner_items();
pm_list.close();
const $filter_li = $(".top_left_all_messages"); const $filter_li = $(".top_left_all_messages");
$filter_li.addClass("active-filter"); $filter_li.addClass("active-filter");