@@ -55,12 +55,14 @@ interface RemoteSessionProps {
5555 host : string ;
5656 password : string ;
5757 protocol ?: Protocol ;
58+ /** ID of the last viewed chat — used to restore the previous chat on reconnect. */
59+ lastChatId ?: string ;
5860 onStatusChange : ( status : SessionStatus , error ?: string ) => void ;
5961 /** Called when the bridge instance changes (connected or disconnected). */
6062 onBridgeChange ?: ( bridge : WebBridge | null ) => void ;
6163}
6264
63- export function RemoteSession ( { host, password, protocol, onStatusChange, onBridgeChange } : RemoteSessionProps ) {
65+ export function RemoteSession ( { host, password, protocol, lastChatId , onStatusChange, onBridgeChange } : RemoteSessionProps ) {
6466 const [ state , setState ] = useState <
6567 | { status : 'connecting' }
6668 | { status : 'connected' }
@@ -72,6 +74,8 @@ export function RemoteSession({ host, password, protocol, onStatusChange, onBrid
7274
7375 const bridgeRef = useRef < WebBridge | null > ( null ) ;
7476 const mountedRef = useRef ( true ) ;
77+ const lastChatIdRef = useRef ( lastChatId ) ;
78+ lastChatIdRef . current = lastChatId ;
7579 const onStatusChangeRef = useRef ( onStatusChange ) ;
7680 const onBridgeChangeRef = useRef ( onBridgeChange ) ;
7781 onStatusChangeRef . current = onStatusChange ;
@@ -85,7 +89,7 @@ export function RemoteSession({ host, password, protocol, onStatusChange, onBrid
8589 // Disconnect any existing bridge
8690 bridgeRef . current ?. disconnect ( ) ;
8791
88- const bridge = new WebBridge ( host , password , protocol ) ;
92+ const bridge = new WebBridge ( host , password , protocol , lastChatIdRef . current ) ;
8993 bridgeRef . current = bridge ;
9094
9195 // Subscribe to reconnection events
0 commit comments