Open chats: the server moves a restarted chat (/new) to its new session
The server-stored open-chat set kept a /new'd chat's old session unless the restarting device's own write landed, so another device (the phone) came back to the old conversation. chat_new_session now replaces the session in the stored set in place (position and floating kept) and pushes the new revision to every connection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -177,3 +177,47 @@ func (s *Store) RemoveChatOpenWorkspaceSessions(ctx context.Context, scope strin
|
||||
}
|
||||
return next, true, nil
|
||||
}
|
||||
|
||||
// ReplaceChatOpenWorkspaceSession moves an open chat to its new session id
|
||||
// (the composer's /new) in place, keeping its position and floating flag. If
|
||||
// the new id is already open, the old entry is dropped instead. Nothing is
|
||||
// stored when the old id is not open.
|
||||
func (s *Store) ReplaceChatOpenWorkspaceSession(ctx context.Context, scope, oldID, newID string) (snapshot protocol.ChatOpenWorkspaceSnapshot, changed bool, err error) {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return snapshot, false, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
current, err := readOpenWorkspace(ctx, tx, scope)
|
||||
if err != nil || current.Revision == 0 || oldID == newID {
|
||||
return current, false, err
|
||||
}
|
||||
present := false
|
||||
for _, entry := range current.Entries {
|
||||
if entry.SessionID == newID {
|
||||
present = true
|
||||
}
|
||||
}
|
||||
next := make([]protocol.ChatOpenWorkspaceEntry, 0, len(current.Entries))
|
||||
for _, entry := range current.Entries {
|
||||
if entry.SessionID == oldID {
|
||||
changed = true
|
||||
if present {
|
||||
continue
|
||||
}
|
||||
entry.SessionID = newID
|
||||
}
|
||||
next = append(next, entry)
|
||||
}
|
||||
if !changed {
|
||||
return current, false, nil
|
||||
}
|
||||
snapshot = protocol.ChatOpenWorkspaceSnapshot{Revision: current.Revision + 1, Entries: next}
|
||||
if err := writeOpenWorkspace(ctx, tx, scope, snapshot.Revision, next); err != nil {
|
||||
return protocol.ChatOpenWorkspaceSnapshot{}, false, err
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return protocol.ChatOpenWorkspaceSnapshot{}, false, err
|
||||
}
|
||||
return snapshot, true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user