Merge pull request #5180 from matrix-org/t3chguy/fix/15123
null-guard roomId in RightPanel and pass Room to UserView
This commit is contained in:
commit
83c2ae2479
2 changed files with 10 additions and 11 deletions
|
@ -225,11 +225,12 @@ export default class RightPanel extends React.Component {
|
||||||
const GroupRoomInfo = sdk.getComponent('groups.GroupRoomInfo');
|
const GroupRoomInfo = sdk.getComponent('groups.GroupRoomInfo');
|
||||||
|
|
||||||
let panel = <div />;
|
let panel = <div />;
|
||||||
|
const roomId = this.props.room ? this.props.room.roomId : undefined;
|
||||||
|
|
||||||
switch (this.state.phase) {
|
switch (this.state.phase) {
|
||||||
case RightPanelPhases.RoomMemberList:
|
case RightPanelPhases.RoomMemberList:
|
||||||
if (this.props.room.roomId) {
|
if (roomId) {
|
||||||
panel = <MemberList roomId={this.props.room.roomId} key={this.props.room.roomId} />;
|
panel = <MemberList roomId={roomId} key={roomId} />;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RightPanelPhases.GroupMemberList:
|
case RightPanelPhases.GroupMemberList:
|
||||||
|
@ -244,8 +245,8 @@ export default class RightPanel extends React.Component {
|
||||||
case RightPanelPhases.EncryptionPanel:
|
case RightPanelPhases.EncryptionPanel:
|
||||||
panel = <UserInfo
|
panel = <UserInfo
|
||||||
user={this.state.member}
|
user={this.state.member}
|
||||||
roomId={this.props.room.roomId}
|
room={this.props.room}
|
||||||
key={this.props.room.roomId || this.state.member.userId}
|
key={roomId || this.state.member.userId}
|
||||||
onClose={this.onCloseUserInfo}
|
onClose={this.onCloseUserInfo}
|
||||||
phase={this.state.phase}
|
phase={this.state.phase}
|
||||||
verificationRequest={this.state.verificationRequest}
|
verificationRequest={this.state.verificationRequest}
|
||||||
|
@ -253,7 +254,7 @@ export default class RightPanel extends React.Component {
|
||||||
/>;
|
/>;
|
||||||
break;
|
break;
|
||||||
case RightPanelPhases.Room3pidMemberInfo:
|
case RightPanelPhases.Room3pidMemberInfo:
|
||||||
panel = <ThirdPartyMemberInfo event={this.state.event} key={this.props.room.roomId} />;
|
panel = <ThirdPartyMemberInfo event={this.state.event} key={roomId} />;
|
||||||
break;
|
break;
|
||||||
case RightPanelPhases.GroupMemberInfo:
|
case RightPanelPhases.GroupMemberInfo:
|
||||||
panel = <UserInfo
|
panel = <UserInfo
|
||||||
|
@ -272,7 +273,7 @@ export default class RightPanel extends React.Component {
|
||||||
panel = <NotificationPanel />;
|
panel = <NotificationPanel />;
|
||||||
break;
|
break;
|
||||||
case RightPanelPhases.FilePanel:
|
case RightPanelPhases.FilePanel:
|
||||||
panel = <FilePanel roomId={this.props.room.roomId} resizeNotifier={this.props.resizeNotifier} />;
|
panel = <FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} />;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ limitations under the License.
|
||||||
import React, {useCallback, useMemo, useState, useEffect, useContext} from 'react';
|
import React, {useCallback, useMemo, useState, useEffect, useContext} from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {Group, RoomMember, User} from 'matrix-js-sdk';
|
import {Group, RoomMember, User, Room} from 'matrix-js-sdk';
|
||||||
import dis from '../../../dispatcher/dispatcher';
|
import dis from '../../../dispatcher/dispatcher';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import * as sdk from '../../../index';
|
import * as sdk from '../../../index';
|
||||||
|
@ -1471,11 +1471,9 @@ const UserInfoHeader = ({onClose, member, e2eStatus}) => {
|
||||||
</React.Fragment>;
|
</React.Fragment>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const UserInfo = ({user, groupId, roomId, onClose, phase=RightPanelPhases.RoomMemberInfo, ...props}) => {
|
const UserInfo = ({user, groupId, room, onClose, phase=RightPanelPhases.RoomMemberInfo, ...props}) => {
|
||||||
const cli = useContext(MatrixClientContext);
|
const cli = useContext(MatrixClientContext);
|
||||||
|
|
||||||
// Load room if we are given a room id and memoize it - this can be undefined for User Info/Group Member Info
|
|
||||||
const room = useMemo(() => roomId ? cli.getRoom(roomId) : null, [cli, roomId]);
|
|
||||||
// fetch latest room member if we have a room, so we don't show historical information, falling back to user
|
// fetch latest room member if we have a room, so we don't show historical information, falling back to user
|
||||||
const member = useMemo(() => room ? (room.getMember(user.userId) || user) : user, [room, user]);
|
const member = useMemo(() => room ? (room.getMember(user.userId) || user) : user, [room, user]);
|
||||||
|
|
||||||
|
@ -1529,7 +1527,7 @@ UserInfo.propTypes = {
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
group: PropTypes.instanceOf(Group),
|
group: PropTypes.instanceOf(Group),
|
||||||
groupId: PropTypes.string,
|
groupId: PropTypes.string,
|
||||||
roomId: PropTypes.string,
|
room: PropTypes.instanceOf(Room),
|
||||||
|
|
||||||
onClose: PropTypes.func,
|
onClose: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue