Adding styles and a basic prompt, tho local markers are not getting set
This commit is contained in:
parent
952fe90817
commit
1c1272337c
1 changed files with 101 additions and 19 deletions
120
mattermost.el
120
mattermost.el
|
@ -147,6 +147,15 @@ if the user is not present"
|
||||||
(let ((url (format "/channels/%s/posts" channel-id)))
|
(let ((url (format "/channels/%s/posts" channel-id)))
|
||||||
(mattermost-request "GET" url)))
|
(mattermost-request "GET" url)))
|
||||||
|
|
||||||
|
(define-button-type 'mattermost-channel
|
||||||
|
'face 'default
|
||||||
|
'read-only t
|
||||||
|
'rear-sticky t
|
||||||
|
'front-sticky t
|
||||||
|
'action #'(lambda (b)
|
||||||
|
(let* ((channel (button-get b 'channel)))
|
||||||
|
(mattermost-show-channel channel))))
|
||||||
|
|
||||||
(defun mattermost-insert-channel (channel)
|
(defun mattermost-insert-channel (channel)
|
||||||
"Inserts a channel button in the current buffer"
|
"Inserts a channel button in the current buffer"
|
||||||
(let* ((channel-display-name (plist-get channel :display_name))
|
(let* ((channel-display-name (plist-get channel :display_name))
|
||||||
|
@ -155,13 +164,8 @@ if the user is not present"
|
||||||
channel-name
|
channel-name
|
||||||
channel-display-name)))
|
channel-display-name)))
|
||||||
(insert-text-button (format "> %s\n" name)
|
(insert-text-button (format "> %s\n" name)
|
||||||
'action #'(lambda (b)
|
:type 'mattermost-channel
|
||||||
(let* ((channel (button-get b 'channel)))
|
'channel channel)))
|
||||||
(mattermost-show-channel channel)))
|
|
||||||
'channel channel
|
|
||||||
'read-only t
|
|
||||||
'rear-sticky t
|
|
||||||
'front-sticky t)))
|
|
||||||
|
|
||||||
;; ToDo: when root buffer is closed, disconnect
|
;; ToDo: when root buffer is closed, disconnect
|
||||||
(defun mattermost-show-root ()
|
(defun mattermost-show-root ()
|
||||||
|
@ -196,25 +200,96 @@ if the user is not present"
|
||||||
"Mode to list the Mattermost teams and channels to allow the
|
"Mode to list the Mattermost teams and channels to allow the
|
||||||
user to check their status and select between them")
|
user to check their status and select between them")
|
||||||
|
|
||||||
|
(defvar mattermost-username-button-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(set-keymap-parent map button-map)
|
||||||
|
(define-key map (kbd "n") #'next-line)
|
||||||
|
(define-key map (kbd "p") #'previous-line)
|
||||||
|
map))
|
||||||
|
|
||||||
|
(define-button-type 'mattermost-username
|
||||||
|
'face 'bold
|
||||||
|
'read-only t
|
||||||
|
'rear-sticky t
|
||||||
|
'front-sticky t
|
||||||
|
'keymap mattermost-username-button-map
|
||||||
|
'action #'(lambda (b)
|
||||||
|
(let* ((user (button-get b 'user)))
|
||||||
|
(message "action for user %s!" (plist-get user :username)))))
|
||||||
|
|
||||||
|
(defvar mattermost-post-button-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(set-keymap-parent map button-map)
|
||||||
|
(define-key map (kbd "n") #'next-line)
|
||||||
|
(define-key map (kbd "p") #'previous-line)
|
||||||
|
map))
|
||||||
|
|
||||||
|
(define-button-type 'mattermost-post
|
||||||
|
'face 'default
|
||||||
|
'read-only t
|
||||||
|
'rear-sticky t
|
||||||
|
'front-sticky t
|
||||||
|
'keymap mattermost-post-button-map
|
||||||
|
'action #'(lambda (b)
|
||||||
|
(let* ((post (button-get b 'post)))
|
||||||
|
(message "action for post %s!" (plist-get post :id)))))
|
||||||
|
|
||||||
(defun mattermost-insert-post (post)
|
(defun mattermost-insert-post (post)
|
||||||
"Inserts a post message in the current buffer"
|
"Inserts a post message in the current buffer"
|
||||||
(let* ((user-id (plist-get post :user_id))
|
(let* ((user-id (plist-get post :user_id))
|
||||||
(user (mattermost--get-user user-id))
|
(user (mattermost--get-user user-id))
|
||||||
(username (plist-get user :username))
|
(username (plist-get user :username))
|
||||||
(msg (plist-get post :message)))
|
(msg (plist-get post :message)))
|
||||||
(insert-text-button (format "[%s] %s\n" username msg)
|
(insert-text-button (format "[%s]" username)
|
||||||
'action #'(lambda (b)
|
:type 'mattermost-username
|
||||||
(message "button action! %s" (button-get b 'post)))
|
'user user)
|
||||||
'post post
|
(insert-text-button (format " %s\n" msg)
|
||||||
'read-only t
|
:type 'mattermost-post
|
||||||
'rear-sticky t
|
'post post)))
|
||||||
'front-sticky t)))
|
|
||||||
|
(defun mattermost-prompt ()
|
||||||
|
"Shows the message prompt"
|
||||||
|
(setq mattermost-prompt-marker (make-marker)
|
||||||
|
mattermost-insert-marker (make-marker))
|
||||||
|
(end-of-buffer)
|
||||||
|
(set-marker mattermost-insert-marker (point))
|
||||||
|
(setq prompt (propertize ">> "
|
||||||
|
'rear-nonsticky t
|
||||||
|
'field t
|
||||||
|
'front-sticky t
|
||||||
|
'read-only t))
|
||||||
|
(put-text-property 0 (1- (length prompt))
|
||||||
|
'font-lock-face 'bold
|
||||||
|
prompt)
|
||||||
|
(insert prompt)
|
||||||
|
(set-marker mattermost-prompt-marker (point)))
|
||||||
|
|
||||||
|
(defun mattermost-channel-ret ()
|
||||||
|
"Sends the post if on the input field or the button action
|
||||||
|
otherwise"
|
||||||
|
(interactive)
|
||||||
|
(if (> (point) mattermost-prompt-marker)
|
||||||
|
(let ((inhibit-read-only t)
|
||||||
|
(msg (field-string-no-properties (point))))
|
||||||
|
(message "Sending: %s" msg)
|
||||||
|
(delete-field (point)))))
|
||||||
|
|
||||||
|
(defvar mattermost-channel-mode-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(define-key map (kbd "C-m") 'mattermost-channel-ret)
|
||||||
|
map)
|
||||||
|
"The keymap for mattermost-channel-mode")
|
||||||
|
|
||||||
|
(define-derived-mode mattermost-channel-mode fundamental-mode "Mattermost Channel"
|
||||||
|
"Mode use on a Mattermost channel buffer, that shows the
|
||||||
|
messages of the channel and allows the user to post theirs")
|
||||||
|
|
||||||
;; ToDo: should we receive just a channel id and fetch the channel
|
;; ToDo: should we receive just a channel id and fetch the channel
|
||||||
;; data?
|
;; data?
|
||||||
(defun mattermost-show-channel (channel)
|
(defun mattermost-show-channel (channel)
|
||||||
"Populates the channel buffer with posts and the prompt"
|
"Populates the channel buffer with posts and the prompt"
|
||||||
(let* ((id (plist-get channel :id))
|
(let* ((inhibit-read-only t)
|
||||||
|
(id (plist-get channel :id))
|
||||||
(display-name (plist-get channel :display_name))
|
(display-name (plist-get channel :display_name))
|
||||||
(name (plist-get channel :name))
|
(name (plist-get channel :name))
|
||||||
(cname (if (string-empty-p display-name) name display-name))
|
(cname (if (string-empty-p display-name) name display-name))
|
||||||
|
@ -225,15 +300,22 @@ user to check their status and select between them")
|
||||||
|
|
||||||
(with-current-buffer chanb
|
(with-current-buffer chanb
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(let* ((inhibit-read-only t)
|
|
||||||
(resp (mattermost-get-channel-messages id))
|
;; ToDo: is this the place to define the variables?
|
||||||
|
(defvar-local mattermost-prompt-marker nil
|
||||||
|
"The marker that shows where the prompt starts")
|
||||||
|
(defvar-local mattermost-insert-marker nil
|
||||||
|
"The marker that shows where a new message should be inserted")
|
||||||
|
|
||||||
|
(let* ((resp (mattermost-get-channel-messages id))
|
||||||
(order (seq-reverse (plist-get resp :order)))
|
(order (seq-reverse (plist-get resp :order)))
|
||||||
(posts (plist-get resp :posts)))
|
(posts (plist-get resp :posts)))
|
||||||
(dolist (post-id order)
|
(dolist (post-id order)
|
||||||
(let ((post (plist-get posts (mattermost-string->keyword post-id))))
|
(let ((post (plist-get posts (mattermost-string->keyword post-id))))
|
||||||
(mattermost-insert-post post)))))
|
(mattermost-insert-post post))))
|
||||||
|
(mattermost-prompt)
|
||||||
|
(mattermost-channel-mode))
|
||||||
(switch-to-buffer chanb)
|
(switch-to-buffer chanb)
|
||||||
;; ToDo: here enable mode
|
|
||||||
(end-of-buffer)))
|
(end-of-buffer)))
|
||||||
|
|
||||||
(defun mattermost ()
|
(defun mattermost ()
|
||||||
|
|
Loading…
Reference in a new issue