From 43efa29ef8d284da1286867fb48525166196bd52 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 7 Nov 2018 13:25:42 +0100 Subject: [PATCH] track active room with OpenRoomsStore --- src/ActiveRoomObserver.js | 15 ++++++++------- src/components/views/rooms/RoomTile.js | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ActiveRoomObserver.js b/src/ActiveRoomObserver.js index d6fbb460b5..ee3212f611 100644 --- a/src/ActiveRoomObserver.js +++ b/src/ActiveRoomObserver.js @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -import RoomViewStore from './stores/RoomViewStore'; +import OpenRoomsStore from './stores/OpenRoomsStore'; /** - * Consumes changes from the RoomViewStore and notifies specific things + * Consumes changes from the OpenRoomsStore and notifies specific things * about when the active room changes. Unlike listening for RoomViewStore * changes, you can subscribe to only changes relevant to a particular * room. @@ -28,11 +28,11 @@ import RoomViewStore from './stores/RoomViewStore'; class ActiveRoomObserver { constructor() { this._listeners = {}; - - this._activeRoomId = RoomViewStore.getRoomId(); + const roomStore = OpenRoomsStore.getCurrentRoomStore(); + this._activeRoomId = roomStore && roomStore.getRoomId(); // TODO: We could self-destruct when the last listener goes away, or at least // stop listening. - this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate.bind(this)); + this._roomStoreToken = OpenRoomsStore.addListener(this._onOpenRoomsStoreUpdate.bind(this)); } addListener(roomId, listener) { @@ -59,12 +59,13 @@ class ActiveRoomObserver { } } - _onRoomViewStoreUpdate() { + _onOpenRoomsStoreUpdate() { // emit for the old room ID if (this._activeRoomId) this._emit(this._activeRoomId); + const activeRoomStore = OpenRoomsStore.getCurrentRoomStore(); // update our cache - this._activeRoomId = RoomViewStore.getRoomId(); + this._activeRoomId = activeRoomStore && activeRoomStore.getRoomId(); // and emit for the new one if (this._activeRoomId) this._emit(this._activeRoomId); diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js index faa08c7001..71be2df5a4 100644 --- a/src/components/views/rooms/RoomTile.js +++ b/src/components/views/rooms/RoomTile.js @@ -116,9 +116,9 @@ module.exports = React.createClass({ } }, - _onActiveRoomChange: function() { + _onActiveRoomChange: function(activeRoomId) { this.setState({ - selected: this.props.room.roomId === RoomViewStore.getRoomId(), + selected: this.props.room.roomId === activeRoomId, }); },