aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-01 16:33:31 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-01 16:33:31 +0200
commitd50e1324f5476a7bf84cbf0b8307e6a283cdbb10 (patch)
tree83034776ae26fcf7c757782db8cf613b15e0570b
parentc6aa74e6942f5156e43a027c54862bfd68270911 (diff)
view instance details of post at point's author.
-rw-r--r--lisp/mastodon-tl.el52
1 files changed, 52 insertions, 0 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 079af22..36a79da 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1357,11 +1357,63 @@ RESPONSE is the JSON returned by the server."
(defmacro mastodon-tl--do-if-toot (&rest body)
"Execute BODY if we have a toot or user at point."
+ (declare (debug (symbolp &rest body)))
`(if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view
(not (mastodon-tl--property 'toot-json)))
(message "Looks like there's no toot or user at point?")
,@body))
+(defun mastodon-tl-view-instance-description ()
+ "View the details of the instance the current post's author is on."
+ (interactive)
+ (mastodon-tl--do-if-toot
+ (let* ((toot (mastodon-tl--property 'toot-json))
+ (reblog (alist-get 'reblog toot))
+ (account (or (alist-get 'account reblog)
+ (alist-get 'account toot)))
+ (acct (alist-get 'acct account))
+ (username (alist-get 'username account))
+ (instance
+ (concat "https://"
+ (string-remove-prefix (concat username "@")
+ acct)))
+ (response (mastodon-http--get-json
+ (concat instance
+ "/api/v1/instance"))))
+ (when response
+ (let ((buf (get-buffer-create "*mastodon-preferences*")))
+ (with-current-buffer buf
+ ;; (setq masto-test-inst-json response)
+ (switch-to-buffer-other-window buf)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (special-mode)
+ (mastodon-tl--print-json-keys response)
+ (goto-char (point-min)))))))))
+
+(defun mastodon-tl--print-json-keys (response)
+ "Print the JSON keys and values in RESPONSE."
+ (while response
+ (let ((el (pop response)))
+ (if (equal (type-of (cdr el)) 'cons)
+ (progn
+ (setq-local left-margin 4)
+ (insert
+ (mastodon-tl--render-text
+ (format "%-20s: "
+ (prin1-to-string (car el)))
+ nil)
+ "\n")
+ (indent-to-left-margin)
+ (mastodon-tl--print-json-keys (cdr el)))
+ (insert
+ (mastodon-tl--render-text
+ (format "%-20s: %s"
+ (prin1-to-string (car el))
+ (prin1-to-string (cdr el)))
+ nil)
+ "\n")))))
+
(defun mastodon-tl--follow-user (user-handle &optional notify)
"Query for USER-HANDLE from current status and follow that user.
If NOTIFY is \"true\", enable notifications when that user posts.