mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
pm list: Extract pm_list_data module.
This sets the stage to remove some node test mocking. This is a pure code move, and we change _get_convos to get_convos.
This commit is contained in:
@@ -28,6 +28,7 @@ mock_esm("../../static/js/user_status", {
|
|||||||
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const pm_conversations = zrequire("pm_conversations");
|
const pm_conversations = zrequire("pm_conversations");
|
||||||
|
const pm_list_data = zrequire("pm_list_data");
|
||||||
const pm_list = zrequire("pm_list");
|
const pm_list = zrequire("pm_list");
|
||||||
|
|
||||||
const alice = {
|
const alice = {
|
||||||
@@ -206,7 +207,7 @@ test("get_active_user_ids_string", ({override}) => {
|
|||||||
|
|
||||||
override(narrow_state, "filter", () => active_filter);
|
override(narrow_state, "filter", () => active_filter);
|
||||||
|
|
||||||
assert.equal(pm_list.get_active_user_ids_string(), undefined);
|
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
||||||
|
|
||||||
function set_filter_result(emails) {
|
function set_filter_result(emails) {
|
||||||
active_filter = {
|
active_filter = {
|
||||||
@@ -218,10 +219,10 @@ test("get_active_user_ids_string", ({override}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_filter_result([]);
|
set_filter_result([]);
|
||||||
assert.equal(pm_list.get_active_user_ids_string(), undefined);
|
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
||||||
|
|
||||||
set_filter_result(["bob@zulip.com,alice@zulip.com"]);
|
set_filter_result(["bob@zulip.com,alice@zulip.com"]);
|
||||||
assert.equal(pm_list.get_active_user_ids_string(), "101,102");
|
assert.equal(pm_list_data.get_active_user_ids_string(), "101,102");
|
||||||
});
|
});
|
||||||
|
|
||||||
function private_filter() {
|
function private_filter() {
|
||||||
@@ -238,10 +239,10 @@ test("is_all_privates", ({override}) => {
|
|||||||
override(narrow_state, "filter", () => filter);
|
override(narrow_state, "filter", () => filter);
|
||||||
|
|
||||||
filter = undefined;
|
filter = undefined;
|
||||||
assert.equal(pm_list.is_all_privates(), false);
|
assert.equal(pm_list_data.is_all_privates(), false);
|
||||||
|
|
||||||
filter = private_filter();
|
filter = private_filter();
|
||||||
assert.equal(pm_list.is_all_privates(), true);
|
assert.equal(pm_list_data.is_all_privates(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("expand", ({override, override_rewire}) => {
|
test("expand", ({override, override_rewire}) => {
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
import * as buddy_data from "./buddy_data";
|
|
||||||
import * as hash_util from "./hash_util";
|
|
||||||
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_conversations from "./pm_conversations";
|
|
||||||
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";
|
||||||
import * as ui from "./ui";
|
import * as ui from "./ui";
|
||||||
import * as ui_util from "./ui_util";
|
import * as ui_util from "./ui_util";
|
||||||
import * as unread from "./unread";
|
|
||||||
import * as user_status from "./user_status";
|
|
||||||
import * as vdom from "./vdom";
|
import * as vdom from "./vdom";
|
||||||
|
|
||||||
let prior_dom;
|
let prior_dom;
|
||||||
@@ -43,73 +38,8 @@ export function close() {
|
|||||||
remove_expanded_private_messages();
|
remove_expanded_private_messages();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_active_user_ids_string() {
|
|
||||||
const filter = narrow_state.filter();
|
|
||||||
|
|
||||||
if (!filter) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emails = filter.operands("pm-with")[0];
|
|
||||||
|
|
||||||
if (!emails) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return people.emails_strings_to_user_ids_string(emails);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function _get_convos() {
|
|
||||||
const private_messages = pm_conversations.recent.get();
|
|
||||||
const display_messages = [];
|
|
||||||
const active_user_ids_string = get_active_user_ids_string();
|
|
||||||
|
|
||||||
for (const private_message_obj of private_messages) {
|
|
||||||
const user_ids_string = private_message_obj.user_ids_string;
|
|
||||||
const reply_to = people.user_ids_string_to_emails_string(user_ids_string);
|
|
||||||
const recipients_string = people.get_recipients(user_ids_string);
|
|
||||||
|
|
||||||
const num_unread = unread.num_unread_for_person(user_ids_string);
|
|
||||||
|
|
||||||
const is_group = user_ids_string.includes(",");
|
|
||||||
|
|
||||||
const is_active = user_ids_string === active_user_ids_string;
|
|
||||||
|
|
||||||
let user_circle_class;
|
|
||||||
let status_emoji_info;
|
|
||||||
|
|
||||||
if (!is_group) {
|
|
||||||
const user_id = Number.parseInt(user_ids_string, 10);
|
|
||||||
user_circle_class = buddy_data.get_user_circle_class(user_id);
|
|
||||||
const recipient_user_obj = people.get_by_user_id(user_id);
|
|
||||||
|
|
||||||
if (recipient_user_obj.is_bot) {
|
|
||||||
user_circle_class = "user_circle_green";
|
|
||||||
// bots do not have status emoji
|
|
||||||
} else {
|
|
||||||
status_emoji_info = user_status.get_status_emoji(user_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const display_message = {
|
|
||||||
recipients: recipients_string,
|
|
||||||
user_ids_string,
|
|
||||||
unread: num_unread,
|
|
||||||
is_zero: num_unread === 0,
|
|
||||||
is_active,
|
|
||||||
url: hash_util.pm_with_url(reply_to),
|
|
||||||
status_emoji_info,
|
|
||||||
user_circle_class,
|
|
||||||
is_group,
|
|
||||||
};
|
|
||||||
display_messages.push(display_message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return display_messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function _build_private_messages_list() {
|
export function _build_private_messages_list() {
|
||||||
const convos = _get_convos();
|
const convos = pm_list_data.get_convos();
|
||||||
const dom_ast = pm_list_dom.pm_ul(convos);
|
const dom_ast = pm_list_dom.pm_ul(convos);
|
||||||
return dom_ast;
|
return dom_ast;
|
||||||
}
|
}
|
||||||
@@ -136,21 +66,11 @@ export function update_private_messages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_all_privates() {
|
|
||||||
const filter = narrow_state.filter();
|
|
||||||
|
|
||||||
if (!filter) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return filter.operands("is").includes("private");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function expand() {
|
export function expand() {
|
||||||
private_messages_open = true;
|
private_messages_open = true;
|
||||||
stream_popover.hide_topic_popover();
|
stream_popover.hide_topic_popover();
|
||||||
update_private_messages();
|
update_private_messages();
|
||||||
if (is_all_privates()) {
|
if (pm_list_data.is_all_privates()) {
|
||||||
$(".top_left_private_messages").addClass("active-filter");
|
$(".top_left_private_messages").addClass("active-filter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
static/js/pm_list_data.js
Normal file
82
static/js/pm_list_data.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import * as buddy_data from "./buddy_data";
|
||||||
|
import * as hash_util from "./hash_util";
|
||||||
|
import * as narrow_state from "./narrow_state";
|
||||||
|
import * as people from "./people";
|
||||||
|
import * as pm_conversations from "./pm_conversations";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
import * as user_status from "./user_status";
|
||||||
|
|
||||||
|
export function get_active_user_ids_string() {
|
||||||
|
const filter = narrow_state.filter();
|
||||||
|
|
||||||
|
if (!filter) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emails = filter.operands("pm-with")[0];
|
||||||
|
|
||||||
|
if (!emails) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return people.emails_strings_to_user_ids_string(emails);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function get_convos() {
|
||||||
|
const private_messages = pm_conversations.recent.get();
|
||||||
|
const display_messages = [];
|
||||||
|
const active_user_ids_string = get_active_user_ids_string();
|
||||||
|
|
||||||
|
for (const private_message_obj of private_messages) {
|
||||||
|
const user_ids_string = private_message_obj.user_ids_string;
|
||||||
|
const reply_to = people.user_ids_string_to_emails_string(user_ids_string);
|
||||||
|
const recipients_string = people.get_recipients(user_ids_string);
|
||||||
|
|
||||||
|
const num_unread = unread.num_unread_for_person(user_ids_string);
|
||||||
|
|
||||||
|
const is_group = user_ids_string.includes(",");
|
||||||
|
|
||||||
|
const is_active = user_ids_string === active_user_ids_string;
|
||||||
|
|
||||||
|
let user_circle_class;
|
||||||
|
let status_emoji_info;
|
||||||
|
|
||||||
|
if (!is_group) {
|
||||||
|
const user_id = Number.parseInt(user_ids_string, 10);
|
||||||
|
user_circle_class = buddy_data.get_user_circle_class(user_id);
|
||||||
|
const recipient_user_obj = people.get_by_user_id(user_id);
|
||||||
|
|
||||||
|
if (recipient_user_obj.is_bot) {
|
||||||
|
user_circle_class = "user_circle_green";
|
||||||
|
// bots do not have status emoji
|
||||||
|
} else {
|
||||||
|
status_emoji_info = user_status.get_status_emoji(user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const display_message = {
|
||||||
|
recipients: recipients_string,
|
||||||
|
user_ids_string,
|
||||||
|
unread: num_unread,
|
||||||
|
is_zero: num_unread === 0,
|
||||||
|
is_active,
|
||||||
|
url: hash_util.pm_with_url(reply_to),
|
||||||
|
status_emoji_info,
|
||||||
|
user_circle_class,
|
||||||
|
is_group,
|
||||||
|
};
|
||||||
|
display_messages.push(display_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return display_messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function is_all_privates() {
|
||||||
|
const filter = narrow_state.filter();
|
||||||
|
|
||||||
|
if (!filter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter.operands("is").includes("private");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user