aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-profile.el
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-05-15 14:13:06 +0200
committermousebot <mousebot@riseup.net>2021-05-16 13:18:11 +0200
commite5a8ca254300e20932786a1ecb4ceb3387ab84e5 (patch)
tree3a22eedd25c7325c84ab511da9648753f140135e /lisp/mastodon-profile.el
parent5ea4b715d022e5a4ccff47d4874ee171aa7af522 (diff)
add basic display of "fields" (category pairs) on user profiles
clean up fields mastodon-profile--fields-format
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r--lisp/mastodon-profile.el50
1 files changed, 47 insertions, 3 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index e0e209d..ec3dd0f 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -109,6 +109,41 @@ following the current profile."
their-id))))
(mastodon-http--get-json url)))
+(defun mastodon-profile--fields-get (account)
+ "Fetch the fields vector from a profile.
+
+Returns a list of lists."
+ (let ((fields (mastodon-profile--account-field account 'fields)))
+ (when fields
+ (mapcar
+ (lambda (el)
+ (list
+ (cdr (assoc 'name el))
+ (cdr (assoc 'value el))))
+ fields))))
+
+(defun mastodon-profile--fields-insert (fields)
+ "Format and insert field pairs in FIELDS."
+ (let* ((car-fields (mapcar 'car fields))
+ ;; (cdr-fields (mapcar 'cadr fields))
+ ;; (cdr-fields-rendered
+ ;; (list
+ ;; (mapcar (lambda (x)
+ ;; (mastodon-tl--render-text x nil))
+ ;; cdr-fields)))
+ (left-width (car (sort (mapcar 'length car-fields) '>))))
+ ;; (right-width (car (sort (mapcar 'length cdr-fields) '>))))
+ (mapconcat (lambda (field)
+ (mastodon-tl--render-text
+ (concat
+ (format "_ %s " (car field))
+ (make-string (- (+ 1 left-width) (length (car field))) ?_)
+ (format " :: %s" (cadr field)))
+ ;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_)
+ ;; " |")
+ nil))
+ fields "")))
+
(defun mastodon-profile--make-profile-buffer-for (account endpoint-type update-function)
(let* ((id (mastodon-profile--account-field account 'id))
(url (mastodon-http--api (format "accounts/%s/%s"
@@ -135,7 +170,8 @@ following the current profile."
(aref (mastodon-profile--relationships-get id) 0))))
(follows-you (cdr (assoc 'followed_by
(aref (mastodon-profile--relationships-get id) 0))))
- (followsp (or (equal follows-you 't) (equal followed-by-you 't))))
+ (followsp (or (equal follows-you 't) (equal followed-by-you 't)))
+ (fields (mastodon-profile--fields-get account)))
(with-output-to-temp-buffer buffer
(switch-to-buffer buffer)
(mastodon-mode)
@@ -165,6 +201,14 @@ following the current profile."
'face 'default)
"\n ------------\n"
(mastodon-tl--render-text note nil)
+ (if fields
+ (progn
+ (concat "\n"
+ (mastodon-tl--set-face
+ (mastodon-profile--fields-insert fields)
+ 'success)
+ "\n"))
+ "")
(mastodon-tl--set-face
(concat " ------------\n"
" TOOTS: " toots-count " | "
@@ -175,9 +219,9 @@ following the current profile."
(if followsp
(mastodon-tl--set-face
(concat (if (equal follows-you 't)
- "FOLLOWS YOU | ")
+ " | FOLLOWS YOU")
(if (equal followed-by-you 't)
- "FOLLOWED BY YOU | ")
+ " | FOLLOWED BY YOU")
"\n\n")
'success)
"") ; if no followsp we still need str-or-char-p for insert