Display new rooms as they arrive

This commit is contained in:
David Baker 2015-06-19 16:12:22 +01:00
parent 1270bc3c62
commit 41014af471
2 changed files with 12 additions and 0 deletions

View file

@ -8,6 +8,7 @@ var RoomTile = ComponentBroker.get("molecules/RoomTile");
module.exports = { module.exports = {
componentWillMount: function() { componentWillMount: function() {
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
cli.on("Room", this.onRoom);
cli.on("Room.timeline", this.onRoomTimeline); cli.on("Room.timeline", this.onRoomTimeline);
this.setState({ this.setState({
@ -18,6 +19,7 @@ module.exports = {
componentWillUnmount: function() { componentWillUnmount: function() {
if (MatrixClientPeg.get()) { if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Room", this.onRoom);
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline); MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
} }
}, },
@ -29,6 +31,13 @@ module.exports = {
}); });
}, },
onRoom: function(room) {
var cli = MatrixClientPeg.get();
this.setState({
roomList: cli.getRooms(),
});
},
onRoomTimeline: function(ev, room, toStartOfTimeline) { onRoomTimeline: function(ev, room, toStartOfTimeline) {
if (room.roomId == this.props.selectedRoom) return; if (room.roomId == this.props.selectedRoom) return;
if (ev.getSender() == MatrixClientPeg.get().credentials.userId) return; if (ev.getSender() == MatrixClientPeg.get().credentials.userId) return;
@ -51,6 +60,7 @@ module.exports = {
key={room.roomId} key={room.roomId}
selected={selected} selected={selected}
unread={that.state.activityMap[room.roomId] === 1} unread={that.state.activityMap[room.roomId] === 1}
highlight={that.state.activityMap[room.roomId] === 2}
/> />
); );
}); });

View file

@ -1,3 +1,5 @@
var React = require('react');
var MatrixClientPeg = require("../../MatrixClientPeg"); var MatrixClientPeg = require("../../MatrixClientPeg");
var Matrix = require("matrix-js-sdk"); var Matrix = require("matrix-js-sdk");