"use strict"; const assert = require("node:assert/strict"); const {mock_esm, zrequire} = require("./lib/namespace.cjs"); const {run_test} = require("./lib/test.cjs"); const $ = require("./lib/zjquery.cjs"); const {page_params} = require("./lib/zpage_params.cjs"); const {Filter} = zrequire("filter"); const {MessageList} = zrequire("message_list"); const message_lists = zrequire("message_lists"); const popover_menus_data = zrequire("popover_menus_data"); const people = zrequire("people"); const compose_state = zrequire("compose_state"); const user_groups = zrequire("user_groups"); const {MessageListData} = zrequire("message_list_data"); const {set_current_user, set_realm} = zrequire("state_data"); const noop = function () {}; // Define MessageList stuff function MessageListView() { return { maybe_rerender: noop, append: noop, prepend: noop, clear_rendering_state: noop, get_row: () => ({ find: () => ({ is: () => false, }), }), message_containers: new Map(), }; } mock_esm("../src/message_list_view", { MessageListView, }); mock_esm("../src/ui_util", { listener_for_preferred_color_scheme_change: noop, }); mock_esm("../src/hash_util", { by_conversation_and_time_url: () => "conversation_and_time_url", }); mock_esm("../src/stream_data", { is_subscribed: () => true, is_stream_archived: () => false, }); mock_esm("../src/group_permission_settings", { get_group_permission_setting_config() { return { allow_everyone_group: false, }; }, }); const current_user = {}; set_current_user(current_user); const realm = {}; set_realm(realm); // Define test users const mike = { user_id: 1000, full_name: "Test Mike", email: "mike@example.com", is_admin: false, is_guest: false, }; const bob = { user_id: 2000, full_name: "Test Bob", email: "bob@example.com", is_admin: false, is_guest: false, }; const me = { user_id: 999, full_name: "Test Myself", email: "me@example.com", is_admin: false, is_guest: false, }; const everyone = { name: "role:everyone", id: 2, members: new Set([999, 1000, 2000]), is_system_group: true, direct_subgroup_ids: new Set([]), }; user_groups.initialize({realm_user_groups: [everyone]}); // Helper functions: function add_initialize_users() { // Initialize people people.init(); // Add users people.add_active_user(mike); people.add_active_user(bob); people.add_active_user(me); // Initialize current user people.initialize_current_user(me.user_id); } function init_message_list() { const filter = new Filter([]); const list = new MessageList({ data: new MessageListData({ excludes_muted_topics: false, filter, }), }); assert.equal(list.empty(), true); return list; } // Append message to message_list, also add container to message_lists function add_message_with_view(list, messages) { list.append(messages, true); for (const message of messages) { message_lists.current.view.message_containers.set(message.id, { is_hidden: message.is_hidden, }); } } // Function sets page parameters with no time constraints on editing the message. // User is assumed to not be an admin. function set_page_params_no_edit_restrictions({override}) { page_params.is_spectator = false; override(realm, "realm_allow_message_editing", true); override(realm, "realm_message_content_edit_limit_seconds", null); override(realm, "realm_allow_edit_history", true); override(realm, "realm_message_content_delete_limit_seconds", null); override(realm, "realm_enable_read_receipts", true); override(realm, "realm_move_messages_within_stream_limit_seconds", null); } // Test init function function test(label, f) { run_test(label, (helpers) => { // Stubs for calculate_timestamp_widths() $("