No longer persist guest room IDs. Replace with transient peeked room ID.
This commit is contained in:
parent
afbb451d4a
commit
29587ec347
2 changed files with 13 additions and 30 deletions
|
@ -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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {MatrixClientPeg} from "./MatrixClientPeg";
|
|
||||||
const ROOM_ID_KEY = "matrix-guest-room-ids";
|
|
||||||
const IS_GUEST_KEY = "matrix-is-guest";
|
const IS_GUEST_KEY = "matrix-is-guest";
|
||||||
|
|
||||||
class GuestAccess {
|
class GuestAccess {
|
||||||
|
|
||||||
constructor(localStorage) {
|
constructor(localStorage) {
|
||||||
var existingRoomIds;
|
this.localStorage = localStorage;
|
||||||
try {
|
try {
|
||||||
this._isGuest = localStorage.getItem(IS_GUEST_KEY) === "true";
|
this._isGuest = localStorage.getItem(IS_GUEST_KEY) === "true";
|
||||||
existingRoomIds = JSON.parse(
|
|
||||||
localStorage.getItem(ROOM_ID_KEY) // an array
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
catch (e) {} // don't care
|
catch (e) {} // don't care
|
||||||
this.rooms = new Set(existingRoomIds);
|
|
||||||
this.localStorage = localStorage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addRoom(roomId) {
|
setPeekedRoom(roomId) {
|
||||||
this.rooms.add(roomId);
|
// we purposefully do not persist this to local storage as peeking is
|
||||||
this._saveAndSetRooms();
|
// entirely transient.
|
||||||
|
this._peekedRoomId = roomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRoom(roomId) {
|
getPeekedRoom() {
|
||||||
this.rooms.delete(roomId);
|
return this._peekedRoomId;
|
||||||
this._saveAndSetRooms();
|
|
||||||
}
|
|
||||||
|
|
||||||
getRooms() {
|
|
||||||
return Array.from(this.rooms.entries());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isGuest() {
|
isGuest() {
|
||||||
|
@ -53,19 +42,9 @@ class GuestAccess {
|
||||||
markAsGuest(isGuest) {
|
markAsGuest(isGuest) {
|
||||||
try {
|
try {
|
||||||
this.localStorage.setItem(IS_GUEST_KEY, JSON.stringify(isGuest));
|
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.
|
} catch (e) {} // ignore. If they don't do LS, they'll just get a new account.
|
||||||
this._isGuest = isGuest;
|
this._isGuest = isGuest;
|
||||||
this.rooms = new Set();
|
this._peekedRoomId = null;
|
||||||
}
|
|
||||||
|
|
||||||
_saveAndSetRooms() {
|
|
||||||
let rooms = this.getRooms();
|
|
||||||
MatrixClientPeg.get().setGuestRooms(rooms);
|
|
||||||
try {
|
|
||||||
this.localStorage.setItem(ROOM_ID_KEY, rooms);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,11 @@ function createClient(hs_url, is_url, user_id, access_token, guestAccess) {
|
||||||
if (guestAccess) {
|
if (guestAccess) {
|
||||||
console.log("Guest: %s", guestAccess.isGuest());
|
console.log("Guest: %s", guestAccess.isGuest());
|
||||||
matrixClient.setGuest(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue