From 29587ec347066886700ee8033e80d0d3855b808e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 6 Jan 2016 17:33:00 +0000 Subject: [PATCH] No longer persist guest room IDs. Replace with transient peeked room ID. --- src/GuestAccess.js | 37 ++++++++----------------------------- src/MatrixClientPeg.js | 6 +++++- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/GuestAccess.js b/src/GuestAccess.js index a76e198b4e..ef48d23ded 100644 --- a/src/GuestAccess.js +++ b/src/GuestAccess.js @@ -13,37 +13,26 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import {MatrixClientPeg} from "./MatrixClientPeg"; -const ROOM_ID_KEY = "matrix-guest-room-ids"; const IS_GUEST_KEY = "matrix-is-guest"; class GuestAccess { constructor(localStorage) { - var existingRoomIds; + this.localStorage = localStorage; try { this._isGuest = localStorage.getItem(IS_GUEST_KEY) === "true"; - existingRoomIds = JSON.parse( - localStorage.getItem(ROOM_ID_KEY) // an array - ); } catch (e) {} // don't care - this.rooms = new Set(existingRoomIds); - this.localStorage = localStorage; } - addRoom(roomId) { - this.rooms.add(roomId); - this._saveAndSetRooms(); + setPeekedRoom(roomId) { + // we purposefully do not persist this to local storage as peeking is + // entirely transient. + this._peekedRoomId = roomId; } - removeRoom(roomId) { - this.rooms.delete(roomId); - this._saveAndSetRooms(); - } - - getRooms() { - return Array.from(this.rooms.entries()); + getPeekedRoom() { + return this._peekedRoomId; } isGuest() { @@ -53,19 +42,9 @@ class GuestAccess { markAsGuest(isGuest) { try { this.localStorage.setItem(IS_GUEST_KEY, JSON.stringify(isGuest)); - // nuke the rooms being watched from previous guest accesses if any. - this.localStorage.setItem(ROOM_ID_KEY, "[]"); } catch (e) {} // ignore. If they don't do LS, they'll just get a new account. this._isGuest = isGuest; - this.rooms = new Set(); - } - - _saveAndSetRooms() { - let rooms = this.getRooms(); - MatrixClientPeg.get().setGuestRooms(rooms); - try { - this.localStorage.setItem(ROOM_ID_KEY, rooms); - } catch (e) {} + this._peekedRoomId = null; } } diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 76fa102562..f250333461 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -51,7 +51,11 @@ function createClient(hs_url, is_url, user_id, access_token, guestAccess) { if (guestAccess) { console.log("Guest: %s", guestAccess.isGuest()); matrixClient.setGuest(guestAccess.isGuest()); - matrixClient.setGuestRooms(guestAccess.getRooms()); + var peekedRoomId = guestAccess.getPeekedRoom(); + if (peekedRoomId) { + console.log("Peeking in room %s", peekedRoomId); + matrixClient.peekInRoom(peekedRoomId); + } } }