factor out the peek rule calculation so that we can do it both onNewRoom and if there's a room already. I guess we could do it in react's onStateUpdate too

This commit is contained in:
Matthew Hodgson 2016-01-18 20:05:33 +00:00
parent eb7144ef85
commit f22519f10c

View file

@ -115,7 +115,8 @@ module.exports = React.createClass({
// We can't try to /join because this may implicitly accept invites (!)
// We can /peek though. If it fails then we present the join UI. If it
// succeeds then great, show the preview (but we still may be able to /join!).
if (!this.state.room && this.props.autoPeek) {
if (!this.state.room) {
if (this.props.autoPeek) {
console.log("Attempting to peek into room %s", this.props.roomId);
MatrixClientPeg.get().peekInRoom(this.props.roomId).done(() => {
this.setState({
@ -125,14 +126,16 @@ module.exports = React.createClass({
// we don't need to do anything - JS SDK will emit Room events
// which will update the UI. We *do* however need to know if we
// can join the room so we can fiddle with the UI appropriately.
var peekedRoom = MatrixClientPeg.get().getRoom(this.props.roomId);
if (!peekedRoom) {
return;
}
// ...XXX: or do we? can't we just do them onNewRoom?
}, function(err) {
console.error("Failed to peek into room: %s", err);
});
}
}
else {
this._calculatePeekRules(this.state.room);
}
},
componentWillUnmount: function() {
@ -284,7 +287,12 @@ module.exports = React.createClass({
this.setState({
room: room
});
}
this._calculatePeekRules(room);
},
_calculatePeekRules: function(room) {
var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", "");
if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") {
this.setState({
@ -298,7 +306,6 @@ module.exports = React.createClass({
canPeek: true
});
}
}
},
onRoomName: function(room) {