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 <noreply@anthropic.com>
This commit is contained in:
@@ -127,6 +127,8 @@ func handleClient(conn net.Conn, mgr *netmgr.Manager) {
|
|||||||
|
|
||||||
// Send initial state snapshot.
|
// Send initial state snapshot.
|
||||||
send(stateSnapshot(mgr))
|
send(stateSnapshot(mgr))
|
||||||
|
// Send stored history for each room so the UI is populated on connect.
|
||||||
|
sendStoredHistory(mgr, send)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(conn)
|
scanner := bufio.NewScanner(conn)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
@@ -462,6 +464,34 @@ func stateSnapshot(mgr *netmgr.Manager) proto.IpcMessage {
|
|||||||
return msg
|
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 {
|
func errMsg(s string) proto.IpcMessage {
|
||||||
return proto.IpcMessage{Type: proto.EvtError, ErrorMessage: s}
|
return proto.IpcMessage{Type: proto.EvtError, ErrorMessage: s}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user