Hit MatrixClient.peekInRoom on rooms we can only peek into.

This commit is contained in:
Kegan Dougal 2016-01-07 14:57:26 +00:00
parent 1a8a4728cd
commit a369c862a0
1 changed files with 18 additions and 4 deletions

View File

@ -56,17 +56,27 @@ module.exports = React.createClass({
}); });
}, },
joinRoom: function(roomId) { joinRoom: function(roomId, shouldPeek) {
var self = this; var self = this;
self.setState({ loading: true }); self.setState({ loading: true });
// XXX: check that JS SDK suppresses duplicate attempts to join the same room
MatrixClientPeg.get().joinRoom(roomId).done(function() { var joinOrPeekPromise;
if (shouldPeek) {
joinOrPeekPromise = MatrixClientPeg.get().peekInRoom(roomId);
}
else {
joinOrPeekPromise = MatrixClientPeg.get().joinRoom(roomId);
}
joinOrPeekPromise.done(function() {
dis.dispatch({ dis.dispatch({
action: 'view_room', action: 'view_room',
room_id: roomId room_id: roomId
}); });
}, function(err) { }, function(err) {
console.error("Failed to join room: %s", JSON.stringify(err)); console.error("Failed to join room: %s", JSON.stringify(err));
console.error(err);
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, { Modal.createDialog(ErrorDialog, {
title: "Failed to join room", title: "Failed to join room",
@ -92,12 +102,16 @@ module.exports = React.createClass({
var name = rooms[i].name || rooms[i].aliases[0]; var name = rooms[i].name || rooms[i].aliases[0];
guestRead = null; guestRead = null;
guestJoin = null; guestJoin = null;
var shouldPeek = false;
if (rooms[i].world_readable) { if (rooms[i].world_readable) {
guestRead = ( guestRead = (
<img src="img/members.svg" <img src="img/members.svg"
alt="World Readable" title="World Readable" width="12" height="12" /> alt="World Readable" title="World Readable" width="12" height="12" />
); );
if (MatrixClientPeg.get().isGuest() && !rooms[i].guest_can_join) {
shouldPeek = true;
}
} }
if (rooms[i].guest_can_join) { if (rooms[i].guest_can_join) {
guestJoin = ( guestJoin = (
@ -109,7 +123,7 @@ module.exports = React.createClass({
// <img src={ MatrixClientPeg.get().getAvatarUrlForRoom(rooms[i].room_id, 40, 40, "crop") } width="40" height="40" alt=""/> // <img src={ MatrixClientPeg.get().getAvatarUrlForRoom(rooms[i].room_id, 40, 40, "crop") } width="40" height="40" alt=""/>
rows.unshift( rows.unshift(
<tbody key={ rooms[i].room_id }> <tbody key={ rooms[i].room_id }>
<tr onClick={self.joinRoom.bind(null, rooms[i].room_id)}> <tr onClick={self.joinRoom.bind(null, rooms[i].room_id, shouldPeek)}>
<td className="mx_RoomDirectory_name">{ name } {guestRead} {guestJoin}</td> <td className="mx_RoomDirectory_name">{ name } {guestRead} {guestJoin}</td>
<td>{ rooms[i].aliases[0] }</td> <td>{ rooms[i].aliases[0] }</td>
<td>{ rooms[i].num_joined_members }</td> <td>{ rooms[i].num_joined_members }</td>