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:
@@ -208,3 +208,28 @@
|
||||
(should (string-match-p "Sarah> from sse" (buffer-string))))
|
||||
(let ((msg (car (noise-db-get-messages "+1"))))
|
||||
(should (string= "from sse" (gethash "body" msg))))))
|
||||
|
||||
(ert-deftest noise-receive-sse-stores-then-open-shows-message ()
|
||||
"An SSE event stores the message; opening the conversation later shows it."
|
||||
(noise-receive-test--with-db
|
||||
;; No conversation buffer open — simulate SSE event arriving
|
||||
(noise-receive--handle-sse-event
|
||||
(noise-receive-test--ht
|
||||
"envelope"
|
||||
(noise-receive-test--ht
|
||||
"sourceNumber" "+1" "sourceName" "Sarah"
|
||||
"dataMessage" (noise-receive-test--ht
|
||||
"timestamp" 1717930000000
|
||||
"message" "hello from the void"))))
|
||||
;; Verify message is in DB
|
||||
(let ((msgs (noise-db-get-messages "+1")))
|
||||
(should (= 1 (length msgs)))
|
||||
(should (string= "hello from the void" (gethash "body" (car msgs)))))
|
||||
;; Verify conversation has unread count
|
||||
(let ((conv (noise-db-get-conversation "+1")))
|
||||
(should (= 1 (gethash "unread_count" conv))))
|
||||
;; Now open the conversation and verify message renders
|
||||
(require 'noise-conversation)
|
||||
(with-current-buffer (noise-conversation-open "+1")
|
||||
(should (string-match-p "Sarah> hello from the void" (buffer-string)))
|
||||
(should (= 0 (gethash "unread_count" (noise-db-get-conversation "+1")))))))
|
||||
|
||||
Reference in New Issue
Block a user