Posting messages works! tho the markers are still being set manually

This commit is contained in:
Miguel de la Cruz 2022-06-02 12:44:58 +02:00
parent 1c1272337c
commit 7de96b524b

View file

@ -40,6 +40,15 @@
(defvar mattermost-websocket nil
"The websocket connected to the server")
(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")
(defvar-local mattermost-channel-id nil
"The buffer channel ID")
;; ToDo: probably not the best way to get a keyword from a string
(defun mattermost-string->keyword (str)
"Returns a keyword from a string"
@ -156,6 +165,10 @@ if the user is not present"
(let* ((channel (button-get b 'channel)))
(mattermost-show-channel channel))))
(defun mattermost-create-post (message channel-id)
"Creates a post on a channel"
(mattermost-request "POST" "/posts" `(:channel_id ,channel-id :message ,message)))
(defun mattermost-insert-channel (channel)
"Inserts a channel button in the current buffer"
(let* ((channel-display-name (plist-get channel :display_name))
@ -271,7 +284,7 @@ user to check their status and select between them")
(if (> (point) mattermost-prompt-marker)
(let ((inhibit-read-only t)
(msg (field-string-no-properties (point))))
(message "Sending: %s" msg)
(mattermost-create-post msg mattermost-channel-id)
(delete-field (point)))))
(defvar mattermost-channel-mode-map
@ -300,13 +313,6 @@ user to check their status and select between them")
(with-current-buffer chanb
(erase-buffer)
;; 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)))
(posts (plist-get resp :posts)))
@ -316,6 +322,7 @@ user to check their status and select between them")
(mattermost-prompt)
(mattermost-channel-mode))
(switch-to-buffer chanb)
(setq mattermost-channel-id id)
(end-of-buffer)))
(defun mattermost ()