Implement third-party invite waiting room (#10229)

This commit is contained in:
Michael Weimann 2023-03-06 12:08:04 +01:00 committed by GitHub
parent 94950c6987
commit db6ee53535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 388 additions and 40 deletions

View file

@ -116,6 +116,8 @@ import VoipUserMapper from "../../VoipUserMapper";
import { isCallEvent } from "./LegacyCallEventGrouper";
import { WidgetType } from "../../widgets/WidgetType";
import WidgetUtils from "../../utils/WidgetUtils";
import { shouldEncryptRoomWithSingle3rdPartyInvite } from "../../utils/room/shouldEncryptRoomWithSingle3rdPartyInvite";
import { WaitingForThirdPartyRoomView } from "./WaitingForThirdPartyRoomView";
const DEBUG = false;
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
@ -231,6 +233,7 @@ export interface IRoomState {
}
interface LocalRoomViewProps {
localRoom: LocalRoom;
resizeNotifier: ResizeNotifier;
permalinkCreator: RoomPermalinkCreator;
roomView: RefObject<HTMLElement>;
@ -246,7 +249,7 @@ interface LocalRoomViewProps {
function LocalRoomView(props: LocalRoomViewProps): ReactElement {
const context = useContext(RoomContext);
const room = context.room as LocalRoom;
const encryptionEvent = context.room.currentState.getStateEvents(EventType.RoomEncryption)[0];
const encryptionEvent = props.localRoom.currentState.getStateEvents(EventType.RoomEncryption)[0];
let encryptionTile: ReactNode;
if (encryptionEvent) {
@ -261,8 +264,8 @@ function LocalRoomView(props: LocalRoomViewProps): ReactElement {
});
};
let statusBar: ReactElement;
let composer: ReactElement;
let statusBar: ReactElement | null = null;
let composer: ReactElement | null = null;
if (room.isError) {
const buttons = (
@ -281,7 +284,7 @@ function LocalRoomView(props: LocalRoomViewProps): ReactElement {
} else {
composer = (
<MessageComposer
room={context.room}
room={props.localRoom}
resizeNotifier={props.resizeNotifier}
permalinkCreator={props.permalinkCreator}
/>
@ -293,7 +296,7 @@ function LocalRoomView(props: LocalRoomViewProps): ReactElement {
<ErrorBoundary>
<RoomHeader
room={context.room}
searchInfo={null}
searchInfo={undefined}
inRoom={true}
onSearchClick={null}
onInviteClick={null}
@ -342,7 +345,7 @@ function LocalRoomCreateLoader(props: ILocalRoomCreateLoaderProps): ReactElement
<ErrorBoundary>
<RoomHeader
room={context.room}
searchInfo={null}
searchInfo={undefined}
inRoom={true}
onSearchClick={null}
onInviteClick={null}
@ -373,7 +376,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private roomView = createRef<HTMLElement>();
private searchResultsPanel = createRef<ScrollPanel>();
private messagePanel: TimelinePanel;
private messagePanel?: TimelinePanel;
private roomViewBody = createRef<HTMLDivElement>();
public static contextType = SDKContext;
@ -382,15 +385,19 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
public constructor(props: IRoomProps, context: React.ContextType<typeof SDKContext>) {
super(props, context);
if (!context.client) {
throw new Error("Unable to create RoomView without MatrixClient");
}
const llMembers = context.client.hasLazyLoadMembersEnabled();
this.state = {
roomId: null,
roomId: undefined,
roomLoading: true,
peekLoading: false,
shouldPeek: true,
membersLoaded: !llMembers,
numUnreadMessages: 0,
callState: null,
callState: undefined,
activeCall: null,
canPeek: false,
canSelfRedact: false,
@ -1920,10 +1927,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
private renderLocalRoomView(): ReactElement {
private renderLocalRoomView(localRoom: LocalRoom): ReactElement {
return (
<RoomContext.Provider value={this.state}>
<LocalRoomView
localRoom={localRoom}
resizeNotifier={this.props.resizeNotifier}
permalinkCreator={this.permalinkCreator}
roomView={this.roomView}
@ -1933,13 +1941,33 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
private renderWaitingForThirdPartyRoomView(inviteEvent: MatrixEvent): ReactElement {
return (
<RoomContext.Provider value={this.state}>
<WaitingForThirdPartyRoomView
resizeNotifier={this.props.resizeNotifier}
roomView={this.roomView}
inviteEvent={inviteEvent}
/>
</RoomContext.Provider>
);
}
public render(): React.ReactNode {
if (this.state.room instanceof LocalRoom) {
if (this.state.room.state === LocalRoomState.CREATING) {
return this.renderLocalRoomCreateLoader();
}
return this.renderLocalRoomView();
return this.renderLocalRoomView(this.state.room);
}
if (this.state.room) {
const { shouldEncrypt, inviteEvent } = shouldEncryptRoomWithSingle3rdPartyInvite(this.state.room);
if (shouldEncrypt) {
return this.renderWaitingForThirdPartyRoomView(inviteEvent);
}
}
if (!this.state.room) {

View file

@ -0,0 +1,82 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import { RefObject } from "react";
import { useRoomContext } from "../../contexts/RoomContext";
import ResizeNotifier from "../../utils/ResizeNotifier";
import { E2EStatus } from "../../utils/ShieldUtils";
import ErrorBoundary from "../views/elements/ErrorBoundary";
import RoomHeader from "../views/rooms/RoomHeader";
import ScrollPanel from "./ScrollPanel";
import EventTileBubble from "../views/messages/EventTileBubble";
import NewRoomIntro from "../views/rooms/NewRoomIntro";
import { UnwrappedEventTile } from "../views/rooms/EventTile";
import { _t } from "../../languageHandler";
interface Props {
roomView: RefObject<HTMLElement>;
resizeNotifier: ResizeNotifier;
inviteEvent: MatrixEvent;
}
/**
* Component that displays a waiting room for an encrypted DM with a third party invite.
* If encryption by default is enabled, DMs with a third party invite should be encrypted as well.
* To avoid UTDs, users are shown a waiting room until the others have joined.
*/
export const WaitingForThirdPartyRoomView: React.FC<Props> = ({ roomView, resizeNotifier, inviteEvent }) => {
const context = useRoomContext();
return (
<div className="mx_RoomView mx_RoomView--local">
<ErrorBoundary>
<RoomHeader
room={context.room}
inRoom={true}
onSearchClick={null}
onInviteClick={null}
onForgetClick={null}
e2eStatus={E2EStatus.Normal}
onAppsClick={null}
appsShown={false}
excludedRightPanelPhaseButtons={[]}
showButtons={false}
enableRoomOptionsMenu={false}
viewingCall={false}
activeCall={null}
/>
<main className="mx_RoomView_body" ref={roomView}>
<div className="mx_RoomView_timeline">
<ScrollPanel className="mx_RoomView_messagePanel" resizeNotifier={resizeNotifier}>
<EventTileBubble
className="mx_cryptoEvent mx_cryptoEvent_icon"
title={_t("Waiting for users to join Element")}
subtitle={_t(
"Once invited users have joined Element, you will be able to chat and the room will be end-to-end encrypted",
)}
/>
<NewRoomIntro />
<UnwrappedEventTile mxEvent={inviteEvent} />
</ScrollPanel>
</div>
</main>
</ErrorBoundary>
</div>
);
};