Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils/device-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ export function humanState(human: DeviceHumanStatus): string {
export function humanFields(human: DeviceHumanStatus, now: number = Date.now()): Field[] {
const fields: Field[] = [['state', humanState(human)]];
if (human.reason) fields.push(['reason', human.reason]);
if (human.since) fields.push(['asked', formatWhen(human.since, now)]);
// A person who took control unasked: the reason is "<email> took control",
// and nobody asked for anything.
const tookControl = human.human_in_control && !!human.reason?.endsWith(' took control');
if (human.since) fields.push([tookControl ? 'since' : 'asked', formatWhen(human.since, now)]);
if (human.waiting && human.expires_at) {
fields.push(['ends', `${formatWhen(human.expires_at, now)} unless they hand it back`]);
}
Expand Down
3 changes: 3 additions & 0 deletions test/unit/device-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ describe('dcd device', () => {
const labels = (h: typeof base | Record<string, unknown>) =>
humanFields(h as typeof base, now).map(([label]) => label);
expect(labels(base)).to.deep.equal(['state', 'reason', 'asked', 'ends']);
// Taken unasked: "since", not "asked". A request a person picked up stays "asked".
expect(labels({ ...base, human_in_control: true, reason: 'ann@x.com took control' })).to.deep.equal(['state', 'reason', 'since', 'ends']);
expect(labels({ ...base, human_in_control: true })).to.deep.equal(['state', 'reason', 'asked', 'ends']);
const back = { ...base, waiting: false, reason: null, since: null, handed_back: true, note: 'Done', handed_back_at: '2026-10-19T10:00:00Z' };
expect(humanFields(back, now)).to.deep.include(['note', 'Done']);
expect(humanFields(back, now)[0]).to.deep.equal(['state', 'handed back']);
Expand Down
Loading