part of 'chat_shell_runs_controller.dart'; /// Dismissing finished command cards for every client of the chat, and the /// Undo that restores them while the server still keeps them. extension ChatShellRunsDismissal on ChatShellRunsController { /// Dismisses finished runs [ids] for every client of the chat: their cards /// go at once and come back (with the refusal) if the server refuses. /// Returns the refusal, or null. A running command is never dismissed. Future dismiss(List ids) async { final removed = [ for (final id in ids) if (_runs[id] case final run? when !run.running) run, ]; if (removed.isEmpty) return null; for (final run in removed) { _remove(run.id); } _changed(membership: true); try { await _repository.dismiss(sessionId, [for (final r in removed) r.id]); return null; } catch (error) { if (_disposed) return null; final reason = _reason(error); for (final run in removed) { _gone.remove(run.id); _runs[run.id] = run; _errors[run.id] = reason; } _changed(membership: true); return reason; } } /// Undoes the dismissal of [ids] while the server still keeps them. /// Returns the refusal, or null. Future restore(List ids) async { try { final restored = await _repository.restore(sessionId, ids); if (_disposed) return null; for (final run in restored) { _gone.remove(run.id); final held = _runs[run.id]; final keep = held != null && held.outputEnd >= run.outputEnd; _runs[run.id] = keep ? held.withLifecycle(run) : run; if (!keep) terminals.replaced(run); } _changed(membership: true); return null; } catch (error) { return _reason(error); } } void _remove(String id) { _gone.add(id); _runs.remove(id); _errors.remove(id); _shares.remove(id); _stopping.remove(id); terminals.removed(id); } }