activity: Extract new activity_ui module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-05 01:20:16 -07:00 committed by Tim Abbott
parent 69ceff4995
commit 13d1241eed
14 changed files with 296 additions and 288 deletions

View File

@ -1,27 +1,10 @@
import $ from "jquery";
import _ from "lodash";
import * as blueslip from "./blueslip";
import * as buddy_data from "./buddy_data";
import {buddy_list} from "./buddy_list";
import * as channel from "./channel";
import * as keydown_util from "./keydown_util";
import {ListCursor} from "./list_cursor";
import * as narrow from "./narrow";
import {page_params} from "./page_params";
import * as people from "./people";
import * as pm_list from "./pm_list";
import * as popovers from "./popovers";
import * as presence from "./presence";
import * as sidebar_ui from "./sidebar_ui";
import * as ui_util from "./ui_util";
import {UserSearch} from "./user_search";
import * as util from "./util";
import * as watchdog from "./watchdog";
export let user_cursor;
export let user_filter;
/*
Helpers for detecting user activity and managing user idle states
*/
@ -51,33 +34,7 @@ export function set_new_user_input(value) {
new_user_input = value;
}
function get_pm_list_item(user_id) {
return buddy_list.find_li({
key: user_id,
});
}
function set_pm_count(user_ids_string, count) {
const $pm_li = get_pm_list_item(user_ids_string);
ui_util.update_unread_count_in_dom($pm_li, count);
}
export function update_dom_with_unread_counts(counts) {
// counts is just a data object that gets calculated elsewhere
// Our job is to update some DOM elements.
for (const [user_ids_string, count] of counts.pm_count) {
// TODO: just use user_ids_string in our markup
const is_pm = !user_ids_string.includes(",");
if (is_pm) {
set_pm_count(user_ids_string, count);
}
}
}
export function clear_for_testing() {
user_cursor = undefined;
user_filter = undefined;
client_is_active = false;
}
@ -88,53 +45,6 @@ export function mark_client_idle() {
client_is_active = false;
}
export function redraw_user(user_id) {
if (page_params.realm_presence_disabled) {
return;
}
const filter_text = get_filter_text();
if (!buddy_data.matches_filter(filter_text, user_id)) {
return;
}
const info = buddy_data.get_item(user_id);
buddy_list.insert_or_move({
key: user_id,
item: info,
});
}
export function searching() {
return user_filter && user_filter.searching();
}
export function build_user_sidebar() {
if (page_params.realm_presence_disabled) {
return undefined;
}
const filter_text = get_filter_text();
const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
buddy_list.populate({keys: user_ids});
return user_ids; // for testing
}
function do_update_users_for_search() {
// Hide all the popovers but not userlist sidebar
// when the user is searching.
popovers.hide_all();
build_user_sidebar();
user_cursor.reset();
}
const update_users_for_search = _.throttle(do_update_users_for_search, 50);
export function compute_active_status() {
// The overall algorithm intent for the `status` field is to send
// `ACTIVE` (aka green circle) if we know the user is at their
@ -163,7 +73,7 @@ export function compute_active_status() {
return IDLE;
}
export function send_presence_to_server(want_redraw) {
export function send_presence_to_server(redraw) {
// Zulip has 2 data feeds coming from the server to the client:
// The server_events data, and this presence feed. Data from
// server_events is nicely serialized, but if we've been offline
@ -190,7 +100,7 @@ export function send_presence_to_server(want_redraw) {
url: "/json/users/me/presence",
data: {
status: compute_active_status(),
ping_only: !want_redraw,
ping_only: !redraw,
new_user_input,
slim_presence: true,
},
@ -204,7 +114,7 @@ export function send_presence_to_server(want_redraw) {
new_user_input = false;
if (want_redraw) {
if (redraw) {
presence.set_info(data.presences, data.server_timestamp);
redraw();
}
@ -216,7 +126,7 @@ export function mark_client_active() {
// exported for testing
if (!client_is_active) {
client_is_active = true;
send_presence_to_server(false);
send_presence_to_server();
}
}
@ -232,124 +142,4 @@ export function initialize() {
onActive: mark_client_active,
keepTracking: true,
});
set_cursor_and_filter();
build_user_sidebar();
buddy_list.start_scroll_handler();
function get_full_presence_list_update() {
send_presence_to_server(true);
}
/* Time between keep-alive pings */
const active_ping_interval_ms = page_params.server_presence_ping_interval_seconds * 1000;
util.call_function_periodically(get_full_presence_list_update, active_ping_interval_ms);
// Let the server know we're here, but pass "false" for
// want_redraw, since we just got all this info in page_params.
send_presence_to_server(false);
}
export function update_presence_info(user_id, info, server_time) {
presence.update_info_from_event(user_id, info, server_time);
redraw_user(user_id);
pm_list.update_private_messages();
}
export function redraw() {
build_user_sidebar();
user_cursor.redraw();
pm_list.update_private_messages();
}
export function reset_users() {
// Call this when we're leaving the search widget.
build_user_sidebar();
user_cursor.clear();
}
export function narrow_for_user(opts) {
const user_id = buddy_list.get_key_from_li({$li: opts.$li});
return narrow_for_user_id({user_id});
}
export function narrow_for_user_id(opts) {
const person = people.get_by_user_id(opts.user_id);
const email = person.email;
narrow.by("dm", email, {trigger: "sidebar"});
user_filter.clear_and_hide_search();
}
function keydown_enter_key() {
const user_id = user_cursor.get_key();
if (user_id === undefined) {
return;
}
narrow_for_user_id({user_id});
sidebar_ui.hide_all();
popovers.hide_all();
}
export function set_cursor_and_filter() {
user_cursor = new ListCursor({
list: buddy_list,
highlight_class: "highlighted_user",
});
user_filter = new UserSearch({
update_list: update_users_for_search,
reset_items: reset_users,
on_focus: () => user_cursor.reset(),
});
const $input = user_filter.input_field();
$input.on("blur", () => user_cursor.clear());
keydown_util.handle({
$elem: $input,
handlers: {
Enter() {
keydown_enter_key();
return true;
},
ArrowUp() {
user_cursor.prev();
return true;
},
ArrowDown() {
user_cursor.next();
return true;
},
},
});
}
export function initiate_search() {
if (user_filter) {
user_filter.initiate_search();
}
}
export function escape_search() {
if (user_filter) {
user_filter.escape_search();
}
}
export function get_filter_text() {
if (!user_filter) {
// This may be overly defensive, but there may be
// situations where get called before everything is
// fully initialized. The empty string is a fine
// default here.
blueslip.warn("get_filter_text() is called before initialization");
return "";
}
return user_filter.text();
}

219
web/src/activity_ui.js Normal file
View File

@ -0,0 +1,219 @@
import _ from "lodash";
import * as activity from "./activity";
import * as blueslip from "./blueslip";
import * as buddy_data from "./buddy_data";
import {buddy_list} from "./buddy_list";
import * as keydown_util from "./keydown_util";
import {ListCursor} from "./list_cursor";
import * as narrow from "./narrow";
import {page_params} from "./page_params";
import * as people from "./people";
import * as pm_list from "./pm_list";
import * as popovers from "./popovers";
import * as presence from "./presence";
import * as sidebar_ui from "./sidebar_ui";
import * as ui_util from "./ui_util";
import {UserSearch} from "./user_search";
import * as util from "./util";
export let user_cursor;
export let user_filter;
function get_pm_list_item(user_id) {
return buddy_list.find_li({
key: user_id,
});
}
function set_pm_count(user_ids_string, count) {
const $pm_li = get_pm_list_item(user_ids_string);
ui_util.update_unread_count_in_dom($pm_li, count);
}
export function update_dom_with_unread_counts(counts) {
// counts is just a data object that gets calculated elsewhere
// Our job is to update some DOM elements.
for (const [user_ids_string, count] of counts.pm_count) {
// TODO: just use user_ids_string in our markup
const is_pm = !user_ids_string.includes(",");
if (is_pm) {
set_pm_count(user_ids_string, count);
}
}
}
export function clear_for_testing() {
user_cursor = undefined;
user_filter = undefined;
}
export function redraw_user(user_id) {
if (page_params.realm_presence_disabled) {
return;
}
const filter_text = get_filter_text();
if (!buddy_data.matches_filter(filter_text, user_id)) {
return;
}
const info = buddy_data.get_item(user_id);
buddy_list.insert_or_move({
key: user_id,
item: info,
});
}
export function searching() {
return user_filter && user_filter.searching();
}
export function build_user_sidebar() {
if (page_params.realm_presence_disabled) {
return undefined;
}
const filter_text = get_filter_text();
const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
buddy_list.populate({keys: user_ids});
return user_ids; // for testing
}
function do_update_users_for_search() {
// Hide all the popovers but not userlist sidebar
// when the user is searching.
popovers.hide_all();
build_user_sidebar();
user_cursor.reset();
}
const update_users_for_search = _.throttle(do_update_users_for_search, 50);
export function initialize() {
set_cursor_and_filter();
build_user_sidebar();
buddy_list.start_scroll_handler();
function get_full_presence_list_update() {
activity.send_presence_to_server(redraw);
}
/* Time between keep-alive pings */
const active_ping_interval_ms = page_params.server_presence_ping_interval_seconds * 1000;
util.call_function_periodically(get_full_presence_list_update, active_ping_interval_ms);
// Let the server know we're here, but do not pass
// redraw, since we just got all this info in page_params.
activity.send_presence_to_server();
}
export function update_presence_info(user_id, info, server_time) {
presence.update_info_from_event(user_id, info, server_time);
redraw_user(user_id);
pm_list.update_private_messages();
}
export function redraw() {
build_user_sidebar();
user_cursor.redraw();
pm_list.update_private_messages();
}
export function reset_users() {
// Call this when we're leaving the search widget.
build_user_sidebar();
user_cursor.clear();
}
export function narrow_for_user(opts) {
const user_id = buddy_list.get_key_from_li({$li: opts.$li});
return narrow_for_user_id({user_id});
}
export function narrow_for_user_id(opts) {
const person = people.get_by_user_id(opts.user_id);
const email = person.email;
narrow.by("dm", email, {trigger: "sidebar"});
user_filter.clear_and_hide_search();
}
function keydown_enter_key() {
const user_id = user_cursor.get_key();
if (user_id === undefined) {
return;
}
narrow_for_user_id({user_id});
sidebar_ui.hide_all();
popovers.hide_all();
}
export function set_cursor_and_filter() {
user_cursor = new ListCursor({
list: buddy_list,
highlight_class: "highlighted_user",
});
user_filter = new UserSearch({
update_list: update_users_for_search,
reset_items: reset_users,
on_focus: () => user_cursor.reset(),
});
const $input = user_filter.input_field();
$input.on("blur", () => user_cursor.clear());
keydown_util.handle({
$elem: $input,
handlers: {
Enter() {
keydown_enter_key();
return true;
},
ArrowUp() {
user_cursor.prev();
return true;
},
ArrowDown() {
user_cursor.next();
return true;
},
},
});
}
export function initiate_search() {
if (user_filter) {
user_filter.initiate_search();
}
}
export function escape_search() {
if (user_filter) {
user_filter.escape_search();
}
}
export function get_filter_text() {
if (!user_filter) {
// This may be overly defensive, but there may be
// situations where get called before everything is
// fully initialized. The empty string is a fine
// default here.
blueslip.warn("get_filter_text() is called before initialization");
return "";
}
return user_filter.text();
}

View File

@ -6,7 +6,7 @@ import WinChan from "winchan";
import render_buddy_list_tooltip_content from "../templates/buddy_list_tooltip_content.hbs";
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as blueslip from "./blueslip";
import * as browser_history from "./browser_history";
import * as buddy_data from "./buddy_data";
@ -480,7 +480,7 @@ export function initialize() {
.on("click", ".selectable_sidebar_block", (e) => {
const $li = $(e.target).parents("li");
activity.narrow_for_user({$li});
activity_ui.narrow_for_user({$li});
e.preventDefault();
e.stopPropagation();

View File

@ -1,6 +1,7 @@
import $ from "jquery";
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as browser_history from "./browser_history";
import * as common from "./common";
import * as compose from "./compose";
@ -293,8 +294,8 @@ export function process_escape_key(e) {
}
if (processing_text()) {
if (activity.searching()) {
activity.escape_search();
if (activity_ui.searching()) {
activity_ui.escape_search();
return true;
}
@ -886,7 +887,7 @@ export function process_hotkey(e, hotkey) {
stream_list.initiate_search();
return true;
case "query_users":
activity.initiate_search();
activity_ui.initiate_search();
return true;
case "search":
case "search_with_k":

View File

@ -1,4 +1,4 @@
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as message_lists from "./message_lists";
import * as muted_users from "./muted_users";
import * as overlays from "./overlays";
@ -17,7 +17,7 @@ export function rerender_for_muted_user() {
settings_muted_users.populate_list();
}
activity.redraw();
activity_ui.redraw();
pm_list.update_private_messages();
// If a user is (un)muted, we want to update their avatars on the Recent Conversations

View File

@ -1,6 +1,6 @@
import $ from "jquery";
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as alert_words from "./alert_words";
import * as alert_words_ui from "./alert_words_ui";
import * as attachments_ui from "./attachments_ui";
@ -160,7 +160,7 @@ export function dispatch_normal_event(event) {
break;
case "presence":
activity.update_presence_info(event.user_id, event.presence, event.server_timestamp);
activity_ui.update_presence_info(event.user_id, event.presence, event.server_timestamp);
break;
case "restart": {
@ -751,7 +751,7 @@ export function dispatch_normal_event(event) {
settings_display.report_user_list_style_change(
settings_display.user_settings_panel,
);
activity.build_user_sidebar();
activity_ui.build_user_sidebar();
}
if (event.property === "dense_mode") {
$("body").toggleClass("less_dense_mode");
@ -796,7 +796,7 @@ export function dispatch_normal_event(event) {
msg_list.rerender();
}
// Rerender buddy list status emoji
activity.build_user_sidebar();
activity_ui.build_user_sidebar();
}
if (event.property === "display_emoji_reaction_users") {
@ -814,7 +814,7 @@ export function dispatch_normal_event(event) {
if (event.property === "presence_enabled") {
user_settings.presence_enabled = event.value;
$("#user_presence_enabled").prop("checked", user_settings.presence_enabled);
activity.redraw_user(page_params.user_id);
activity_ui.redraw_user(page_params.user_id);
break;
}
if (event.property === "email_address_visibility") {
@ -899,7 +899,7 @@ export function dispatch_normal_event(event) {
user_id: event.user_id,
status_text: event.status_text,
});
activity.redraw_user(event.user_id);
activity_ui.redraw_user(event.user_id);
// Update the status text in compose box placeholder when opened to self.
if (compose_pm_pill.get_user_ids().includes(event.user_id)) {
@ -909,7 +909,7 @@ export function dispatch_normal_event(event) {
if (event.emoji_name !== undefined) {
user_status.set_status_emoji(event);
activity.redraw_user(event.user_id);
activity_ui.redraw_user(event.user_id);
pm_list.update_private_messages();
message_live_update.update_user_status_emoji(
event.user_id,

View File

@ -13,6 +13,7 @@ import render_right_sidebar from "../templates/right_sidebar.hbs";
import * as about_zulip from "./about_zulip";
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as add_stream_options_popover from "./add_stream_options_popover";
import * as alert_words from "./alert_words";
import * as blueslip from "./blueslip";
@ -368,7 +369,7 @@ export function initialize_kitchen_sink_stuff() {
function initialize_unread_ui() {
unread_ui.register_update_unread_counts_hook((counts) =>
activity.update_dom_with_unread_counts(counts),
activity_ui.update_dom_with_unread_counts(counts),
);
unread_ui.register_update_unread_counts_hook((counts, skip_animations) =>
left_sidebar_navigation_area.update_dom_with_unread_counts(counts, skip_animations),
@ -674,6 +675,7 @@ export function initialize_everything() {
initialize_unread_ui();
activity.initialize();
activity_ui.initialize();
emoji_picker.initialize();
user_group_popover.initialize();
user_card_popover.initialize();

View File

@ -4,7 +4,7 @@
// (We should do bot updates here too.)
import $ from "jquery";
import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as blueslip from "./blueslip";
import * as compose from "./compose";
import * as message_live_update from "./message_live_update";
@ -57,7 +57,7 @@ export const update_person = function update(person) {
people.set_full_name(person_obj, person.full_name);
settings_users.update_user_data(person.user_id, person);
activity.redraw();
activity_ui.redraw();
message_live_update.update_user_full_name(person.user_id, person.full_name);
pm_list.update_private_messages();
if (people.is_my_user_id(person.user_id)) {

View File

@ -40,6 +40,7 @@ const people = zrequire("people");
const buddy_data = zrequire("buddy_data");
const {buddy_list} = zrequire("buddy_list");
const activity = zrequire("activity");
const activity_ui = zrequire("activity_ui");
const me = {
email: "me@zulip.com",
@ -119,7 +120,7 @@ function test(label, f) {
muted_users.set_muted_users([]);
activity.clear_for_testing();
activity.set_cursor_and_filter();
activity_ui.set_cursor_and_filter();
f(helpers);
@ -129,8 +130,9 @@ function test(label, f) {
run_test("reload_defaults", () => {
activity.clear_for_testing();
activity_ui.clear_for_testing();
blueslip.expect("warn", "get_filter_text() is called before initialization");
assert.equal(activity.get_filter_text(), "");
assert.equal(activity_ui.get_filter_text(), "");
});
test("get_status", () => {
@ -219,7 +221,7 @@ test("presence_list_full_update", ({override, mock_template}) => {
compose_state.private_message_recipient = () => fred.email;
compose_fade.set_focused_recipient("private");
const user_ids = activity.build_user_sidebar();
const user_ids = activity_ui.build_user_sidebar();
assert.deepEqual(user_ids, [
me.user_id,
@ -260,12 +262,12 @@ test("direct_message_update_dom_counts", () => {
counts.set(pm_key, 5);
$li.addClass("user_sidebar_entry");
activity.update_dom_with_unread_counts({pm_count: counts});
activity_ui.update_dom_with_unread_counts({pm_count: counts});
assert.equal($count.text(), "5");
counts.set(pm_key, 0);
activity.update_dom_with_unread_counts({pm_count: counts});
activity_ui.update_dom_with_unread_counts({pm_count: counts});
assert.equal($count.text(), "");
});
@ -302,7 +304,7 @@ test("handlers", ({override, mock_template}) => {
buddy_list.populate({
keys: [me.user_id, alice.user_id, fred.user_id],
});
activity.set_cursor_and_filter();
activity_ui.set_cursor_and_filter();
$("#user_presences").empty = () => {};
$me_li = $.create("me stub");
@ -316,7 +318,7 @@ test("handlers", ({override, mock_template}) => {
(function test_filter_keys() {
init();
activity.user_cursor.go_to(alice.user_id);
activity_ui.user_cursor.go_to(alice.user_id);
filter_key_handlers.ArrowDown();
filter_key_handlers.ArrowUp();
})();
@ -348,12 +350,12 @@ test("handlers", ({override, mock_template}) => {
$(".user-list-filter").val("al");
narrowed = false;
activity.user_cursor.go_to(alice.user_id);
activity_ui.user_cursor.go_to(alice.user_id);
filter_key_handlers.Enter();
assert.ok(narrowed);
// get line coverage for cleared case
activity.user_cursor.clear();
activity_ui.user_cursor.clear();
filter_key_handlers.Enter();
})();
@ -362,7 +364,7 @@ test("handlers", ({override, mock_template}) => {
// We wire up the click handler in click_handlers.js,
// so this just tests the called function.
narrowed = false;
activity.narrow_for_user({$li: $alice_li});
activity_ui.narrow_for_user({$li: $alice_li});
assert.ok(narrowed);
})();
@ -433,8 +435,8 @@ test("first/prev/next", ({override, mock_template}) => {
override(buddy_list.$container, "append", () => {});
activity.redraw_user(alice.user_id);
activity.redraw_user(fred.user_id);
activity_ui.redraw_user(alice.user_id);
activity_ui.redraw_user(fred.user_id);
assert.equal(buddy_list.first_key(), alice.user_id);
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
@ -477,7 +479,7 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
appended_html = html;
});
activity.redraw_user(alice.user_id);
activity_ui.redraw_user(alice.user_id);
assert.ok(appended_html.indexOf('data-user-id="1"') > 0);
assert.ok(appended_html.indexOf("user_circle_green") > 0);
});
@ -491,11 +493,11 @@ test("insert_alice_then_fred", ({override, mock_template}) => {
});
override(padded_widget, "update_padding", () => {});
activity.redraw_user(alice.user_id);
activity_ui.redraw_user(alice.user_id);
assert.ok(appended_html.indexOf('data-user-id="1"') > 0);
assert.ok(appended_html.indexOf("user_circle_green") > 0);
activity.redraw_user(fred.user_id);
activity_ui.redraw_user(fred.user_id);
assert.ok(appended_html.indexOf('data-user-id="2"') > 0);
assert.ok(appended_html.indexOf("user_circle_green") > 0);
});
@ -509,7 +511,7 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
});
override(padded_widget, "update_padding", () => {});
activity.redraw_user(fred.user_id);
activity_ui.redraw_user(fred.user_id);
assert.ok(appended_html.indexOf('data-user-id="2"') > 0);
assert.ok(appended_html.indexOf("user_circle_green") > 0);
@ -526,7 +528,7 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
fred_removed = true;
};
activity.redraw_user(alice.user_id);
activity_ui.redraw_user(alice.user_id);
assert.ok(inserted_html.indexOf('data-user-id="1"') > 0);
assert.ok(inserted_html.indexOf("user_circle_green") > 0);
@ -545,7 +547,7 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
inserted_html = html;
};
activity.redraw_user(fred_with_new_name.user_id);
activity_ui.redraw_user(fred_with_new_name.user_id);
assert.ok(fred_removed);
assert.ok(appended_html.indexOf('data-user-id="2"') > 0);
@ -559,19 +561,19 @@ test("insert_unfiltered_user_with_filter", () => {
// match the search filter.
const $user_filter = $(".user-list-filter");
$user_filter.val("do-not-match-filter");
activity.redraw_user(fred.user_id);
activity_ui.redraw_user(fred.user_id);
});
test("realm_presence_disabled", () => {
page_params.realm_presence_disabled = true;
activity.redraw_user();
activity.build_user_sidebar();
activity_ui.redraw_user();
activity_ui.build_user_sidebar();
});
test("redraw_muted_user", () => {
muted_users.add_muted_user(mark.user_id);
activity.redraw_user(mark.user_id);
activity_ui.redraw_user(mark.user_id);
assert.equal($("#user_presences").html(), "never-been-set");
});
@ -599,12 +601,12 @@ test("update_presence_info", ({override}) => {
});
presence.presence_info.delete(me.user_id);
activity.update_presence_info(me.user_id, info, server_time);
activity_ui.update_presence_info(me.user_id, info, server_time);
assert.ok(inserted);
assert.deepEqual(presence.presence_info.get(me.user_id).status, "active");
presence.presence_info.delete(alice.user_id);
activity.update_presence_info(alice.user_id, info, server_time);
activity_ui.update_presence_info(alice.user_id, info, server_time);
assert.ok(inserted);
const expected = {status: "active", last_active: 500};
@ -656,6 +658,7 @@ test("initialize", ({override, mock_template}) => {
});
activity.initialize();
activity_ui.initialize();
payload.success({
zephyr_mirror_active: true,
presences: {},
@ -676,6 +679,7 @@ test("initialize", ({override, mock_template}) => {
$(window).off("focus");
activity.initialize();
activity_ui.initialize();
payload.success({
zephyr_mirror_active: false,
presences: {},

View File

@ -19,7 +19,7 @@ const typing_person1 = events.typing_person1;
set_global("requestAnimationFrame", (func) => func());
const activity = mock_esm("../src/activity");
const activity_ui = mock_esm("../src/activity_ui");
const alert_words_ui = mock_esm("../src/alert_words_ui");
const attachments_ui = mock_esm("../src/attachments_ui");
const bot_data = mock_esm("../src/bot_data");
@ -347,7 +347,7 @@ run_test("presence", ({override}) => {
const event = event_fixtures.presence;
const stub = make_stub();
override(activity, "update_presence_info", stub.f);
override(activity_ui, "update_presence_info", stub.f);
dispatch(event);
assert.equal(stub.num_calls, 1);
const args = stub.get_args("user_id", "presence", "server_time");
@ -936,7 +936,7 @@ run_test("user_settings", ({override}) => {
event = event_fixtures.user_settings__emojiset;
called = false;
override(settings_display, "report_emojiset_change", stub.f);
override(activity, "build_user_sidebar", noop);
override(activity_ui, "build_user_sidebar", noop);
user_settings.emojiset = "text";
dispatch(event);
assert.equal(stub.num_calls, 1);
@ -981,7 +981,7 @@ run_test("user_settings", ({override}) => {
event = event_fixtures.user_settings__user_list_style;
override(settings_display, "report_user_list_style_change", stub.f);
user_settings.user_list_style = 1;
override(activity, "build_user_sidebar", stub.f);
override(activity_ui, "build_user_sidebar", stub.f);
dispatch(event);
assert.equal(stub.num_calls, 2);
assert_same(user_settings.user_list_style, 2);
@ -994,12 +994,12 @@ run_test("user_settings", ({override}) => {
event = event_fixtures.user_settings__presence_disabled;
user_settings.presence_enabled = true;
override(activity, "redraw_user", noop);
override(activity_ui, "redraw_user", noop);
dispatch(event);
assert_same(user_settings.presence_enabled, false);
event = event_fixtures.user_settings__presence_enabled;
override(activity, "redraw_user", noop);
override(activity_ui, "redraw_user", noop);
dispatch(event);
assert_same(user_settings.presence_enabled, true);
@ -1107,7 +1107,7 @@ run_test("user_status", ({override}) => {
let event = event_fixtures.user_status__set_status_emoji;
{
const stub = make_stub();
override(activity, "redraw_user", stub.f);
override(activity_ui, "redraw_user", stub.f);
override(pm_list, "update_private_messages", noop);
dispatch(event);
assert.equal(stub.num_calls, 1);
@ -1126,7 +1126,7 @@ run_test("user_status", ({override}) => {
event = event_fixtures.user_status__set_status_text;
{
const stub = make_stub();
override(activity, "redraw_user", stub.f);
override(activity_ui, "redraw_user", stub.f);
override(compose_pm_pill, "get_user_ids", () => [event.user_id]);
dispatch(event);
assert.equal(stub.num_calls, 1);

View File

@ -55,7 +55,7 @@ const {run_test} = require("./lib/test");
*/
// We are going to use mock versions of some of our libraries.
const activity = mock_esm("../src/activity");
const activity_ui = mock_esm("../src/activity_ui");
const message_live_update = mock_esm("../src/message_live_update");
const pm_list = mock_esm("../src/pm_list");
const settings_users = mock_esm("../src/settings_users");
@ -132,7 +132,7 @@ run_test("update user with event", ({override}) => {
// verify that they run. Fortunately, the run_test()
// wrapper will tell us if we override a method that
// doesn't get called!
override(activity, "redraw", () => {});
override(activity_ui, "redraw", () => {});
override(message_live_update, "update_user_full_name", () => {});
override(pm_list, "update_private_messages", () => {});
override(settings_users, "update_user_data", () => {});

View File

@ -121,7 +121,7 @@ message_lists.current = {
},
};
const activity = zrequire("activity");
const activity_ui = zrequire("activity_ui");
const emoji = zrequire("emoji");
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
const hotkey = zrequire("hotkey");
@ -318,7 +318,7 @@ run_test("streams", ({override}) => {
run_test("basic mappings", () => {
assert_mapping("?", browser_history, "go_to_location");
assert_mapping("/", search, "initiate_search");
assert_mapping_rewire("w", activity, "initiate_search");
assert_mapping_rewire("w", activity_ui, "initiate_search");
assert_mapping("q", stream_list, "initiate_search");
assert_mapping("A", narrow, "stream_cycle_backward");

View File

@ -14,7 +14,7 @@ const settings_account = mock_esm("../src/settings_account", {
update_account_settings_display() {},
});
mock_esm("../src/activity", {
mock_esm("../src/activity_ui", {
redraw() {},
});
mock_esm("../src/compose", {

View File

@ -2,17 +2,11 @@
const {strict: assert} = require("assert");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params");
const _document = {
hasFocus() {
return true;
},
};
const fake_buddy_list = {
scroll_container_sel: "#whatever",
find_li() {},
@ -30,9 +24,7 @@ const presence = mock_esm("../src/presence");
const resize = mock_esm("../src/resize");
const sidebar_ui = mock_esm("../src/sidebar_ui");
set_global("document", _document);
const activity = zrequire("activity");
const activity_ui = zrequire("activity_ui");
const buddy_data = zrequire("buddy_data");
const muted_users = zrequire("muted_users");
const people = zrequire("people");
@ -71,7 +63,7 @@ function test(label, f) {
people.add_active_user(me);
people.initialize_current_user(me.user_id);
muted_users.set_muted_users([]);
activity.set_cursor_and_filter();
activity_ui.set_cursor_and_filter();
f({override});
});
}
@ -111,9 +103,9 @@ test("escape_search", ({override}) => {
override(popovers, "hide_all", () => {});
set_input_val("somevalue");
activity.escape_search();
activity_ui.escape_search();
assert.equal($(".user-list-filter").val(), "");
activity.escape_search();
activity_ui.escape_search();
assert.ok($("#user_search_section").hasClass("notdisplayed"));
// We need to reset this because the unit tests aren't isolated from each other.
@ -132,7 +124,7 @@ test("blur search right", ({override}) => {
$(".user-list-filter").trigger("blur");
assert.equal($(".user-list-filter").is_focused(), false);
activity.initiate_search();
activity_ui.initiate_search();
assert.equal($(".user-list-filter").is_focused(), true);
});
@ -148,7 +140,7 @@ test("blur search left", ({override}) => {
$(".user-list-filter").trigger("blur");
assert.equal($(".user-list-filter").is_focused(), false);
activity.initiate_search();
activity_ui.initiate_search();
assert.equal($(".user-list-filter").is_focused(), true);
});
@ -165,7 +157,7 @@ test("filter_user_ids", ({override}) => {
function test_filter(search_text, expected_users) {
const expected_user_ids = expected_users.map((user) => user.user_id);
$(".user-list-filter").val(search_text);
const filter_text = activity.get_filter_text();
const filter_text = activity_ui.get_filter_text();
assert.deepEqual(
buddy_data.get_filtered_and_sorted_user_ids(filter_text),
expected_user_ids,
@ -175,7 +167,7 @@ test("filter_user_ids", ({override}) => {
assert.deepEqual(user_ids, expected_user_ids);
});
activity.build_user_sidebar();
activity_ui.build_user_sidebar();
}
// Sanity check data setup.
@ -233,9 +225,9 @@ test("click on user header to toggle display", ({override}) => {
});
test("searching", () => {
assert.equal(activity.searching(), false);
assert.equal(activity_ui.searching(), false);
$(".user-list-filter").trigger("focus");
assert.equal(activity.searching(), true);
assert.equal(activity_ui.searching(), true);
$(".user-list-filter").trigger("blur");
assert.equal(activity.searching(), false);
assert.equal(activity_ui.searching(), false);
});