From a5cdb11518eeb267c31ec5ab25d5eae1d20cc720 Mon Sep 17 00:00:00 2001 From: Rexogamer Date: Sat, 28 Oct 2023 06:40:23 +0100 Subject: [PATCH] fix: open the home screen if the current server is deleted externally --- App.tsx | 7 +++++++ src/Generic.tsx | 3 +++ src/SideMenus.tsx | 3 +++ 3 files changed, 13 insertions(+) diff --git a/App.tsx b/App.tsx index 60090a80..c426a055 100644 --- a/App.tsx +++ b/App.tsx @@ -293,6 +293,13 @@ class MainView extends React.Component { } } }); + client.on('server/delete', async s => { + const currentServer = app.getCurrentServer(); + if (currentServer === s) { + app.openServer(undefined); + app.openChannel(null); + } + }); AsyncStorage.getItem('token', async (err, res) => { if (!err) { if (typeof res !== 'string') { diff --git a/src/Generic.tsx b/src/Generic.tsx index 3a7bafd3..647cb060 100644 --- a/src/Generic.tsx +++ b/src/Generic.tsx @@ -291,6 +291,9 @@ export const app = { openInvite: i => {}, openBotInvite: i => {}, openServer: (s?: Server) => {}, + getCurrentServer: () => { + return undefined as string | undefined; + }, openChannel: c => {}, openDirectMessage: (c: Channel) => {}, openImage: a => {}, diff --git a/src/SideMenus.tsx b/src/SideMenus.tsx index 48b3c765..413214a6 100644 --- a/src/SideMenus.tsx +++ b/src/SideMenus.tsx @@ -31,6 +31,9 @@ export const LeftMenu = ({ setCurrentServerInner(s); AsyncStorage.setItem('lastServer', s?._id || 'DirectMessage'); } + setFunction('getCurrentServer', () => { + return currentServer?._id ?? undefined; + }) setFunction('openServer', (s: Server | null) => { setCurrentServer(s); });