UI updates
This commit is contained in:
+25
-10
@@ -32,9 +32,13 @@
|
|||||||
(setq buffer-read-only t)
|
(setq buffer-read-only t)
|
||||||
(setq-local header-line-format
|
(setq-local header-line-format
|
||||||
(concat " U "
|
(concat " U "
|
||||||
(format "%-20s" "Name")
|
(format "%-18s" "Name")
|
||||||
(format "%-40s" "Last message")
|
(format "%-42s" "Last message")
|
||||||
"When")))
|
"When"))
|
||||||
|
(when (bound-and-true-p evil-mode)
|
||||||
|
(let ((m (make-sparse-keymap)))
|
||||||
|
(define-key m (kbd "RET") #'noise-chat-list-open)
|
||||||
|
(setq-local evil-normal-state-local-map m))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun noise-chat-list ()
|
(defun noise-chat-list ()
|
||||||
@@ -50,10 +54,21 @@
|
|||||||
(let ((inhibit-read-only t)
|
(let ((inhibit-read-only t)
|
||||||
(conversations (noise-db-get-all-conversations)))
|
(conversations (noise-db-get-all-conversations)))
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
|
;; Clear old fringe overlays
|
||||||
|
(remove-overlays (point-min) (point-max) 'noise-fringe t)
|
||||||
(if (null conversations)
|
(if (null conversations)
|
||||||
(insert "No conversations. Sync from signal-cli with `g`.\n")
|
(insert "No conversations. Sync from signal-cli with `g`.\n")
|
||||||
(dolist (conv conversations)
|
(dolist (conv conversations)
|
||||||
(insert (noise-chat-list--format-row conv) "\n")))
|
(let ((unread (or (gethash "unread_count" conv) 0))
|
||||||
|
(row (noise-chat-list--format-row conv)))
|
||||||
|
(insert row "\n")
|
||||||
|
(when (> unread 0)
|
||||||
|
(let ((ov (make-overlay (line-beginning-position 0)
|
||||||
|
(line-beginning-position 0))))
|
||||||
|
(overlay-put ov 'noise-fringe t)
|
||||||
|
(overlay-put ov 'before-string
|
||||||
|
(propertize " " 'display
|
||||||
|
'(left-fringe filled-rectangle warning))))))))
|
||||||
(noise-chat-list--update-modeline conversations)
|
(noise-chat-list--update-modeline conversations)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(set-buffer-modified-p nil)))
|
(set-buffer-modified-p nil)))
|
||||||
@@ -93,13 +108,13 @@ Today: HH:MM, this week: Ddd, older: Mon DD."
|
|||||||
|
|
||||||
(defun noise-chat-list--format-row (conv)
|
(defun noise-chat-list--format-row (conv)
|
||||||
"Format a single conversation row for display.
|
"Format a single conversation row for display.
|
||||||
CONV is a hash table with string keys from noise-db."
|
CONV is a hash table with string keys from noise-db.
|
||||||
|
The unread dot is rendered in the Emacs fringe, not inline."
|
||||||
(let* ((unread (or (gethash "unread_count" conv) 0))
|
(let* ((unread (or (gethash "unread_count" conv) 0))
|
||||||
(name (or (gethash "name" conv) "Unknown"))
|
(name (or (gethash "name" conv) "Unknown"))
|
||||||
(preview (or (gethash "last_message_preview" conv) ""))
|
(preview (or (gethash "last_message_preview" conv) ""))
|
||||||
(sender (or (gethash "last_message_sender" conv) ""))
|
(sender (or (gethash "last_message_sender" conv) ""))
|
||||||
(timestamp (or (gethash "last_message_time" conv) 0))
|
(timestamp (or (gethash "last_message_time" conv) 0))
|
||||||
(fringe (if (> unread 0) "●" " "))
|
|
||||||
(unread-str (if (> unread 0) (format "%3d" unread) " "))
|
(unread-str (if (> unread 0) (format "%3d" unread) " "))
|
||||||
(name-str (truncate-string-to-width name 18 nil nil "…"))
|
(name-str (truncate-string-to-width name 18 nil nil "…"))
|
||||||
(preview-prefix
|
(preview-prefix
|
||||||
@@ -107,11 +122,11 @@ CONV is a hash table with string keys from noise-db."
|
|||||||
((string= sender "") preview)
|
((string= sender "") preview)
|
||||||
((string= sender "me") (concat "me: " preview))
|
((string= sender "me") (concat "me: " preview))
|
||||||
(t (concat sender ": " preview))))
|
(t (concat sender ": " preview))))
|
||||||
(preview-str (truncate-string-to-width preview-prefix 36 nil nil "…"))
|
(preview-str (truncate-string-to-width preview-prefix 42 nil nil "…"))
|
||||||
(time-str (noise-chat-list--format-time timestamp)))
|
(time-str (noise-chat-list--format-time timestamp)))
|
||||||
(concat (propertize fringe 'face 'warning) " " unread-str " "
|
(concat unread-str " "
|
||||||
(propertize (format "%-18s" name-str) 'face 'bold) " "
|
(propertize (format "%-18s" name-str) 'face 'bold)
|
||||||
preview-str " "
|
(propertize (format "%-42s" preview-str) 'face 'shadow)
|
||||||
(propertize time-str 'face 'shadow))))
|
(propertize time-str 'face 'shadow))))
|
||||||
|
|
||||||
(defun noise-chat-list--conversation-at-point ()
|
(defun noise-chat-list--conversation-at-point ()
|
||||||
|
|||||||
@@ -47,7 +47,11 @@
|
|||||||
"Major mode for a Noise Signal conversation buffer.
|
"Major mode for a Noise Signal conversation buffer.
|
||||||
\\{noise-conversation-mode-map}"
|
\\{noise-conversation-mode-map}"
|
||||||
:group 'noise
|
:group 'noise
|
||||||
(setq-local header-line-format noise-conversation--mode-header))
|
(setq-local header-line-format noise-conversation--mode-header)
|
||||||
|
(when (bound-and-true-p evil-mode)
|
||||||
|
(let ((m (make-sparse-keymap)))
|
||||||
|
(define-key m (kbd "RET") #'noise-conversation-send)
|
||||||
|
(setq-local evil-normal-state-local-map m))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun noise-conversation-open (conversation-id)
|
(defun noise-conversation-open (conversation-id)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
(noise-chat-list-test--make-row "conv-1" "Sarah" 3
|
(noise-chat-list-test--make-row "conv-1" "Sarah" 3
|
||||||
"are you taking the girls?"
|
"are you taking the girls?"
|
||||||
"Sarah" (float-time)))))
|
"Sarah" (float-time)))))
|
||||||
(should (string-match "●" row))
|
(should (string-match " 3" row))
|
||||||
(should (string-match "Sarah" row))
|
(should (string-match "Sarah" row))
|
||||||
(should (string-match "are you taking" row))))
|
(should (string-match "are you taking" row))))
|
||||||
|
|
||||||
@@ -49,4 +49,4 @@
|
|||||||
(noise-chat-list-test--make-row "conv-2" "Mark Okafor" 0
|
(noise-chat-list-test--make-row "conv-2" "Mark Okafor" 0
|
||||||
"merged" "me" (float-time)))))
|
"merged" "me" (float-time)))))
|
||||||
(should (string-match "Mark Okafor" row))
|
(should (string-match "Mark Okafor" row))
|
||||||
(should-not (string-match "●" row))))
|
(should (string-match "^ " row))))
|
||||||
|
|||||||
Reference in New Issue
Block a user