diff --git a/mattermost.el b/mattermost.el index 0a62054..a47ba1b 100644 --- a/mattermost.el +++ b/mattermost.el @@ -69,8 +69,8 @@ (funcall secret) secret))))) -(defun mattermost-print-post (post) - "Prints the post in the current buffer" +(defun mattermost-insert-post (post) + "Inserts the post in the current buffer" (let* ((msg (plist-get post :message)) ;; ToDo: convert to a readable date ;; (update-at (plist-get post :update_at)) @@ -165,6 +165,21 @@ if the user is not present" map) "The keymap for mattermost-root-mode") +(defun mattermost-insert-channel (channel) + "Inserts a channel button in the current buffer" + (let* ((channel-display-name (plist-get channel :display_name)) + (channel-name (plist-get channel :name)) + (name (if (string-empty-p channel-display-name) + channel-name + channel-display-name))) + (insert-text-button (format "> %s\n" name) + 'action #'(lambda (b) + (let* ((channel (button-get b 'channel)) + (channel-id (plist-get channel :id))) + + (message "button action! %s" channel-id))) + 'channel channel))) + (defun show-root () "Populates the Mattermost Root buffer and changes to it" (interactive) @@ -178,12 +193,7 @@ if the user is not present" (channels (mattermost-get-channels team-id))) (insert (format "%s\n" team-display-name)) (dolist (channel channels) - (let ((channel-id (plist-get channel :id)) - (channel-display-name (plist-get channel :display_name)) - (channel-name (plist-get channel :name))) - (insert (format "> [%s] %s\n" channel-id (if (string= channel-display-name "") - channel-name - channel-display-name))))))))) + (mattermost-insert-channel channel)))))) (switch-to-buffer rootb) (mattermost-root-mode) (beginning-of-buffer)))