From d886c0b39cc66a2747321c6fd5048597b24eb7b8 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 13 Dec 2022 17:55:07 +1300 Subject: [PATCH 1/4] remove async call to get virtual room from room load --- src/components/structures/RoomView.tsx | 31 ++++++++++----------- src/components/structures/TimelinePanel.tsx | 5 ++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index acf9d4b7175..e124757d224 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -658,12 +658,7 @@ export class RoomView extends React.Component { // NB: This does assume that the roomID will not change for the lifetime of // the RoomView instance if (initial) { - const virtualRoom = newState.roomId - ? await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(newState.roomId) - : undefined; - newState.room = this.context.client!.getRoom(newState.roomId) || undefined; - newState.virtualRoom = virtualRoom || undefined; if (newState.room) { newState.showApps = this.shouldShowApps(newState.room); this.onRoomLoaded(newState.room); @@ -1208,6 +1203,14 @@ export class RoomView extends React.Component { return this.messagePanel.canResetTimeline(); }; + private loadVirtualRoom = async (room?: Room): Promise => { + const virtualRoom = room?.roomId + ? await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room?.roomId) + : undefined; + + this.setState({ virtualRoom }); + }; + // called when state.room is first initialised (either at initial load, // after a successful peek, or after we join the room). private onRoomLoaded = (room: Room) => { @@ -1222,6 +1225,7 @@ export class RoomView extends React.Component { this.updateE2EStatus(room); this.updatePermissions(room); this.checkWidgets(room); + this.loadVirtualRoom(room); if ( this.getMainSplitContentType(room) !== MainSplitContentType.Timeline && @@ -1288,7 +1292,7 @@ export class RoomView extends React.Component { }); } - private onRoom = async (room: Room) => { + private onRoom = (room: Room) => { if (!room || room.roomId !== this.state.roomId) { return; } @@ -1301,16 +1305,11 @@ export class RoomView extends React.Component { ); } - const virtualRoom = await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room.roomId); - this.setState( - { - room: room, - virtualRoom: virtualRoom || undefined, - }, - () => { - this.onRoomLoaded(room); - }, - ); + this.setState({ + room: room, + }, () => { + this.onRoomLoaded(room); + }); }; private onDeviceVerificationChanged = (userId: string) => { diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index 960ca7625c9..9f3e4f9c83b 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -342,6 +342,11 @@ class TimelinePanel extends React.Component { const differentEventId = prevProps.eventId != this.props.eventId; const differentHighlightedEventId = prevProps.highlightedEventId != this.props.highlightedEventId; const differentAvoidJump = prevProps.eventScrollIntoView && !this.props.eventScrollIntoView; + const differentOverlayTimeline = prevProps.overlayTimelineSet !== this.props.overlayTimelineSet; + if (differentOverlayTimeline) { + logger.log(`TimelinePanel updating overlay timeline.`); + this.initTimeline(this.props); + } if (differentEventId || differentHighlightedEventId || differentAvoidJump) { logger.log( `TimelinePanel switching to eventId ${this.props.eventId} (was ${prevProps.eventId}), ` + From 3315cc4f77b1d0ee0f0c340429ba547599ad0a81 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 13 Dec 2022 17:59:40 +1300 Subject: [PATCH 2/4] dont init timeline twice when overlay and focused event both change --- src/components/structures/TimelinePanel.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index 9f3e4f9c83b..a066272bdbb 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -343,16 +343,15 @@ class TimelinePanel extends React.Component { const differentHighlightedEventId = prevProps.highlightedEventId != this.props.highlightedEventId; const differentAvoidJump = prevProps.eventScrollIntoView && !this.props.eventScrollIntoView; const differentOverlayTimeline = prevProps.overlayTimelineSet !== this.props.overlayTimelineSet; - if (differentOverlayTimeline) { - logger.log(`TimelinePanel updating overlay timeline.`); - this.initTimeline(this.props); - } if (differentEventId || differentHighlightedEventId || differentAvoidJump) { logger.log( `TimelinePanel switching to eventId ${this.props.eventId} (was ${prevProps.eventId}), ` + `scrollIntoView: ${this.props.eventScrollIntoView} (was ${prevProps.eventScrollIntoView})`, ); this.initTimeline(this.props); + } else if (differentOverlayTimeline) { + logger.log(`TimelinePanel updating overlay timeline.`); + this.initTimeline(this.props); } } From 4be94dacd7fce0d9f35253e36df3617c60695697 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 13 Dec 2022 18:15:06 +1300 Subject: [PATCH 3/4] strict error --- src/components/structures/RoomView.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index e124757d224..e6754d35c6e 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1204,11 +1204,9 @@ export class RoomView extends React.Component { }; private loadVirtualRoom = async (room?: Room): Promise => { - const virtualRoom = room?.roomId - ? await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room?.roomId) - : undefined; + const virtualRoom = room?.roomId && await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room?.roomId); - this.setState({ virtualRoom }); + this.setState({ virtualRoom: virtualRoom || undefined }); }; // called when state.room is first initialised (either at initial load, From 3aef84d2dd39d789673c935a568a8e1a3e217131 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 13 Dec 2022 18:44:59 +1300 Subject: [PATCH 4/4] prettier --- src/components/structures/RoomView.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index e6754d35c6e..ef57465d3b8 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1204,7 +1204,7 @@ export class RoomView extends React.Component { }; private loadVirtualRoom = async (room?: Room): Promise => { - const virtualRoom = room?.roomId && await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room?.roomId); + const virtualRoom = room?.roomId && (await VoipUserMapper.sharedInstance().getVirtualRoomForRoom(room?.roomId)); this.setState({ virtualRoom: virtualRoom || undefined }); }; @@ -1303,11 +1303,14 @@ export class RoomView extends React.Component { ); } - this.setState({ - room: room, - }, () => { - this.onRoomLoaded(room); - }); + this.setState( + { + room: room, + }, + () => { + this.onRoomLoaded(room); + }, + ); }; private onDeviceVerificationChanged = (userId: string) => {