This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Bail out of RoomSettingsDialog
when room is not found
#10662
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b94b27d
hack to fix console noise from unfaked timers and clearAllModals
aa579ef
remove old debug logging in AsyncWrapper
d6fd1a1
Merge branch 'kerry/remove-logs' into kerry/25017/snc-settings-tabs
714101c
pass room to room settings tabs
e434d64
add errorboundary for roomsettingsdialog
03779d4
apply strictnullchecks to tabs/room
e0635f7
Merge branch 'develop' into kerry/25017/room-settings-prop
307a37f
dedupe code to set toom in roomsettingdialog
2c7f243
add unit tests
8103e9e
test SecurityRoomSettingsTab
3d8ed22
Merge branch 'develop' into kerry/25017/room-settings-prop
fdeae80
remove snapshot
723f031
strict fixes
6baa87a
Merge branch 'develop' into kerry/25017/room-settings-prop
9148797
Merge branch 'develop' into kerry/25017/room-settings-prop
4235d3b
more tests
46f381f
2% more test coverage
67c0bb2
remove roomName from RoomSettingsDialogs state
36e87ce
Merge branch 'develop' into kerry/25017/room-settings-prop
7aa340f
Merge branch 'develop' into kerry/25017/room-settings-prop
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
/* | ||
Copyright 2019 New Vector Ltd | ||
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> | ||
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. | ||
|
@@ -16,7 +18,7 @@ limitations under the License. | |
*/ | ||
|
||
import React from "react"; | ||
import { RoomEvent } from "matrix-js-sdk/src/models/room"; | ||
import { RoomEvent, Room } from "matrix-js-sdk/src/models/room"; | ||
|
||
import TabbedView, { Tab } from "../../structures/TabbedView"; | ||
import { _t, _td } from "../../../languageHandler"; | ||
|
@@ -36,6 +38,7 @@ import { VoipRoomSettingsTab } from "../settings/tabs/room/VoipRoomSettingsTab"; | |
import { ActionPayload } from "../../../dispatcher/payloads"; | ||
import { NonEmptyArray } from "../../../@types/common"; | ||
import { PollHistoryTab } from "../settings/tabs/room/PollHistoryTab"; | ||
import ErrorBoundary from "../elements/ErrorBoundary"; | ||
|
||
export const ROOM_GENERAL_TAB = "ROOM_GENERAL_TAB"; | ||
export const ROOM_VOIP_TAB = "ROOM_VOIP_TAB"; | ||
|
@@ -54,14 +57,17 @@ interface IProps { | |
|
||
interface IState { | ||
roomName: string; | ||
room: Room; | ||
} | ||
|
||
export default class RoomSettingsDialog extends React.Component<IProps, IState> { | ||
class RoomSettingsDialog extends React.Component<IProps, IState> { | ||
private dispatcherRef: string; | ||
|
||
public constructor(props: IProps) { | ||
super(props); | ||
this.state = { roomName: "" }; | ||
|
||
const room = this.getRoom(); | ||
this.state = { roomName: "", room }; | ||
} | ||
|
||
public componentDidMount(): void { | ||
|
@@ -70,6 +76,13 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
this.onRoomName(); | ||
} | ||
|
||
public componentDidUpdate(): void { | ||
if (this.props.roomId !== this.state.room.roomId) { | ||
const room = this.getRoom(); | ||
this.setState({ room }); | ||
} | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
if (this.dispatcherRef) { | ||
dis.unregister(this.dispatcherRef); | ||
|
@@ -78,6 +91,21 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
MatrixClientPeg.get().removeListener(RoomEvent.Name, this.onRoomName); | ||
} | ||
|
||
/** | ||
* Get room from client | ||
* @returns Room | ||
* @throws when room is not found | ||
*/ | ||
private getRoom(): Room { | ||
const room = MatrixClientPeg.get().getRoom(this.props.roomId)!; | ||
|
||
// something is really wrong if we encounter this | ||
if (!room) { | ||
throw new Error(`Cannot find room ${this.props.roomId}`); | ||
} | ||
return room; | ||
} | ||
|
||
private onAction = (payload: ActionPayload): void => { | ||
// When view changes below us, close the room settings | ||
// whilst the modal is open this can only be triggered when someone hits Leave Room | ||
|
@@ -88,7 +116,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
|
||
private onRoomName = (): void => { | ||
this.setState({ | ||
roomName: MatrixClientPeg.get().getRoom(this.props.roomId)?.name ?? "", | ||
roomName: this.state.room.name ?? "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be overtaken by my other comment in this file, but could we omit the |
||
}); | ||
}; | ||
|
||
|
@@ -100,7 +128,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_GENERAL_TAB, | ||
_td("General"), | ||
"mx_RoomSettingsDialog_settingsIcon", | ||
<GeneralRoomSettingsTab roomId={this.props.roomId} />, | ||
<GeneralRoomSettingsTab room={this.state.room} />, | ||
"RoomSettingsGeneral", | ||
), | ||
); | ||
|
@@ -110,7 +138,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_VOIP_TAB, | ||
_td("Voice & Video"), | ||
"mx_RoomSettingsDialog_voiceIcon", | ||
<VoipRoomSettingsTab roomId={this.props.roomId} />, | ||
<VoipRoomSettingsTab room={this.state.room} />, | ||
), | ||
); | ||
} | ||
|
@@ -119,12 +147,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_SECURITY_TAB, | ||
_td("Security & Privacy"), | ||
"mx_RoomSettingsDialog_securityIcon", | ||
( | ||
<SecurityRoomSettingsTab | ||
roomId={this.props.roomId} | ||
closeSettingsFn={() => this.props.onFinished(true)} | ||
/> | ||
), | ||
<SecurityRoomSettingsTab room={this.state.room} closeSettingsFn={() => this.props.onFinished(true)} />, | ||
"RoomSettingsSecurityPrivacy", | ||
), | ||
); | ||
|
@@ -133,7 +156,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_ROLES_TAB, | ||
_td("Roles & Permissions"), | ||
"mx_RoomSettingsDialog_rolesIcon", | ||
<RolesRoomSettingsTab roomId={this.props.roomId} />, | ||
<RolesRoomSettingsTab room={this.state.room} />, | ||
"RoomSettingsRolesPermissions", | ||
), | ||
); | ||
|
@@ -144,7 +167,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
"mx_RoomSettingsDialog_notificationsIcon", | ||
( | ||
<NotificationSettingsTab | ||
roomId={this.props.roomId} | ||
roomId={this.state.room.roomId} | ||
closeSettingsFn={() => this.props.onFinished(true)} | ||
/> | ||
), | ||
|
@@ -158,7 +181,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_BRIDGES_TAB, | ||
_td("Bridges"), | ||
"mx_RoomSettingsDialog_bridgesIcon", | ||
<BridgeSettingsTab roomId={this.props.roomId} />, | ||
<BridgeSettingsTab room={this.state.room} />, | ||
"RoomSettingsBridges", | ||
), | ||
); | ||
|
@@ -169,7 +192,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
ROOM_POLL_HISTORY_TAB, | ||
_td("Poll history"), | ||
"mx_RoomSettingsDialog_pollsIcon", | ||
<PollHistoryTab roomId={this.props.roomId} onFinished={() => this.props.onFinished(true)} />, | ||
<PollHistoryTab room={this.state.room} onFinished={() => this.props.onFinished(true)} />, | ||
), | ||
); | ||
|
||
|
@@ -181,7 +204,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
"mx_RoomSettingsDialog_warningIcon", | ||
( | ||
<AdvancedRoomSettingsTab | ||
roomId={this.props.roomId} | ||
room={this.state.room} | ||
closeSettingsFn={() => this.props.onFinished(true)} | ||
/> | ||
), | ||
|
@@ -213,3 +236,11 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState> | |
); | ||
} | ||
} | ||
|
||
const WrappedRoomSettingsDialog: React.FC<IProps> = (props) => ( | ||
<ErrorBoundary> | ||
<RoomSettingsDialog {...props} /> | ||
</ErrorBoundary> | ||
); | ||
|
||
export default WrappedRoomSettingsDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the changes to this file. If we're storing the room in state though, couldn't we also remove the
roomName
from state and readthis.state.room.name
whereverthis.state.roomName
is currently used?I think the
onRoomName
method could possibly disappear then too