Skip to content

Commit f898986

Browse files
committed
Merge pull request element-hq#594 from vector-im/kegan/guest-access
Enable guest access
2 parents 8a156dc + a369c86 commit f898986

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎src/components/structures/RoomDirectory.js‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,27 @@ module.exports = React.createClass({
5656
});
5757
},
5858

59-
joinRoom: function(roomId) {
59+
joinRoom: function(roomId, shouldPeek) {
6060
var self = this;
6161
self.setState({ loading: true });
62-
// XXX: check that JS SDK suppresses duplicate attempts to join the same room
63-
MatrixClientPeg.get().joinRoom(roomId).done(function() {
62+
63+
var joinOrPeekPromise;
64+
65+
if (shouldPeek) {
66+
joinOrPeekPromise = MatrixClientPeg.get().peekInRoom(roomId);
67+
}
68+
else {
69+
joinOrPeekPromise = MatrixClientPeg.get().joinRoom(roomId);
70+
}
71+
72+
joinOrPeekPromise.done(function() {
6473
dis.dispatch({
6574
action: 'view_room',
6675
room_id: roomId
6776
});
6877
}, function(err) {
6978
console.error("Failed to join room: %s", JSON.stringify(err));
79+
console.error(err);
7080
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
7181
Modal.createDialog(ErrorDialog, {
7282
title: "Failed to join room",
@@ -87,13 +97,34 @@ module.exports = React.createClass({
8797
});
8898
var rows = [];
8999
var self = this;
100+
var guestRead, guestJoin;
90101
for (var i = 0; i < rooms.length; i++) {
91102
var name = rooms[i].name || rooms[i].aliases[0];
103+
guestRead = null;
104+
guestJoin = null;
105+
var shouldPeek = false;
106+
107+
if (rooms[i].world_readable) {
108+
guestRead = (
109+
<img src="img/members.svg"
110+
alt="World Readable" title="World Readable" width="12" height="12" />
111+
);
112+
if (MatrixClientPeg.get().isGuest() && !rooms[i].guest_can_join) {
113+
shouldPeek = true;
114+
}
115+
}
116+
if (rooms[i].guest_can_join) {
117+
guestJoin = (
118+
<img src="img/leave.svg"
119+
alt="Guests can join" title="Guests can join" width="12" height="12" />
120+
);
121+
}
122+
92123
// <img src={ MatrixClientPeg.get().getAvatarUrlForRoom(rooms[i].room_id, 40, 40, "crop") } width="40" height="40" alt=""/>
93124
rows.unshift(
94125
<tbody key={ rooms[i].room_id }>
95-
<tr onClick={self.joinRoom.bind(null, rooms[i].room_id)}>
96-
<td className="mx_RoomDirectory_name">{ name }</td>
126+
<tr onClick={self.joinRoom.bind(null, rooms[i].room_id, shouldPeek)}>
127+
<td className="mx_RoomDirectory_name">{ name } {guestRead} {guestJoin}</td>
97128
<td>{ rooms[i].aliases[0] }</td>
98129
<td>{ rooms[i].num_joined_members }</td>
99130
</tr>

‎src/vector/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ function loadApp() {
154154
registrationUrl={makeRegistrationUrl()}
155155
ConferenceHandler={VectorConferenceHandler}
156156
config={configJson}
157-
startingQueryParams={parseQsFromFragment(window.location)} />,
157+
startingQueryParams={parseQsFromFragment(window.location)}
158+
enableGuest={true} />,
158159
document.getElementById('matrixchat')
159160
);
160161
}

0 commit comments

Comments
 (0)