muted_users_ui: Move functions to more appropriate modules.

This commit is contained in:
Tim Abbott 2023-10-01 12:48:06 -07:00
parent 9283da57f0
commit 4143dac95e
5 changed files with 48 additions and 43 deletions

View File

@ -1,3 +1,4 @@
import * as channel from "./channel";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import {get_time_from_date_muted} from "./util"; import {get_time_from_date_muted} from "./util";
@ -68,6 +69,18 @@ export function set_muted_users(list: RawMutedUser[]): void {
} }
} }
export function mute_user(user_id: number): void {
void channel.post({
url: "/json/users/me/muted_users/" + user_id,
});
}
export function unmute_user(user_id: number): void {
void channel.del({
url: "/json/users/me/muted_users/" + user_id,
});
}
export function initialize(params: {muted_users: RawMutedUser[]}): void { export function initialize(params: {muted_users: RawMutedUser[]}): void {
set_muted_users(params.muted_users); set_muted_users(params.muted_users);
} }

View File

@ -1,47 +1,12 @@
import render_confirm_mute_user from "../templates/confirm_dialog/confirm_mute_user.hbs";
import * as activity from "./activity"; import * as activity from "./activity";
import * as channel from "./channel";
import * as confirm_dialog from "./confirm_dialog";
import {$t_html} from "./i18n";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import * as muted_users from "./muted_users"; import * as muted_users from "./muted_users";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import * as people from "./people";
import * as pm_list from "./pm_list"; import * as pm_list from "./pm_list";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as recent_view_ui from "./recent_view_ui"; import * as recent_view_ui from "./recent_view_ui";
import * as settings_muted_users from "./settings_muted_users"; import * as settings_muted_users from "./settings_muted_users";
export function mute_user(user_id) {
channel.post({
url: "/json/users/me/muted_users/" + user_id,
});
}
export function confirm_mute_user(user_id) {
function on_click() {
mute_user(user_id);
}
const html_body = render_confirm_mute_user({
user_name: people.get_full_name(user_id),
});
confirm_dialog.launch({
html_heading: $t_html({defaultMessage: "Mute user"}),
help_link: "/help/mute-a-user",
html_body,
on_click,
});
}
export function unmute_user(user_id) {
channel.del({
url: "/json/users/me/muted_users/" + user_id,
});
}
export function rerender_for_muted_user() { export function rerender_for_muted_user() {
message_lists.current.update_muting_and_rerender(); message_lists.current.update_muting_and_rerender();
if (message_lists.current !== message_lists.home) { if (message_lists.current !== message_lists.home) {

View File

@ -4,7 +4,6 @@ import render_muted_user_ui_row from "../templates/muted_user_ui_row.hbs";
import * as ListWidget from "./list_widget"; import * as ListWidget from "./list_widget";
import * as muted_users from "./muted_users"; import * as muted_users from "./muted_users";
import * as muted_users_ui from "./muted_users_ui";
import * as people from "./people"; import * as people from "./people";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
@ -52,7 +51,7 @@ export function set_up() {
const user_id = Number.parseInt($row.attr("data-user-id"), 10); const user_id = Number.parseInt($row.attr("data-user-id"), 10);
e.stopPropagation(); e.stopPropagation();
muted_users_ui.unmute_user(user_id); muted_users.unmute_user(user_id);
}); });
populate_list(); populate_list();

View File

@ -3,6 +3,7 @@ import {parseISO} from "date-fns";
import $ from "jquery"; import $ from "jquery";
import tippy from "tippy.js"; import tippy from "tippy.js";
import render_confirm_mute_user from "../templates/confirm_dialog/confirm_mute_user.hbs";
import render_user_card_popover_content from "../templates/user_card_popover_content.hbs"; import render_user_card_popover_content from "../templates/user_card_popover_content.hbs";
import render_user_card_popover_manage_menu from "../templates/user_card_popover_manage_menu.hbs"; import render_user_card_popover_manage_menu from "../templates/user_card_popover_manage_menu.hbs";
import render_user_card_popover_title from "../templates/user_card_popover_title.hbs"; import render_user_card_popover_title from "../templates/user_card_popover_title.hbs";
@ -13,13 +14,13 @@ import * as channel from "./channel";
import * as compose_actions from "./compose_actions"; import * as compose_actions from "./compose_actions";
import * as compose_state from "./compose_state"; import * as compose_state from "./compose_state";
import * as compose_ui from "./compose_ui"; import * as compose_ui from "./compose_ui";
import * as confirm_dialog from "./confirm_dialog";
import {show_copied_confirmation} from "./copied_tooltip"; import {show_copied_confirmation} from "./copied_tooltip";
import * as dialog_widget from "./dialog_widget"; import * as dialog_widget from "./dialog_widget";
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import * as muted_users from "./muted_users"; import * as muted_users from "./muted_users";
import * as muted_users_ui from "./muted_users_ui";
import * as narrow from "./narrow"; import * as narrow from "./narrow";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
@ -40,6 +41,23 @@ import * as user_status_ui from "./user_status_ui";
let current_user_sidebar_user_id; let current_user_sidebar_user_id;
export function confirm_mute_user(user_id) {
function on_click() {
muted_users.mute_user(user_id);
}
const html_body = render_confirm_mute_user({
user_name: people.get_full_name(user_id),
});
confirm_dialog.launch({
html_heading: $t_html({defaultMessage: "Mute user"}),
help_link: "/help/mute-a-user",
html_body,
on_click,
});
}
class PopoverMenu { class PopoverMenu {
constructor() { constructor() {
this.instance = null; this.instance = null;
@ -785,13 +803,13 @@ function register_click_handlers() {
hide_all_user_card_popovers(); hide_all_user_card_popovers();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
muted_users_ui.confirm_mute_user(user_id); confirm_mute_user(user_id);
}); });
$("body").on("click", ".sidebar-popover-unmute-user", (e) => { $("body").on("click", ".sidebar-popover-unmute-user", (e) => {
const user_id = elem_to_user_id($(e.target).parents("ul")); const user_id = elem_to_user_id($(e.target).parents("ul"));
hide_all_user_card_popovers(); hide_all_user_card_popovers();
muted_users_ui.unmute_user(user_id); muted_users.unmute_user(user_id);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });

View File

@ -8,10 +8,10 @@ const $ = require("./lib/zjquery");
const noop = () => {}; const noop = () => {};
const channel = mock_esm("../src/channel");
const list_widget = mock_esm("../src/list_widget", { const list_widget = mock_esm("../src/list_widget", {
generic_sort_functions: noop, generic_sort_functions: noop,
}); });
const muted_users_ui = mock_esm("../src/muted_users_ui");
const settings_muted_users = zrequire("settings_muted_users"); const settings_muted_users = zrequire("settings_muted_users");
const muted_users = zrequire("muted_users"); const muted_users = zrequire("muted_users");
@ -61,12 +61,22 @@ run_test("settings", ({override}) => {
}; };
let unmute_user_called = false; let unmute_user_called = false;
muted_users_ui.unmute_user = (user_id) => { channel.del = (payload) => {
assert.equal(user_id, 5); assert.equal(payload.url, "/json/users/me/muted_users/5");
unmute_user_called = true; unmute_user_called = true;
return {abort() {}};
}; };
unmute_click_handler.call($unmute_button, event); unmute_click_handler.call($unmute_button, event);
assert.ok(unmute_user_called); assert.ok(unmute_user_called);
assert.ok(row_attribute_fetched); assert.ok(row_attribute_fetched);
let mute_user_called = false;
channel.post = (payload) => {
assert.equal(payload.url, "/json/users/me/muted_users/5");
mute_user_called = true;
return {abort() {}};
};
muted_users.mute_user(5);
assert.ok(mute_user_called);
}); });