Fix TUI refresh for incoming messages

ober

52ebc107175432f1207bea408199e76ac361561d

diff --git a/signal/tui/main.ss b/signal/tui/main.ss
index 10aa517..825f570 100644
--- a/signal/tui/main.ss
+++ b/signal/tui/main.ss
@@ -409,9 +409,13 @@
           (when invalidate? (tb-invalidate!))
           (draw! state)
           (tb-present!))
-        (let* ([ev (tb-peek-event *idle-poll-ms*)]
+        ;; Keep terminal input nonblocking so Signal actor events are drained even
+        ;; on terminals where the C peek timeout does not wake reliably.
+        (let* ([ev (tb-peek-event 0)]
                [event-dirty? (and ev (begin (handle-event! state actor ev) #t))]
                [last-invalidate (if invalidate? now last-invalidate)])
+          (when (and (not ev) (not (tui-state-quit? state)))
+            (sleep-ms *idle-poll-ms*))
           (unless (tui-state-quit? state)
             (loop event-dirty? last-invalidate))))))
 
@@ -2597,6 +2601,15 @@
     (cond
       [(or (<= n 0) (null? xs)) '()]
       [else (cons (car xs) (cap-list (cdr xs) (- n 1)))]))
+  (def (conversation-unread-summary conversations)
+    (let loop ([convs conversations] [acc '()])
+      (cond
+        [(null? convs) (reverse acc)]
+        [else
+         (let ([conv (car convs)])
+           (loop (cdr convs)
+                 (cons (cons (conversation-id conv) (conversation-unread conv))
+                       acc)))])))
 
   ;; --- Drawing ---
 
@@ -2636,6 +2649,10 @@
       (let ([conv (selected-conversation state)])
         (when (changed? 'conversation-count (length (tui-state-conversations state)))
           (add! 'conversations))
+        (when (changed? 'conversation-unreads
+                        (conversation-unread-summary
+                          (tui-state-conversations state)))
+          (add! 'conversations))
         (when (changed? 'selected-conversation-id (and conv (conversation-id conv)))
           (add! 'conversations)
           (add! 'thread))
@@ -2669,6 +2686,8 @@
       (hash-put! ht 'thread-scroll (tui-state-thread-scroll state))
       (hash-put! ht 'conv-scroll (tui-state-conv-scroll state))
       (hash-put! ht 'conversation-count (length (tui-state-conversations state)))
+      (hash-put! ht 'conversation-unreads
+                 (conversation-unread-summary (tui-state-conversations state)))
       (hash-put! ht 'selected-conversation-id (and conv (conversation-id conv)))
       (hash-put! ht 'selected-conversation-title (and conv (conversation-title conv)))
       (hash-put! ht 'selected-message-count (and conv (length (conversation-messages conv))))