feat(ui): working vertical slice — dashboard, channel view, send

- mattermost-dashboard-mode: list channels from bridge
- mattermost-channel-mode: view history and send messages
- Interactive connection prompt (password in memory only)
- Fix JSON array parsing (vectors → lists) in protocol layer
- Add mattermost-reset-state for clean reconnects
- Add dev-check.sh for quick Rust validation
- Verified end-to-end: Emacs → Bridge → Mattermost → back
This commit is contained in:
Ivan I. Ovchinnikov
2026-11-21 09:03:19 +03:00
parent 8e98a68906
commit 612456334f
4 changed files with 166 additions and 33 deletions
+105
View File
@@ -0,0 +1,105 @@
;;; mattermost-channel.el --- Channel buffer UI -*- lexical-binding: t; -*-
(require 'mattermost-custom)
(require 'mattermost-protocol)
(defvar mattermost-channel-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-s") #'mattermost-channel-send-message)
(define-key map (kbd "g") #'mattermost-channel-refresh)
map)
"Keymap for `mattermost-channel-mode`.")
(define-derived-mode mattermost-channel-mode special-mode "Mattermost-Channel"
"Major mode for viewing a Mattermost channel.
\\{mattermost-channel-mode-map}"
(setq buffer-read-only t)
(setq truncate-lines t))
(defvar-local mattermost--channel-id nil
"Channel ID for the current buffer.")
(defvar-local mattermost--server-id nil
"Server ID for the current buffer.")
(defvar-local mattermost--channel-name nil
"Display name of the current channel.")
(defun mattermost-channel-open (server-id channel-id channel-name)
"Open a buffer for CHANNEL-ID on SERVER-ID with CHANNEL-NAME."
(let ((buf-name (format "*MM: %s*" channel-name)))
(let ((buf (get-buffer-create buf-name)))
(with-current-buffer buf
(mattermost-channel-mode)
(setq-local mattermost--server-id server-id)
(setq-local mattermost--channel-id channel-id)
(setq-local mattermost--channel-name channel-name)
(mattermost-channel-load-history))
(switch-to-buffer buf))))
(defun mattermost-channel-load-history ()
"Load and display message history for the current channel."
(let ((server-id mattermost--server-id)
(channel-id mattermost--channel-id)
(channel-name mattermost--channel-name))
(message "[MM-DEBUG] Loading history for channel %s..." channel-id)
(mattermost--send-request
"get_history"
(list :server_id server-id
:channel_id channel-id
:limit 50)
(lambda (response)
(if (plist-get response :ok)
(mattermost--render-channel-history
channel-name
(plist-get (plist-get response :result) :posts))
(message "[MM] Failed to load history: %S" (plist-get response :error)))))))
(defun mattermost--render-channel-history (channel-name posts)
"Render POSTS in the current channel buffer with CHANNEL-NAME."
(let ((inhibit-read-only t))
(erase-buffer)
(insert (format "Channel: %s\n" channel-name))
(insert "========================================\n\n")
(dolist (post posts)
(let* ((msg-text (or (plist-get post :message) ""))
(create-at (plist-get post :create_at))
(time-str (if create-at
(format-time-string "%H:%M" (seconds-to-time (/ create-at 1000)))
"??:??"))
(user-id (or (plist-get post :user_id) "unknown")))
(insert (format "[%s] %s: %s\n" time-str user-id msg-text))))
(insert "\n")
(goto-char (point-max))))
(defun mattermost-channel-refresh ()
"Reload message history for the current channel."
(interactive)
(message "[MM-DEBUG] Refreshing channel...")
(mattermost-channel-load-history))
(defun mattermost-channel-send-message ()
"Send a message to the current channel."
(interactive)
(let* ((server-id mattermost--server-id)
(channel-id mattermost--channel-id)
(msg (read-string "Message: ")))
(when (string-empty-p msg)
(error "Message cannot be empty"))
(message "[MM-DEBUG] Sending message to channel %s..." channel-id)
(mattermost--send-request
"send_post"
(list :server_id server-id
:channel_id channel-id
:message msg)
(lambda (response)
(if (plist-get response :ok)
(progn
(message "[MM] Message sent successfully.")
(mattermost-channel-refresh))
(message "[MM] Failed to send message: %S" (plist-get response :error)))))))
(provide 'mattermost-channel)
+41 -20
View File
@@ -2,6 +2,7 @@
(require 'mattermost-custom)
(require 'mattermost-protocol)
(require 'mattermost-channel)
(defvar mattermost--current-server-id nil
"Current server ID for the dashboard buffer.")
@@ -19,9 +20,18 @@
(setq buffer-read-only t)
(setq truncate-lines t))
(defun mattermost-reset-state ()
"Reset all connection state and clear pending requests."
(interactive)
(when (and (boundp 'mattermost--process) mattermost--process (process-live-p mattermost--process))
(delete-process mattermost--process))
(setq mattermost--process nil)
(setq mattermost--pending-requests (make-hash-table :test 'equal))
(setq mattermost--input-buffer "")
(message "[MM] State reset complete. Ready to reconnect."))
(defun mattermost-ensure-connected (callback)
"Ensure connection to the bridge, prompting for missing credentials.
Calls CALLBACK with server-id on success. Password is never saved to disk."
"Ensure connection to the bridge, prompting for missing credentials."
(let* ((url (if (string= mattermost-server-url "")
(read-string "Mattermost URL (e.g., https://mattermost.local): ")
mattermost-server-url))
@@ -31,12 +41,16 @@ Calls CALLBACK with server-id on success. Password is never saved to disk."
(password (read-passwd "Password (or PAT token): "))
(server-id mattermost-server-id))
;; Сохраняем только не-секретные настройки, если они были пустыми
(when (string= mattermost-server-url "")
(customize-save-variable 'mattermost-server-url url))
(when (string= mattermost-login-id "")
(customize-save-variable 'mattermost-login-id login))
(unless (and (boundp 'mattermost--process)
mattermost--process
(process-live-p mattermost--process))
(mattermost-connect-to-bridge))
(message "[MM-DEBUG] Connecting to %s as %s (password masked)" url login)
(mattermost--send-request
"connect"
@@ -70,21 +84,22 @@ Calls CALLBACK with server-id on success. Password is never saved to disk."
"Render CHANNELS in a new Mattermost Dashboard buffer."
(let ((buf (get-buffer-create "*Mattermost Dashboard*")))
(with-current-buffer buf
(erase-buffer)
(mattermost-dashboard-mode)
(setq-local mattermost--current-server-id server-id)
(setq-local mattermost--channels channels)
(insert "Mattermost Channels\n")
(insert "==================\n\n")
(dolist (ch channels)
(let ((name (or (plist-get ch :display_name) "Unknown"))
(type (or (plist-get ch :channel_type) "?"))
(id (plist-get ch :id)))
(insert (format "[%s] %s (ID: %s)\n" type name id))))
(goto-char (point-min)))
(let ((inhibit-read-only t))
(erase-buffer)
(mattermost-dashboard-mode)
(setq-local mattermost--current-server-id server-id)
(setq-local mattermost--channels channels)
(insert "Mattermost Channels\n")
(insert "==================\n\n")
(dolist (ch channels)
(let ((name (or (plist-get ch :display_name) "Unknown"))
(type (or (plist-get ch :channel_type) "?"))
(id (plist-get ch :id)))
(insert (format "[%s] %s (ID: %s)\n" type name id))))
(goto-char (point-min))))
(switch-to-buffer buf)))
(defun mattermost-dashboard-refresh ()
@@ -109,8 +124,14 @@ Calls CALLBACK with server-id on success. Password is never saved to disk."
(interactive)
(let ((line (thing-at-point 'line t)))
(if (string-match "ID: \\([a-z0-9]+\\)" line)
(let ((channel-id (match-string 1 line)))
(message "[MM] Opening channel: %s (TODO: implement channel buffer)" channel-id))
(let* ((channel-id (match-string 1 line))
(server-id mattermost--current-server-id)
(channel-name (if (string-match "\\] \\(.+\\) (ID:" line)
(match-string 1 line)
"Unknown")))
(if server-id
(mattermost-channel-open server-id channel-id channel-name)
(error "No server ID associated with this dashboard")))
(message "[MM] No channel ID found on this line."))))
(provide 'mattermost-dashboard)
+3 -2
View File
@@ -15,7 +15,7 @@
(defun mattermost-connect-to-bridge ()
"Connect to the running Rust bridge."
(interactive)
(when (and mattermost--process (process-live-p mattermost--process))
(when (and (boundp 'mattermost--process) mattermost--process (process-live-p mattermost--process))
(delete-process mattermost--process))
(setq mattermost--process
@@ -46,7 +46,8 @@
(setq lines (butlast lines)))
(dolist (line lines)
(let ((msg (ignore-errors (json-parse-string line :object-type 'plist))))
;; ДОБАВЛЕНО: :array-type 'list чтобы JSON-массивы становились списками, а не векторами
(let ((msg (ignore-errors (json-parse-string line :object-type 'plist :array-type 'list))))
(if msg
(let ((id (plist-get msg :id))
(type (plist-get msg :type)))