Get the last messages from a channel and print them on a buffer
This commit is contained in:
parent
15348b0999
commit
ce0951fc45
1 changed files with 27 additions and 3 deletions
|
@ -21,6 +21,11 @@
|
|||
|
||||
(setq mattermost-server-url "https://chat.ctrlz.es")
|
||||
|
||||
;; ToDo: probably not the best way to get a keyword from a string
|
||||
(defun mattermost-string->keyword (str)
|
||||
"Returns a keyword from a string"
|
||||
(read (concat ":" str)))
|
||||
|
||||
(defun mattermost-parse-json ()
|
||||
"Parses the JSON in the current buffer after a url-request"
|
||||
(let ((json-object-type 'plist)
|
||||
|
@ -68,6 +73,11 @@
|
|||
(message "Channels url: %s" url)
|
||||
(mattermost-request "GET" url)))
|
||||
|
||||
(defun mattermost-get-channel-messages (channel-id &optional page per-page)
|
||||
"Returns a list of posts for a given channel"
|
||||
(let ((url (format "/channels/%s/posts" channel-id)))
|
||||
(mattermost-request "GET" url)))
|
||||
|
||||
(with-current-buffer (get-buffer-create "*Mattermost Teams*")
|
||||
(let ((teams (mattermost-get-teams)))
|
||||
(erase-buffer)
|
||||
|
@ -80,9 +90,23 @@
|
|||
(let ((channel-id (plist-get channel :id))
|
||||
(channel-display-name (plist-get channel :display_name))
|
||||
(channel-name (plist-get channel :name)))
|
||||
(insert (format "> %s\n" (if (string= channel-display-name "")
|
||||
channel-name
|
||||
channel-display-name)))))))))
|
||||
(insert (format "> [%s] %s\n" channel-id (if (string= channel-display-name "")
|
||||
channel-name
|
||||
channel-display-name)))))))))
|
||||
|
||||
(setq msgs (mattermost-get-channel-messages "68w17u1da7yg7enayudjjqqwse"))
|
||||
|
||||
(car (plist-get msgs :posts))
|
||||
|
||||
(with-current-buffer (get-buffer-create "*Town Square*")
|
||||
(erase-buffer)
|
||||
(dolist (msgid (plist-get msgs :order))
|
||||
(let* ((posts (plist-get msgs :posts))
|
||||
(post (plist-get posts (mattermost-string->keyword msgid)))
|
||||
(user-id (plist-get post :user_id))
|
||||
(message (plist-get post :message))
|
||||
(update-at (plist-get post :update_at)))
|
||||
(insert (format "[%s %s] %s\n" user-id update-at message)))))
|
||||
|
||||
(provide 'mattermost)
|
||||
;;; mattermost.el ends here
|
||||
|
|
Loading…
Reference in a new issue