Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { logger } from "@sentry/browser";
import { type Room } from "matrix-js-sdk/src/matrix";
import { KnownMembership } from "matrix-js-sdk/src/types";
import React, { type ReactNode } from "react";

import { useMatrixClientContext } from "../../../../../contexts/MatrixClientContext";
import { _t } from "../../../../../languageHandler";
Expand All @@ -29,7 +30,7 @@
}
/**
* The view model for the room ban button used in the UserInfoAdminToolsContainer
* @param {RoomAdminToolsProps} props - the object containing the necceray props for banButton the view model
* @param {RoomAdminToolsProps} props - the object containing the necessary props for banButton the view model
* @param {Room} props.room - the room to ban/unban the user in
* @param {RoomMember} props.member - the member to ban/unban
* @param {boolean} props.isUpdating - whether the operation is currently in progress
Expand Down Expand Up @@ -67,8 +68,15 @@
: _t("user_info|ban_room_confirm_title", { roomName: room.name }),
askReason: !isBanned,
danger: !isBanned,
children: [] as ReactNode,
};

const msc4333Config = cli.msc4333Moderation.getModerationConfigFor(props.room.roomId);

Check failure on line 74 in src/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

useBanButtonViewModel › clicking the ban or unban button calls Modal.createDialog with the correct arguments if user _is_ banned

TypeError: Cannot read properties of undefined (reading 'getModerationConfigFor') at Object.getModerationConfigFor [as onBanOrUnbanClick] (src/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel.tsx:74:53) at Object.onBanOrUnbanClick (test/unit-tests/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel-test.tsx:191:30)

Check failure on line 74 in src/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

useBanButtonViewModel › clicking the ban or unban button calls Modal.createDialog with the correct arguments if user is not banned

TypeError: Cannot read properties of undefined (reading 'getModerationConfigFor') at Object.getModerationConfigFor [as onBanOrUnbanClick] (src/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel.tsx:74:53) at Object.onBanOrUnbanClick (test/unit-tests/components/viewmodels/right_panel/user_info/admin/UserInfoBanButtonViewModel-test.tsx:148:30)
if (msc4333Config && !isBanned) {
const managementRoom = cli.getRoom(msc4333Config.managementRoomId);
commonProps["children"] = [<p key={1}>You are banning this user using {managementRoom?.name} (via {msc4333Config.botUserId}).</p>];
}

let finished: Promise<[success?: boolean, reason?: string, rooms?: Room[]]>;

if (room.isSpaceRoom()) {
Expand Down Expand Up @@ -119,10 +127,18 @@
}

const fn = (roomId: string): Promise<unknown> => {
if (isBanned) {
return cli.unban(roomId, member.userId);
} else {
return cli.ban(roomId, member.userId, reason || undefined);
try {
if (isBanned) {
return cli.unban(roomId, member.userId);
} else {
if (msc4333Config) {
return cli.sendMessage(msc4333Config.managementRoomId, msc4333Config.banCommand.render(member.userId, roomId, reason || ""))
}
return cli.ban(roomId, member.userId, reason || undefined);
}
} catch (e) {
console.error(e);
throw e; // re-throw
}
};

Expand Down
Loading