diff --git a/lib/client.js b/lib/client.js index 3172a9f2b..2440ac44e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1946,6 +1946,34 @@ MatrixClient.prototype.setGuestRooms = function(roomIds) { this._guestRooms = roomIds; }; +/** + * Set r/w flags for guest access in a room. + * @param {string} roomId The room to configure guest access in. + * @param {Object} opts Options + * @param {boolean} opts.allowJoin True to allow guests to join this room. This + * implicitly gives guests write access. If false or not given, guests are + * explicitly forbidden from joining the room. + * @param {boolean} opts.allowRead True to set history visibility to + * be world_readable. This gives guests read access *from this point forward*. + * If false or not given, history visibility is not modified. + * @return {module:client.Promise} Resolves: TODO + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype.setGuestAccess = function(roomId, opts) { + var writePromise = this.sendStateEvent(roomId, "m.room.guest_access", { + guest_access: opts.allowJoin ? "can_join" : "forbidden" + }); + + var readPromise = q(); + if (opts.allowRead) { + readPromise = this.sendStateEvent(roomId, "m.room.history_visibility", { + history_visibility: "world_readable" + }); + } + + return q.all(readPromise, writePromise); +}; + /** * @param {string} username * @param {string} password diff --git a/lib/sync.js b/lib/sync.js index 10b68ffc4..58b4c3239 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -546,6 +546,9 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, room.addEventsToTimeline(timelineEventList); }; +/** + * @return {string} + */ SyncApi.prototype._getGuestFilter = function() { var guestRooms = this.client._guestRooms; // FIXME: horrible gut-wrenching if (!guestRooms) {