fix: show notifications and unread count for SSE messages arriving when chat closed

Three gaps caused messages received via SSE to be invisible when
the conversation buffer wasn't already open:

1. Echo-area notification (noise-receive.el): when an SSE message
   arrives and the conversation buffer isn't in a visible window,
   show "[Noise] <name>" in the echo area.

2. Modeline unread counter (noise.el): the noise-mode lighter now
   shows Noise[N] for N unread messages via a lightweight SUM
   aggregation across all conversations.

3. Auto-refresh hook (noise-conversation.el): a
   window-buffer-change-functions hook re-renders *signal:* buffers
   when they become visible, covering direct C-x b switches.

Also adds regression test:
noise-receive-sse-stores-then-open-shows-message —
store via SSE handler with no buffer open, then open and verify.
This commit is contained in:
2026-06-14 12:57:05 -04:00
parent 0dd2919fad
commit cedd82738a
4 changed files with 66 additions and 3 deletions
+17 -2
View File
@@ -76,11 +76,27 @@ Queries the daemon for registered accounts and sets `noise-account'."
(noise-rpc-error
(message "Error: %s" (cdr err)))))
(defun noise--unread-lighter ()
"Return the mode-line lighter string with unread count."
(let ((count 0))
(when (and (boundp 'noise-db--connection)
noise-db--connection
(fboundp 'sqlitep)
(sqlitep noise-db--connection))
(condition-case nil
(setq count (or (caar (sqlite-select noise-db--connection
"SELECT COALESCE(SUM(unread_count), 0) FROM conversations"))
0))
(error 0)))
(if (> count 0)
(format " Noise[%d]" count)
" Noise")))
;;;###autoload
(define-minor-mode noise-mode
"Toggle Noise Signal client mode."
:global t
:lighter " Noise"
:lighter (:eval (noise--unread-lighter))
:group 'noise
(if noise-mode
(progn
@@ -88,6 +104,5 @@ Queries the daemon for registered accounts and sets `noise-account'."
(noise-receive-start-sse))
(noise-receive-stop-sse)
(message "Noise mode disabled")))
(provide 'noise)
;;; noise.el ends here