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'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 // 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!). // 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); console.log("Attempting to peek into room %s", this.props.roomId);
MatrixClientPeg.get().peekInRoom(this.props.roomId).done(() => { MatrixClientPeg.get().peekInRoom(this.props.roomId).done(() => {
this.setState({ this.setState({
@ -125,14 +126,16 @@ module.exports = React.createClass({
// we don't need to do anything - JS SDK will emit Room events // 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 // 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. // can join the room so we can fiddle with the UI appropriately.
var peekedRoom = MatrixClientPeg.get().getRoom(this.props.roomId);
if (!peekedRoom) { // ...XXX: or do we? can't we just do them onNewRoom?
return;
}
}, function(err) { }, function(err) {
console.error("Failed to peek into room: %s", err); console.error("Failed to peek into room: %s", err);
}); });
} }
}
else {
this._calculatePeekRules(this.state.room);
}
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
@ -284,7 +287,12 @@ module.exports = React.createClass({
this.setState({ this.setState({
room: room room: room
}); });
}
this._calculatePeekRules(room);
},
_calculatePeekRules: function(room) {
var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", ""); var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", "");
if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") { if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") {
this.setState({ this.setState({
@ -298,7 +306,6 @@ module.exports = React.createClass({
canPeek: true canPeek: true
}); });
} }
}
}, },
onRoomName: function(room) { onRoomName: function(room) {