From ca1313099f4db238374f281944710bccd1b2398d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 6 Dec 2018 11:45:58 -0700 Subject: [PATCH] Show the IncomingCallBox if the call is for the RoomSubList Fixes https://github.com/vector-im/riot-web/issues/4369 Previously the RoomSubList would filter its list of rooms to verify that the incoming call belongs to it. This causes problems when the sub list is being told some rooms don't exist (ie: the list is filtered). It is trivial for the RoomList to instead track which RoomSubList (tag) it should be handing the call off to so we do that instead now. The RoomSubList trusts that the caller has already filtered it and will render the IncomingCallBox if it has an incoming call. --- src/components/structures/RoomSubList.js | 15 +++----- src/components/views/rooms/RoomList.js | 45 +++++++++++++++++++----- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index d7980706596..cdeb8926c0b 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -327,17 +327,10 @@ const RoomSubList = React.createClass({ let incomingCall; if (this.props.incomingCall) { - const self = this; - // Check if the incoming call is for this section - const incomingCallRoom = this.props.list.filter(function(room) { - return self.props.incomingCall.roomId === room.roomId; - }); - - if (incomingCallRoom.length === 1) { - const IncomingCallBox = sdk.getComponent("voip.IncomingCallBox"); - incomingCall = - ; - } + // We can assume that if we have an incoming call then it is for this list + const IncomingCallBox = sdk.getComponent("voip.IncomingCallBox"); + incomingCall = + ; } const tabindex = this.props.searchFilter === "" ? "0" : "-1"; diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 3e632ba8ce0..3ad35c036d5 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -71,6 +71,7 @@ module.exports = React.createClass({ isLoadingLeftRooms: false, totalRoomCount: null, lists: {}, + incomingCallTag: null, incomingCall: null, selectedTags: [], }; @@ -155,11 +156,13 @@ module.exports = React.createClass({ if (call && call.call_state === 'ringing') { this.setState({ incomingCall: call, + incomingCallTag: this.getTagNameForRoomId(payload.room_id), }); this._repositionIncomingCallBox(undefined, true); } else { this.setState({ incomingCall: null, + incomingCallTag: null, }); } break; @@ -328,6 +331,26 @@ module.exports = React.createClass({ // this._lastRefreshRoomListTs = Date.now(); }, + getTagNameForRoomId: function(roomId) { + const lists = RoomListStore.getRoomLists(); + for (const tagName of Object.keys(lists)) { + for (const room of lists[tagName]) { + // Should be impossible, but guard anyways. + if (!room) { + continue; + } + const myUserId = MatrixClientPeg.get().getUserId(); + if (HIDE_CONFERENCE_CHANS && Rooms.isConfCallRoom(room, myUserId, this.props.ConferenceHandler)) { + continue; + } + + if (room.roomId === roomId) return tagName; + } + } + + return null; + }, + getRoomLists: function() { const lists = RoomListStore.getRoomLists(); @@ -621,6 +644,12 @@ module.exports = React.createClass({ // so checking on every render is the sanest thing at this time. const showEmpty = SettingsStore.getValue('RoomSubList.showEmpty'); + const incomingCallIfTaggedAs = (tagName) => { + if (!this.state.incomingCall) return null; + if (this.state.incomingCallTag !== tagName) return null; + return this.state.incomingCall; + }; + const self = this; return ( @@ -750,7 +779,7 @@ module.exports = React.createClass({ tagName="m.lowpriority" editable={false} order="recent" - incomingCall={self.state.incomingCall} + incomingCall={incomingCallIfTaggedAs('m.server_notice')} collapsed={self.props.collapsed} searchFilter={self.props.searchFilter} onHeaderClick={self.onSubListHeaderClick}