From 3d1ed04a70aff9c08b713392ac0a4d3856ae16e9 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 23 May 2024 12:00:56 -0500 Subject: [PATCH] =?UTF-8?q?[=F0=9F=90=B4]=20Do=20not=20init=20event=20bus?= =?UTF-8?q?=20if=20no=20session=20(#4193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Do not init event bus if no session * Be explicit * Simplify, fix log --- src/state/messages/events/index.tsx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/state/messages/events/index.tsx b/src/state/messages/events/index.tsx index 6bf79232..d972c8c6 100644 --- a/src/state/messages/events/index.tsx +++ b/src/state/messages/events/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import {AppState} from 'react-native' import {MessagesEventBus} from '#/state/messages/events/agent' -import {useAgent} from '#/state/session' +import {useAgent, useSession} from '#/state/session' const MessagesEventBusContext = React.createContext( null, @@ -11,7 +11,9 @@ const MessagesEventBusContext = React.createContext( export function useMessagesEventBus() { const ctx = React.useContext(MessagesEventBusContext) if (!ctx) { - throw new Error('useChat must be used within a ChatProvider') + throw new Error( + 'useMessagesEventBus must be used within a MessagesEventBusProvider', + ) } return ctx } @@ -20,6 +22,26 @@ export function MessagesEventBusProvider({ children, }: { children: React.ReactNode +}) { + const {currentAccount} = useSession() + + if (!currentAccount) { + return ( + + {children} + + ) + } + + return ( + {children} + ) +} + +export function MessagesEventBusProviderInner({ + children, +}: { + children: React.ReactNode }) { const {getAgent} = useAgent() const [bus] = React.useState(