2019-03-28 20:38:15 -06:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-11-29 21:25:34 +13:00
|
|
|
Copyright 2019-2023 The Matrix.org Foundation C.I.C.
|
2019-03-28 20:38:15 -06:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-03-28 20:38:15 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { EventType, type MatrixEvent, type Room, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2023-11-29 21:25:34 +13:00
|
|
|
import { Button, Text } from "@vector-im/compound-web";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
|
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-05-13 20:41:41 -06:00
|
|
|
import dis from "../../../dispatcher/dispatcher";
|
2019-03-28 20:38:15 -06:00
|
|
|
import Modal from "../../../Modal";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { isValid3pidInvite } from "../../../RoomInvite";
|
2023-11-28 11:30:57 +13:00
|
|
|
import { Action } from "../../../dispatcher/actions";
|
2023-11-29 21:25:34 +13:00
|
|
|
import ErrorDialog from "../dialogs/ErrorDialog";
|
|
|
|
|
import BaseCard from "../right_panel/BaseCard";
|
|
|
|
|
import { Flex } from "../../utils/Flex";
|
2019-03-28 20:38:15 -06:00
|
|
|
|
2021-04-06 12:26:50 +01:00
|
|
|
interface IProps {
|
|
|
|
|
event: MatrixEvent;
|
2023-11-29 21:25:34 +13:00
|
|
|
onClose?: () => void;
|
2021-04-06 12:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
stateKey: string;
|
|
|
|
|
roomId: string;
|
|
|
|
|
displayName: string;
|
|
|
|
|
invited: boolean;
|
|
|
|
|
canKick: boolean;
|
|
|
|
|
senderName: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class ThirdPartyMemberInfo extends React.Component<IProps, IState> {
|
2023-02-24 15:28:40 +00:00
|
|
|
private readonly room: Room | null;
|
2019-03-28 20:38:15 -06:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
2019-03-28 20:38:15 -06:00
|
|
|
super(props);
|
|
|
|
|
|
2023-06-15 08:46:19 +01:00
|
|
|
this.room = MatrixClientPeg.safeGet().getRoom(this.props.event.getRoomId());
|
|
|
|
|
const me = this.room?.getMember(MatrixClientPeg.safeGet().getSafeUserId());
|
2023-02-24 15:28:40 +00:00
|
|
|
const powerLevels = this.room?.currentState.getStateEvents("m.room.power_levels", "");
|
2023-05-22 11:53:23 +12:00
|
|
|
const senderId = this.props.event.getSender()!;
|
2019-03-28 20:38:15 -06:00
|
|
|
|
|
|
|
|
let kickLevel = powerLevels ? powerLevels.getContent().kick : 50;
|
|
|
|
|
if (typeof kickLevel !== "number") kickLevel = 50;
|
|
|
|
|
|
2023-05-22 11:53:23 +12:00
|
|
|
const sender = this.room?.getMember(senderId);
|
2019-03-28 20:38:15 -06:00
|
|
|
|
|
|
|
|
this.state = {
|
2023-04-28 09:45:36 +01:00
|
|
|
stateKey: this.props.event.getStateKey()!,
|
|
|
|
|
roomId: this.props.event.getRoomId()!,
|
2019-03-28 20:38:15 -06:00
|
|
|
displayName: this.props.event.getContent().display_name,
|
|
|
|
|
invited: true,
|
|
|
|
|
canKick: me ? me.powerLevel > kickLevel : false,
|
2023-05-22 11:53:23 +12:00
|
|
|
senderName: sender?.name ?? senderId,
|
2019-03-28 20:38:15 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public componentDidMount(): void {
|
2023-06-15 08:46:19 +01:00
|
|
|
MatrixClientPeg.safeGet().on(RoomStateEvent.Events, this.onRoomStateEvents);
|
2019-03-28 20:38:15 -06:00
|
|
|
}
|
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public componentWillUnmount(): void {
|
2019-03-28 20:38:15 -06:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
if (client) {
|
2022-02-22 12:18:08 +00:00
|
|
|
client.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
|
2019-03-28 20:38:15 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public onRoomStateEvents = (ev: MatrixEvent): void => {
|
2022-02-24 14:39:25 +00:00
|
|
|
if (ev.getType() === EventType.RoomThirdPartyInvite && ev.getStateKey() === this.state.stateKey) {
|
2019-03-28 20:38:15 -06:00
|
|
|
const newDisplayName = ev.getContent().display_name;
|
2019-03-29 11:45:07 -06:00
|
|
|
const isInvited = isValid3pidInvite(ev);
|
2019-03-28 20:38:15 -06:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
const newState = { invited: isInvited } as IState;
|
2019-03-28 20:38:15 -06:00
|
|
|
if (newDisplayName) newState["displayName"] = newDisplayName;
|
|
|
|
|
this.setState(newState);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public onCancel = (): void => {
|
2019-03-28 20:38:15 -06:00
|
|
|
dis.dispatch({
|
2023-11-28 11:30:57 +13:00
|
|
|
action: Action.View3pidInvite,
|
2019-03-28 20:38:15 -06:00
|
|
|
event: null,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public onKickClick = (): void => {
|
2023-06-15 08:46:19 +01:00
|
|
|
MatrixClientPeg.safeGet()
|
2024-03-20 14:27:29 +00:00
|
|
|
.sendStateEvent(this.state.roomId, EventType.RoomThirdPartyInvite, {}, this.state.stateKey)
|
2019-03-28 20:38:15 -06:00
|
|
|
.catch((err) => {
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error(err);
|
2019-03-28 20:38:15 -06:00
|
|
|
|
|
|
|
|
// Revert echo because of error
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ invited: true });
|
2019-03-28 20:38:15 -06:00
|
|
|
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
2023-09-29 08:49:26 +01:00
|
|
|
title: _t("user_info|error_revoke_3pid_invite_title"),
|
|
|
|
|
description: _t("user_info|error_revoke_3pid_invite_description"),
|
2019-03-28 20:38:15 -06:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Local echo
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ invited: false });
|
2019-03-28 20:38:15 -06:00
|
|
|
};
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2023-02-24 15:28:40 +00:00
|
|
|
let adminTools: JSX.Element | undefined;
|
2019-03-28 20:38:15 -06:00
|
|
|
if (this.state.canKick && this.state.invited) {
|
|
|
|
|
adminTools = (
|
2023-11-29 21:25:34 +13:00
|
|
|
<Flex direction="column" as="section" justify="start" gap="var(--cpd-space-2x)">
|
|
|
|
|
<Text as="span" role="heading" size="lg" weight="semibold">
|
|
|
|
|
{_t("user_info|admin_tools_section")}
|
|
|
|
|
</Text>
|
|
|
|
|
<Button size="sm" kind="destructive" className="mx_MemberInfo_field" onClick={this.onKickClick}>
|
2023-09-29 08:49:26 +01:00
|
|
|
{_t("user_info|revoke_invite")}
|
2023-11-29 21:25:34 +13:00
|
|
|
</Button>
|
|
|
|
|
</Flex>
|
2019-03-28 20:38:15 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2024-10-03 09:59:41 +01:00
|
|
|
<BaseCard onClose={this.props.onClose} header={_t("common|profile")}>
|
2023-11-29 21:25:34 +13:00
|
|
|
<Flex className="mx_ThirdPartyMemberInfo" direction="column" gap="var(--cpd-space-4x)">
|
|
|
|
|
<Flex direction="column" as="section" justify="start" gap="var(--cpd-space-2x)">
|
|
|
|
|
{/* same as userinfo name style */}
|
|
|
|
|
<Text as="span" role="heading" size="lg" weight="semibold">
|
|
|
|
|
{this.state.displayName}
|
|
|
|
|
</Text>
|
|
|
|
|
<Text as="span">{_t("user_info|invited_by", { sender: this.state.senderName })}</Text>
|
|
|
|
|
</Flex>
|
|
|
|
|
{adminTools}
|
|
|
|
|
</Flex>
|
|
|
|
|
</BaseCard>
|
2019-03-28 20:38:15 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|