From 7de96b524b259fd2485008e32b50dae8dc2e28c9 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 2 Jun 2022 12:44:58 +0200 Subject: [PATCH] Posting messages works! tho the markers are still being set manually --- mattermost.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mattermost.el b/mattermost.el index 53d2c3b..0de6cd9 100644 --- a/mattermost.el +++ b/mattermost.el @@ -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 ()