From 9ad3c96d431cb9d0789b76d9cb9e8846e4f19611 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Mon, 29 Jun 2026 11:30:33 +0200 Subject: [PATCH] fix: send stored history to IPC client on connect history_loaded events were fired when peers exchanged history gossip, but the browser UI often connects to the daemon after that handshake has already happened. Now the daemon pushes recent messages for all known rooms immediately after the state_snapshot on each new IPC connection, so the browser always gets history regardless of timing. Co-Authored-By: Claude Sonnet 4.6 --- internal/ipc/ipc.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/ipc/ipc.go b/internal/ipc/ipc.go index a3f1026..3a75ca0 100644 --- a/internal/ipc/ipc.go +++ b/internal/ipc/ipc.go @@ -127,6 +127,8 @@ func handleClient(conn net.Conn, mgr *netmgr.Manager) { // Send initial state snapshot. send(stateSnapshot(mgr)) + // Send stored history for each room so the UI is populated on connect. + sendStoredHistory(mgr, send) scanner := bufio.NewScanner(conn) for scanner.Scan() { @@ -462,6 +464,34 @@ func stateSnapshot(mgr *netmgr.Manager) proto.IpcMessage { return msg } +// sendStoredHistory pushes recent messages for all known rooms to a newly-connected IPC client. +func sendStoredHistory(mgr *netmgr.Manager, send func(proto.IpcMessage)) { + all := mgr.All() + if len(all) == 0 { + return + } + n := all[0] // use first network; multi-network history follows same pattern + if n.Store == nil { + return + } + rooms := []string{"general"} + if extra, err := n.Store.Rooms(); err == nil { + rooms = append(rooms, extra...) + } + for _, room := range rooms { + msgs, err := n.Store.RecentMessagesSince(room, 0, 200) + if err != nil || len(msgs) == 0 { + continue + } + send(proto.IpcMessage{ + Type: proto.EvtHistoryLoaded, + NetworkID: n.ID, + Room: room, + Messages: msgs, + }) + } +} + func errMsg(s string) proto.IpcMessage { return proto.IpcMessage{Type: proto.EvtError, ErrorMessage: s} }