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,23 +115,26 @@ 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) {
console.log("Attempting to peek into room %s", this.props.roomId); if (this.props.autoPeek) {
MatrixClientPeg.get().peekInRoom(this.props.roomId).done(() => { console.log("Attempting to peek into room %s", this.props.roomId);
this.setState({ MatrixClientPeg.get().peekInRoom(this.props.roomId).done(() => {
autoPeekDone: true this.setState({
}); autoPeekDone: true
});
// 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) {
} console.error("Failed to peek into room: %s", err);
}, function(err) { });
console.error("Failed to peek into room: %s", err); }
}); }
else {
this._calculatePeekRules(this.state.room);
} }
}, },
@ -284,20 +287,24 @@ module.exports = React.createClass({
this.setState({ this.setState({
room: room room: room
}); });
}
var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", ""); this._calculatePeekRules(room);
if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") { },
this.setState({
guestsCanJoin: true
});
}
var historyVisibility = room.currentState.getStateEvents("m.room.history_visibility", ""); _calculatePeekRules: function(room) {
if (historyVisibility && historyVisibility.getContent().history_visibility === "world_readable") { var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", "");
this.setState({ if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") {
canPeek: true this.setState({
}); guestsCanJoin: true
} });
}
var historyVisibility = room.currentState.getStateEvents("m.room.history_visibility", "");
if (historyVisibility && historyVisibility.getContent().history_visibility === "world_readable") {
this.setState({
canPeek: true
});
} }
}, },