aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-profile.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r--lisp/mastodon-profile.el120
1 files changed, 66 insertions, 54 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 2c364da..7a9edc3 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2017-2019 Johnson Denen
;; Author: Johnson Denen <johnson.denen@gmail.com>
;; Version: 0.9.1
-;; Package-Requires: ((emacs "26.1") (seq "1.8"))
+;; Package-Requires: ((emacs "26.1") (seq "1.0"))
;; Homepage: https://github.com/jdenen/mastodon.el
;; This file is not part of GNU Emacs.
@@ -62,15 +62,14 @@
(defvar mastodon-tl--update-point)
-(defvar mastodon-profile--account nil
+(defvar-local mastodon-profile--account nil
"The data for the account being described in the current profile buffer.")
-(make-variable-buffer-local 'mastodon-profile--account)
;; this way you can update it with C-M-x:
(defvar mastodon-profile-mode-map
(let ((map (make-sparse-keymap)))
- (define-key map (kbd "O") #'mastodon-profile--open-followers)
- (define-key map (kbd "o") #'mastodon-profile--open-following)
+ (define-key map (kbd "s") #'mastodon-profile--open-followers)
+ (define-key map (kbd "g") #'mastodon-profile--open-following)
(define-key map (kbd "a") #'mastodon-profile--follow-request-accept)
(define-key map (kbd "j") #'mastodon-profile--follow-request-reject)
map)
@@ -143,6 +142,14 @@ extra keybindings."
"favourites"
'mastodon-tl--timeline))
+(defun mastodon-profile--view-bookmarks ()
+ "Open a new buffer displaying the user's bookmarks."
+ (interactive)
+ (message "Loading your bookmarked toots...")
+ (mastodon-tl--init "bookmarks"
+ "bookmarks"
+ 'mastodon-tl--timeline))
+
(defun mastodon-profile--view-follow-requests ()
"Open a new buffer displaying the user's follow requests."
(interactive)
@@ -156,9 +163,9 @@ extra keybindings."
(interactive)
(if (mastodon-tl--find-property-range 'toot-json (point))
(let* ((acct-json (mastodon-profile--toot-json))
- (id (cdr (assoc 'id acct-json)))
- (handle (cdr (assoc 'acct acct-json)))
- (name (cdr (assoc 'username acct-json))))
+ (id (alist-get 'id acct-json))
+ (handle (alist-get 'acct acct-json))
+ (name (alist-get 'username acct-json)))
(if id
(let ((response
(mastodon-http--post
@@ -178,9 +185,9 @@ extra keybindings."
(interactive)
(if (mastodon-tl--find-property-range 'toot-json (point))
(let* ((acct-json (mastodon-profile--toot-json))
- (id (cdr (assoc 'id acct-json)))
- (handle (cdr (assoc 'acct acct-json)))
- (name (cdr (assoc 'username acct-json))))
+ (id (alist-get 'id acct-json))
+ (handle (alist-get 'acct acct-json))
+ (name (alist-get 'username acct-json)))
(if id
(let ((response
(mastodon-http--post
@@ -202,8 +209,8 @@ extra keybindings."
"/api/v1/accounts/update_credentials"))
;; (buffer (mastodon-http--patch url))
(json (mastodon-http--patch-json url))
- (source (cdr (assoc 'source json)))
- (note (cdr (assoc 'note source)))
+ (source (alist-get 'source json))
+ (note (alist-get 'note source))
(buffer (get-buffer-create "*mastodon-update-profile*"))
(inhibit-read-only t))
(switch-to-buffer-other-window buffer)
@@ -240,8 +247,8 @@ Returns a list of lists."
(mapcar
(lambda (el)
(list
- (cdr (assoc 'name el))
- (cdr (assoc 'value el))))
+ (alist-get 'name el)
+ (alist-get 'value el)))
fields))))
(defun mastodon-profile--fields-insert (fields)
@@ -249,20 +256,20 @@ Returns a list of lists."
(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)))
+ ;; (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) '>))))
+ ;; (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))) ?_)
- ;; " |")
+ ;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_)
+ ;; " |")
field)) ; nil)) ; hack to make links tabstops
fields "")))
@@ -288,6 +295,7 @@ Returns a list of lists."
(buffer (concat "*mastodon-" acct "-" endpoint-type "*"))
(note (mastodon-profile--account-field account 'note))
(json (mastodon-http--get-json url))
+ (locked (mastodon-profile--account-field account 'locked))
(followers-count (mastodon-tl--as-string
(mastodon-profile--account-field
account 'followers_count)))
@@ -298,10 +306,10 @@ Returns a list of lists."
(mastodon-profile--account-field
account 'statuses_count)))
(relationships (mastodon-profile--relationships-get id))
- (followed-by-you (cdr (assoc 'following
- (aref relationships 0))))
- (follows-you (cdr (assoc 'followed_by
- (aref relationships 0))))
+ (followed-by-you (alist-get 'following
+ (aref relationships 0)))
+ (follows-you (alist-get 'followed_by
+ (aref relationships 0)))
(followsp (or (equal follows-you 't) (equal followed-by-you 't)))
(fields (mastodon-profile--fields-get account))
(pinned (mastodon-profile--get-statuses-pinned account)))
@@ -319,9 +327,9 @@ Returns a list of lists."
(is-followers (string= endpoint-type "followers"))
(is-following (string= endpoint-type "following"))
(endpoint-name (cond
- (is-statuses " TOOTS ")
- (is-followers " FOLLOWERS ")
- (is-following " FOLLOWING "))))
+ (is-statuses " TOOTS ")
+ (is-followers " FOLLOWERS ")
+ (is-following " FOLLOWING "))))
(insert
"\n"
(mastodon-profile--image-from-account account)
@@ -330,18 +338,22 @@ Returns a list of lists."
account 'display_name)
'face 'mastodon-display-name-face)
"\n"
- (propertize acct
+ (propertize (concat "@" acct)
'face 'default)
+ (if (equal locked t)
+ (if (fontp (char-displayable-p #10r9993))
+ " 🔒"
+ " [locked]")
+ "")
"\n ------------\n"
(mastodon-tl--render-text note account)
;; account here to enable tab-stops in profile note
(if fields
- (progn
- (concat "\n"
- (mastodon-tl--set-face
- (mastodon-profile--fields-insert fields)
- 'success)
- "\n"))
+ (concat "\n"
+ (mastodon-tl--set-face
+ (mastodon-profile--fields-insert fields)
+ 'success)
+ "\n")
"")
;; insert counts
(mastodon-tl--set-face
@@ -369,7 +381,7 @@ Returns a list of lists."
'success))
(setq mastodon-tl--update-point (point))
(mastodon-media--inline-images (point-min) (point))
- ;; insert pinned toots first
+ ;; insert pinned toots first
(when (and pinned (equal endpoint-type "statuses"))
(mastodon-profile--insert-statuses-pinned pinned)
(setq mastodon-tl--update-point (point))) ;updates to follow pinned toots
@@ -383,11 +395,11 @@ Returns a list of lists."
If toot is a boost, opens the profile of the booster."
(interactive)
(mastodon-profile--make-author-buffer
- (cdr (assoc 'account (mastodon-profile--toot-json)))))
+ (alist-get 'account (mastodon-profile--toot-json))))
(defun mastodon-profile--image-from-account (status)
"Generate an image from a STATUS."
- (let ((url (cdr (assoc 'avatar_static status))))
+ (let ((url (alist-get 'avatar_static status)))
(unless (equal url "/avatars/original/missing.png")
(mastodon-media--get-media-link-rendering url))))
@@ -430,12 +442,12 @@ FIELD is used to identify regions under 'account"
(propertize
(mastodon-tl--byline-author `((account . ,toot)))
'byline 't
- 'toot-id (cdr (assoc 'id toot))
+ 'toot-id (alist-get 'id toot)
'base-toot-id (mastodon-tl--toot-id toot)
'toot-json toot))
(mastodon-media--inline-images start-pos (point))
(insert "\n"
- (mastodon-tl--render-text (cdr (assoc 'note toot)) nil)
+ (mastodon-tl--render-text (alist-get 'note toot) nil)
"\n")))
tootv)))
@@ -448,7 +460,7 @@ If the handle does not match a search return then retun NIL."
handle))
(matching-account
(seq-remove
- (lambda(x) (not (string= (cdr (assoc 'acct x)) handle)))
+ (lambda(x) (not (string= (alist-get 'acct x) handle)))
(mastodon-http--get-json
(mastodon-http--api (format "accounts/search?q=%s" handle))))))
(when (equal 1 (length matching-account))
@@ -464,35 +476,35 @@ If the handle does not match a search return then retun NIL."
These include the author, author of reblogged entries and any user mentioned."
(when status
- (let ((this-account (cdr (assoc 'account status)))
- (mentions (cdr (assoc 'mentions status)))
- (reblog (cdr (assoc 'reblog status))))
+ (let ((this-account (alist-get 'account status))
+ (mentions (alist-get 'mentions status))
+ (reblog (alist-get 'reblog status)))
(seq-filter
'stringp
(seq-uniq
(seq-concatenate
'list
- (list (cdr (assoc 'acct this-account)))
+ (list (alist-get 'acct this-account))
(mastodon-profile--extract-users-handles reblog)
(mapcar (lambda (mention)
- (cdr (assoc 'acct mention)))
+ (alist-get 'acct mention))
mentions)))))))
(defun mastodon-profile--lookup-account-in-status (handle status)
"Return account for HANDLE using hints in STATUS if possible."
- (let* ((this-account (cdr (assoc 'account status)))
- (reblog-account (cdr (assoc 'account (cdr (assoc 'reblog status)))))
+ (let* ((this-account (alist-get 'account status))
+ (reblog-account (alist-get 'account (alist-get 'reblog status)))
(mention-id (seq-some
(lambda (mention)
(when (string= handle
- (cdr (assoc 'acct mention)))
- (cdr (assoc 'id mention))))
- (cdr (assoc 'mentions status)))))
+ (alist-get 'acct mention))
+ (alist-get 'id mention)))
+ (alist-get 'mentions status))))
(cond ((string= handle
- (cdr (assoc 'acct this-account)))
+ (alist-get 'acct this-account))
this-account)
((string= handle
- (cdr (assoc 'acct reblog-account)))
+ (alist-get 'acct reblog-account))
reblog-account)
(mention-id
(mastodon-profile--account-from-id mention-id))