Show loudly in the chat list when a chat is waiting on the operator
The server's chat activity now counts each session's unanswered approvals and questions (awaiting_operator) and pushes it to every connection when it changes. A waiting chat's list row pulses in the error colour with a solid bar on its leading edge, its avatar wears a ringing bell in place of the spinner, and its state line leads with a bold "Waiting for you". Reduced motion holds the pulse and the bell still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -185,3 +185,43 @@ func TestChatBackgroundTasksKeepUnattendedRoom(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An unanswered approval or question is the operator's to act on: the list
|
||||
// activity counts it, and answering it clears the count.
|
||||
func TestChatActivityCountsWhatAwaitsTheOperator(t *testing.T) {
|
||||
h := newChatHub()
|
||||
defer func() {
|
||||
h.mu.Lock()
|
||||
for _, room := range h.rooms {
|
||||
room.cancel()
|
||||
}
|
||||
h.mu.Unlock()
|
||||
}()
|
||||
const id = "ses_wait"
|
||||
awaiting := func() int {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.activity[id].AwaitingOperator
|
||||
}
|
||||
h.mu.Lock()
|
||||
h.roomLocked(id)
|
||||
h.mu.Unlock()
|
||||
|
||||
h.pushPermission(id, protocol.ChatPermissionFrame{SessionID: id, RequestID: "perm_1"})
|
||||
if got := awaiting(); got != 1 {
|
||||
t.Fatalf("a pending approval: awaiting=%d", got)
|
||||
}
|
||||
h.mu.Lock()
|
||||
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1"}})
|
||||
h.mu.Unlock()
|
||||
if got := awaiting(); got != 2 {
|
||||
t.Fatalf("an approval and a question: awaiting=%d", got)
|
||||
}
|
||||
h.confirmPermission(id, "perm_1", "c", "allow")
|
||||
h.mu.Lock()
|
||||
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1", Resolved: true}})
|
||||
h.mu.Unlock()
|
||||
if got := awaiting(); got != 0 {
|
||||
t.Fatalf("both answered: awaiting=%d", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user