feat: TUI room creation + daemon-side room persistence

/room <name> in the TUI sends create_room to the daemon, which persists
it in the rooms SQLite table and echoes room_created back. state_snapshot
now includes persisted rooms so they survive reconnects. Tab navigation
and room rendering pick them up automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-26 22:26:12 +02:00
parent 1308082c7b
commit 340735f992
4 changed files with 73 additions and 1 deletions

View File

@@ -251,8 +251,15 @@ func (m model) applyEvent(evt proto.IpcMessage) model {
m.peers[p.ID] = p.Alias
m.peerOrder = append(m.peerOrder, p.ID)
}
for _, r := range evt.Rooms {
m = m.addRoom(r)
}
m.status = fmt.Sprintf("● %s · %s", m.localAlias, m.networkName)
case proto.EvtRoomCreated:
m = m.addRoom(evt.Room)
m = m.refreshViewport()
case proto.EvtSessionReady:
if evt.PeerID != nil {
pid := *evt.PeerID
@@ -309,6 +316,14 @@ func (m model) doSend(cmds []tea.Cmd) (model, []tea.Cmd) {
}
m.input.SetValue("")
if strings.HasPrefix(body, "/room ") {
name := strings.TrimSpace(strings.TrimPrefix(body, "/room "))
if name != "" {
cmds = append(cmds, sendIPC(m.enc, proto.IpcMessage{Type: proto.CmdCreateRoom, Room: name}))
}
return m, cmds
}
room := m.rooms[m.activeRoom]
ipcMsg := proto.IpcMessage{Type: proto.CmdSendMessage, Room: room, Body: body}
if strings.HasPrefix(room, "dm:") {
@@ -430,7 +445,7 @@ func (m model) View() string {
if m.errMsg != "" {
statusLine = styleErr.Render(" ✗ " + m.errMsg)
} else {
hint := " tab: rooms · ctrl+i: invite · ctrl+c: quit"
hint := " tab: rooms · /room <name>: new room · ctrl+i: invite · ctrl+c: quit"
statusLine = styleStatus.Width(m.width).Render(" " + m.status + hint)
}