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:
+17
-11
@@ -95,13 +95,18 @@
|
|||||||
- [x] Bridge methods verified via smoke tests.
|
- [x] Bridge methods verified via smoke tests.
|
||||||
- [x] Post model includes file_ids.
|
- [x] Post model includes file_ids.
|
||||||
|
|
||||||
## Phase 4b — Emacs UI (pending)
|
## Phase 4b — Emacs UI
|
||||||
|
|
||||||
- [ ] Connect Emacs to bridge over TCP.
|
- [x] Connect Emacs to bridge over TCP.
|
||||||
- [ ] Open self-DM buffer.
|
- [x] Interactive connection prompt (password in memory only).
|
||||||
- [ ] Display raw messages.
|
- [x] Dashboard buffer with channel list (`mattermost-dashboard-mode`).
|
||||||
- [ ] Send message from Emacs.
|
- [x] Open channel buffer from dashboard.
|
||||||
- [ ] Receive own message online.
|
- [x] Display raw message history in channel buffer.
|
||||||
|
- [x] Send message from channel buffer (`C-c C-s`).
|
||||||
|
- [x] Refresh channel history (`g`).
|
||||||
|
- [x] Reset connection state (`mattermost-reset-state`).
|
||||||
|
- [ ] Receive own message online (WebSocket fan-out).
|
||||||
|
- [ ] Resolve DM channel display names (currently shows empty).
|
||||||
|
|
||||||
## Phase 5 — WebSocket online updates
|
## Phase 5 — WebSocket online updates
|
||||||
|
|
||||||
@@ -127,12 +132,13 @@
|
|||||||
|
|
||||||
## Phase 7 — channels
|
## Phase 7 — channels
|
||||||
|
|
||||||
- [ ] Implement list_channels.
|
- [x] Implement list_channels (Rust backend).
|
||||||
- [ ] Channel list buffer.
|
- [x] Channel list buffer (Emacs UI).
|
||||||
- [ ] Open channel buffer, load history, send message.
|
- [x] Open channel buffer, load history, send message.
|
||||||
- [ ] Channel events online.
|
- [ ] Channel events online (WebSocket fan-out).
|
||||||
- [ ] Implement mark_read.
|
- [ ] Implement mark_read.
|
||||||
- [ ] Forced refresh with g.
|
- [ ] Resolve DM channel display names.
|
||||||
|
- [ ] Forced refresh with g (basic refresh works, full recovery pending).
|
||||||
|
|
||||||
## Phase 8 — TLS/self-signed support
|
## Phase 8 — TLS/self-signed support
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
(require 'mattermost-custom)
|
(require 'mattermost-custom)
|
||||||
(require 'mattermost-protocol)
|
(require 'mattermost-protocol)
|
||||||
|
(require 'mattermost-channel)
|
||||||
|
|
||||||
(defvar mattermost--current-server-id nil
|
(defvar mattermost--current-server-id nil
|
||||||
"Current server ID for the dashboard buffer.")
|
"Current server ID for the dashboard buffer.")
|
||||||
@@ -19,9 +20,18 @@
|
|||||||
(setq buffer-read-only t)
|
(setq buffer-read-only t)
|
||||||
(setq truncate-lines 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)
|
(defun mattermost-ensure-connected (callback)
|
||||||
"Ensure connection to the bridge, prompting for missing credentials.
|
"Ensure connection to the bridge, prompting for missing credentials."
|
||||||
Calls CALLBACK with server-id on success. Password is never saved to disk."
|
|
||||||
(let* ((url (if (string= mattermost-server-url "")
|
(let* ((url (if (string= mattermost-server-url "")
|
||||||
(read-string "Mattermost URL (e.g., https://mattermost.local): ")
|
(read-string "Mattermost URL (e.g., https://mattermost.local): ")
|
||||||
mattermost-server-url))
|
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): "))
|
(password (read-passwd "Password (or PAT token): "))
|
||||||
(server-id mattermost-server-id))
|
(server-id mattermost-server-id))
|
||||||
|
|
||||||
;; Сохраняем только не-секретные настройки, если они были пустыми
|
|
||||||
(when (string= mattermost-server-url "")
|
(when (string= mattermost-server-url "")
|
||||||
(customize-save-variable 'mattermost-server-url url))
|
(customize-save-variable 'mattermost-server-url url))
|
||||||
(when (string= mattermost-login-id "")
|
(when (string= mattermost-login-id "")
|
||||||
(customize-save-variable 'mattermost-login-id login))
|
(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)
|
(message "[MM-DEBUG] Connecting to %s as %s (password masked)" url login)
|
||||||
(mattermost--send-request
|
(mattermost--send-request
|
||||||
"connect"
|
"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."
|
"Render CHANNELS in a new Mattermost Dashboard buffer."
|
||||||
(let ((buf (get-buffer-create "*Mattermost Dashboard*")))
|
(let ((buf (get-buffer-create "*Mattermost Dashboard*")))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(erase-buffer)
|
(let ((inhibit-read-only t))
|
||||||
(mattermost-dashboard-mode)
|
(erase-buffer)
|
||||||
(setq-local mattermost--current-server-id server-id)
|
(mattermost-dashboard-mode)
|
||||||
(setq-local mattermost--channels channels)
|
(setq-local mattermost--current-server-id server-id)
|
||||||
|
(setq-local mattermost--channels channels)
|
||||||
(insert "Mattermost Channels\n")
|
|
||||||
(insert "==================\n\n")
|
(insert "Mattermost Channels\n")
|
||||||
|
(insert "==================\n\n")
|
||||||
(dolist (ch channels)
|
|
||||||
(let ((name (or (plist-get ch :display_name) "Unknown"))
|
(dolist (ch channels)
|
||||||
(type (or (plist-get ch :channel_type) "?"))
|
(let ((name (or (plist-get ch :display_name) "Unknown"))
|
||||||
(id (plist-get ch :id)))
|
(type (or (plist-get ch :channel_type) "?"))
|
||||||
(insert (format "[%s] %s (ID: %s)\n" type name id))))
|
(id (plist-get ch :id)))
|
||||||
|
(insert (format "[%s] %s (ID: %s)\n" type name id))))
|
||||||
(goto-char (point-min)))
|
|
||||||
|
(goto-char (point-min))))
|
||||||
(switch-to-buffer buf)))
|
(switch-to-buffer buf)))
|
||||||
|
|
||||||
(defun mattermost-dashboard-refresh ()
|
(defun mattermost-dashboard-refresh ()
|
||||||
@@ -109,8 +124,14 @@ Calls CALLBACK with server-id on success. Password is never saved to disk."
|
|||||||
(interactive)
|
(interactive)
|
||||||
(let ((line (thing-at-point 'line t)))
|
(let ((line (thing-at-point 'line t)))
|
||||||
(if (string-match "ID: \\([a-z0-9]+\\)" line)
|
(if (string-match "ID: \\([a-z0-9]+\\)" line)
|
||||||
(let ((channel-id (match-string 1 line)))
|
(let* ((channel-id (match-string 1 line))
|
||||||
(message "[MM] Opening channel: %s (TODO: implement channel buffer)" channel-id))
|
(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."))))
|
(message "[MM] No channel ID found on this line."))))
|
||||||
|
|
||||||
(provide 'mattermost-dashboard)
|
(provide 'mattermost-dashboard)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
(defun mattermost-connect-to-bridge ()
|
(defun mattermost-connect-to-bridge ()
|
||||||
"Connect to the running Rust bridge."
|
"Connect to the running Rust bridge."
|
||||||
(interactive)
|
(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))
|
(delete-process mattermost--process))
|
||||||
|
|
||||||
(setq mattermost--process
|
(setq mattermost--process
|
||||||
@@ -46,7 +46,8 @@
|
|||||||
(setq lines (butlast lines)))
|
(setq lines (butlast lines)))
|
||||||
|
|
||||||
(dolist (line 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
|
(if msg
|
||||||
(let ((id (plist-get msg :id))
|
(let ((id (plist-get msg :id))
|
||||||
(type (plist-get msg :type)))
|
(type (plist-get msg :type)))
|
||||||
|
|||||||
Reference in New Issue
Block a user