From f71c200106e48af7c74678f46391695c13809989 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Mon, 2 Jun 2025 13:38:39 +1000 Subject: [PATCH] add room owner check to room manager --- excalidraw-app/data/roomManager.ts | 18 ++++++++++++++++++ excalidraw-app/share/ShareDialog.tsx | 19 ++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/excalidraw-app/data/roomManager.ts b/excalidraw-app/data/roomManager.ts index d3b5afa88..b3c2ff60d 100644 --- a/excalidraw-app/data/roomManager.ts +++ b/excalidraw-app/data/roomManager.ts @@ -176,6 +176,24 @@ class RoomManager { } } + async isRoomOwnedByUser(url: string): Promise { + try { + const rooms = await this.loadRooms(); + const _url = new URL(url); + const match = _url.hash.match(/room=([^,]+),([^&]+)/); + + if (!match) { + return false; + } + + const [, roomId] = match; + return rooms.some((room) => room.roomId === roomId); + } catch (error) { + console.warn("Failed to check room ownership:", error); + return false; + } + } + async getCurrentRoom(): Promise { const rooms = await this.loadRooms(); if (rooms.length === 0) { diff --git a/excalidraw-app/share/ShareDialog.tsx b/excalidraw-app/share/ShareDialog.tsx index 8f5d868d0..50b5cabe8 100644 --- a/excalidraw-app/share/ShareDialog.tsx +++ b/excalidraw-app/share/ShareDialog.tsx @@ -75,23 +75,12 @@ const ActiveRoomDialog = ({ const [isRoomOwner, setIsRoomOwner] = useState(false); useEffect(() => { roomManager - .getCurrentRoom() - .then((room) => { - if (room) { - const _room = new URL(activeRoomLink); - const match = _room.hash.match(/room=([^,]+),([^&]+)/); - if (match) { - const [, roomId] = match; - setIsRoomOwner(roomId === room.roomId); - } else { - setIsRoomOwner(false); - } - } else { - setIsRoomOwner(false); - } + .isRoomOwnedByUser(activeRoomLink) + .then((isOwned) => { + setIsRoomOwner(isOwned); }) .catch((error) => { - console.error("Error getting current room:", error); + console.warn("Failed to check room ownership:", error); setIsRoomOwner(false); }); }, [activeRoomLink]);