mirror of https://github.com/zulip/zulip.git
muted_users_ui: Move functions to more appropriate modules.
This commit is contained in:
parent
9283da57f0
commit
4143dac95e
|
@ -1,3 +1,4 @@
|
|||
import * as channel from "./channel";
|
||||
import * as timerender from "./timerender";
|
||||
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 {
|
||||
set_muted_users(params.muted_users);
|
||||
}
|
||||
|
|
|
@ -1,47 +1,12 @@
|
|||
import render_confirm_mute_user from "../templates/confirm_dialog/confirm_mute_user.hbs";
|
||||
|
||||
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 muted_users from "./muted_users";
|
||||
import * as overlays from "./overlays";
|
||||
import * as people from "./people";
|
||||
import * as pm_list from "./pm_list";
|
||||
import * as popovers from "./popovers";
|
||||
import * as recent_view_ui from "./recent_view_ui";
|
||||
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() {
|
||||
message_lists.current.update_muting_and_rerender();
|
||||
if (message_lists.current !== message_lists.home) {
|
||||
|
|
|
@ -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 muted_users from "./muted_users";
|
||||
import * as muted_users_ui from "./muted_users_ui";
|
||||
import * as people from "./people";
|
||||
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);
|
||||
|
||||
e.stopPropagation();
|
||||
muted_users_ui.unmute_user(user_id);
|
||||
muted_users.unmute_user(user_id);
|
||||
});
|
||||
|
||||
populate_list();
|
||||
|
|
|
@ -3,6 +3,7 @@ import {parseISO} from "date-fns";
|
|||
import $ from "jquery";
|
||||
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_manage_menu from "../templates/user_card_popover_manage_menu.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_state from "./compose_state";
|
||||
import * as compose_ui from "./compose_ui";
|
||||
import * as confirm_dialog from "./confirm_dialog";
|
||||
import {show_copied_confirmation} from "./copied_tooltip";
|
||||
import * as dialog_widget from "./dialog_widget";
|
||||
import * as hash_util from "./hash_util";
|
||||
import {$t, $t_html} from "./i18n";
|
||||
import * as message_lists from "./message_lists";
|
||||
import * as muted_users from "./muted_users";
|
||||
import * as muted_users_ui from "./muted_users_ui";
|
||||
import * as narrow from "./narrow";
|
||||
import * as overlays from "./overlays";
|
||||
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;
|
||||
|
||||
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 {
|
||||
constructor() {
|
||||
this.instance = null;
|
||||
|
@ -785,13 +803,13 @@ function register_click_handlers() {
|
|||
hide_all_user_card_popovers();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
muted_users_ui.confirm_mute_user(user_id);
|
||||
confirm_mute_user(user_id);
|
||||
});
|
||||
|
||||
$("body").on("click", ".sidebar-popover-unmute-user", (e) => {
|
||||
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
||||
hide_all_user_card_popovers();
|
||||
muted_users_ui.unmute_user(user_id);
|
||||
muted_users.unmute_user(user_id);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
|
|
@ -8,10 +8,10 @@ const $ = require("./lib/zjquery");
|
|||
|
||||
const noop = () => {};
|
||||
|
||||
const channel = mock_esm("../src/channel");
|
||||
const list_widget = mock_esm("../src/list_widget", {
|
||||
generic_sort_functions: noop,
|
||||
});
|
||||
const muted_users_ui = mock_esm("../src/muted_users_ui");
|
||||
|
||||
const settings_muted_users = zrequire("settings_muted_users");
|
||||
const muted_users = zrequire("muted_users");
|
||||
|
@ -61,12 +61,22 @@ run_test("settings", ({override}) => {
|
|||
};
|
||||
|
||||
let unmute_user_called = false;
|
||||
muted_users_ui.unmute_user = (user_id) => {
|
||||
assert.equal(user_id, 5);
|
||||
channel.del = (payload) => {
|
||||
assert.equal(payload.url, "/json/users/me/muted_users/5");
|
||||
unmute_user_called = true;
|
||||
return {abort() {}};
|
||||
};
|
||||
|
||||
unmute_click_handler.call($unmute_button, event);
|
||||
assert.ok(unmute_user_called);
|
||||
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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue