From 255ab49ccbbc65f7235460c83c9bebe59669d45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 7 Jul 2021 13:48:48 +0200 Subject: [PATCH] Handle edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/RoomDirectory.tsx | 28 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index c0fdcebc75..3892c9da5c 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -119,7 +119,29 @@ export default class RoomDirectory extends React.Component { } else if (!selectedCommunityId) { MatrixClientPeg.get().getThirdpartyProtocols().then((response) => { this.protocols = response; - this.setState({ protocolsLoading: false }); + const myHomeserver = MatrixClientPeg.getHomeserverName(); + const lsRoomServer = localStorage.getItem(LAST_SERVER_KEY); + const lsInstanceId = localStorage.getItem(LAST_INSTANCE_KEY); + const configSevers = SdkConfig.get().roomDirectory?.servers || []; + const roomServer = configSevers.includes(lsRoomServer) + ? lsRoomServer + : myHomeserver; + const instanceIds = []; + if (roomServer === myHomeserver) { + Object.values(this.protocols).forEach((protocol) => { + protocol.instances.forEach((instance) => instanceIds.push(instance.instance_id)); + }); + } + const instanceId = (instanceIds.includes(lsInstanceId) || lsInstanceId === ALL_ROOMS) + ? lsInstanceId + : null; + + this.setState({ + protocolsLoading: false, + instanceId: instanceId, + roomServer: roomServer, + }); + this.refreshRoomList(); }, (err) => { console.warn(`error loading third party protocols: ${err}`); this.setState({ protocolsLoading: false }); @@ -153,8 +175,8 @@ export default class RoomDirectory extends React.Component { publicRooms: [], loading: true, error: null, - instanceId: localStorage.getItem(LAST_INSTANCE_KEY), - roomServer: localStorage.getItem(LAST_SERVER_KEY) || MatrixClientPeg.getHomeserverName(), + instanceId: null, + roomServer: null, filterString: this.props.initialText || "", selectedCommunityId, communityName: null,