From e1271ad86fbacd51fd24dd41d247518ed061c735 Mon Sep 17 00:00:00 2001 From: gdbroman <99gustaf@gmail.com> Date: Tue, 18 Jul 2023 19:50:38 +0200 Subject: [PATCH] Delete lingering room (Standalone bug) --- .../StandaloneChat/StandaloneChatRoom.tsx | 25 +++++++++++-------- .../StartRoomButton/StartRoomButton.tsx | 7 ++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/renderer/apps/StandaloneChat/StandaloneChatRoom.tsx b/app/src/renderer/apps/StandaloneChat/StandaloneChatRoom.tsx index 91591d6641..e856f98d83 100644 --- a/app/src/renderer/apps/StandaloneChat/StandaloneChatRoom.tsx +++ b/app/src/renderer/apps/StandaloneChat/StandaloneChatRoom.tsx @@ -1,4 +1,4 @@ -import { useEffect } from 'react'; +import { MouseEvent, useEffect } from 'react'; import { observer } from 'mobx-react'; import { @@ -39,6 +39,18 @@ const StandaloneChatRoomPresenter = () => { const creatorStr = creator.length > 14 ? `${creator.substring(0, 14)}...` : creator; + const onClickLeaveRoom = (e: MouseEvent) => { + e.stopPropagation(); + + chatStore.setSubroute('chat'); + roomsStore.leaveRoom(rid); + + // Delete room if we're the creator or the last person in the room. + if (creator === loggedInAccount?.serverId || presentCount === 0) { + roomsStore.deleteRoom(rid); + } + }; + return ( { icon="RoomLeave" size={22} customBg="intent-alert" - onClick={(evt) => { - evt.stopPropagation(); - if (creator === loggedInAccount?.serverId) { - roomsStore.deleteRoom(rid); - chatStore.setSubroute('chat'); - } else { - roomsStore.leaveRoom(rid); - chatStore.setSubroute('chat'); - } - }} + onClick={onClickLeaveRoom} /> { // LEAVE OTHER ROOM sound.playRoomLeave(); roomsStore.leaveRoom(roomsStore.currentRoom.rid); + // DELETE OTHER ROOM IF EMPTY + if (roomsStore.currentRoom?.present.length === 0) { + roomsStore.deleteRoom(roomsStore.currentRoom.rid); + } } if (existingRoom) { if (areWeInRoom) { - sound.playRoomLeave(); // LEAVE ROOM sound.playRoomLeave(); roomsStore.leaveRoom(existingRoom.rid); if (subroute === 'room') setSubroute('chat'); + // DELETE ROOM IF EMPTY if (existingRoom?.present.length === 0) { - // DELETE ROOM roomsStore.deleteRoom(existingRoom.rid); } } else {