aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-26 09:34:20 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-26 09:36:47 +0100
commit0c889fd275b8338aed5f173f0a7df78e23801b92 (patch)
treefe1f088b0e615ab4c61f1d30ea1cea91f31ebd88 /lisp
parent91836e01b1598923c7a6a8e17fba74ff92d2587e (diff)
paginate profile view followers/following with link header
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-profile.el36
-rw-r--r--lisp/mastodon-tl.el23
2 files changed, 41 insertions, 18 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 3ba00b9..658b1d4 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -71,6 +71,9 @@
(autoload 'mastodon-tl--get-endpoint "mastodon-tl.el")
(autoload 'mastodon-toot--get-max-toot-chars "mastodon-toot")
(autoload 'mastodon-tl--add-account-to-list "mastodon-tl")
+(autoload 'mastodon-http--get-response "mastodon-http")
+(autoload 'mastodon-tl--get-link-header-from-response "mastodon-tl")
+(autoload 'mastodon-tl--set-buffer-spec "mastodon-tl")
(defvar mastodon-instance-url)
(defvar mastodon-tl--buffer-spec)
@@ -186,7 +189,9 @@ NO-REBLOGS means do not display boosts in statuses."
(mastodon-profile--make-profile-buffer-for
mastodon-profile--account
"following"
- #'mastodon-profile--add-author-bylines)
+ #'mastodon-profile--add-author-bylines
+ nil
+ :headers)
(error "Not in a mastodon profile")))
(defun mastodon-profile--open-followers ()
@@ -196,7 +201,9 @@ NO-REBLOGS means do not display boosts in statuses."
(mastodon-profile--make-profile-buffer-for
mastodon-profile--account
"followers"
- #'mastodon-profile--add-author-bylines)
+ #'mastodon-profile--add-author-bylines
+ nil
+ :headers)
(error "Not in a mastodon profile")))
(defun mastodon-profile--view-favourites ()
@@ -552,16 +559,25 @@ FIELDS means provide a fields vector fetched by other means."
(defun mastodon-profile--make-profile-buffer-for (account endpoint-type
update-function
- &optional no-reblogs)
+ &optional no-reblogs headers)
"Display profile of ACCOUNT, using ENDPOINT-TYPE and UPDATE-FUNCTION.
-NO-REBLOGS means do not display boosts in statuses."
+NO-REBLOGS means do not display boosts in statuses.
+HEADERS means also fetch link headers for pagination."
(let* ((id (mastodon-profile--account-field account 'id))
(args (when no-reblogs '(("exclude_reblogs" . "t"))))
(url (mastodon-http--api (format "accounts/%s/%s" id endpoint-type)))
(acct (mastodon-profile--account-field account 'acct))
(buffer (concat "*mastodon-" acct "-" endpoint-type "*"))
+ (response (if headers
+ (mastodon-http--get-response url args)
+ (mastodon-http--get-json url args)))
+ (json (if headers (car response) response))
+ (endpoint (format "accounts/%s/%s" id endpoint-type))
+ (link-header (when headers
+ (mastodon-tl--get-link-header-from-response
+ (cdr response))))
+
(note (mastodon-profile--account-field account 'note))
- (json (mastodon-http--get-json url args))
(locked (mastodon-profile--account-field account 'locked))
(followers-count (mastodon-tl--as-string
(mastodon-profile--account-field
@@ -585,11 +601,11 @@ NO-REBLOGS means do not display boosts in statuses."
(switch-to-buffer buffer)
(mastodon-mode)
(mastodon-profile-mode)
- (setq mastodon-profile--account account
- mastodon-tl--buffer-spec
- `(buffer-name ,buffer
- endpoint ,(format "accounts/%s/%s" id endpoint-type)
- update-function ,update-function))
+ (setq mastodon-profile--account account)
+ (mastodon-tl--set-buffer-spec buffer
+ endpoint
+ update-function
+ link-header)
(let* ((inhibit-read-only t)
(is-statuses (string= endpoint-type "statuses"))
(is-followers (string= endpoint-type "followers"))
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 1a726c4..a87cd73 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -136,10 +136,6 @@ If nil `(point-min)' is used instead.")
(defvar-local mastodon-tl--timestamp-update-timer nil
"The timer that, when set will scan the buffer to update the timestamps.")
-(defvar mastodon-tl--link-header-buffers
- '("*mastodon-favourites*" "*mastodon-bookmarks*")
- "A list of buffers that use link headers for pagination.")
-
;; KEYMAPS
(defvar mastodon-tl--link-keymap
@@ -2327,11 +2323,22 @@ For use after e.g. deleting a toot."
(param (cadr split)))
(concat url-base "&" param)))
+(defun mastodon-tl--use-link-header-p ()
+ "Return t if we are in a view that uses Link header pagination.
+Currently this includes favourites, bookmarks, and profile pages
+when showing followers or accounts followed."
+ (let ((buf (buffer-name (current-buffer)))
+ (endpoint (mastodon-tl--get-endpoint)))
+ (or (member buf '("*mastodon-favourites*" "*mastodon-bookmarks*"))
+ (and (string-prefix-p "accounts" endpoint)
+ (or (string-suffix-p "followers" endpoint)
+ (string-suffix-p "following" endpoint))))))
+
(defun mastodon-tl--more ()
"Append older toots to timeline, asynchronously."
(interactive)
(message "Loading older toots...")
- (if (member (buffer-name (current-buffer)) mastodon-tl--link-header-buffers)
+ (if (mastodon-tl--use-link-header-p)
;; link-header: can't build a URL with --more-json-async, endpoint/id:
(let* ((next (car (mastodon-tl--link-header)))
;;(prev (cadr (mastodon-tl--link-header)))
@@ -2532,7 +2539,7 @@ from the start if it is nil."
"Initialize BUFFER-NAME with timeline targeted by ENDPOINT asynchronously.
UPDATE-FUNCTION is used to recieve more toots.
HEADERS means to also collect the response headers. Used for paginating
-favourites."
+favourites and bookmarks."
(let ((url (mastodon-http--api endpoint))
(buffer (concat "*mastodon-" buffer-name "*")))
(if headers
@@ -2545,8 +2552,8 @@ favourites."
"Initialize BUFFER with timeline targeted by ENDPOINT.
UPDATE-FUNCTION is used to recieve more toots.
RESPONSE is the data returned from the server by
-`mastodon-http--process-json', a cons cell of JSON and http
-headers."
+`mastodon-http--process-json', with arg HEADERS a cons cell of
+JSON and http headers, without it just the JSON."
(let* ((json (if headers (car response) response))
(headers (if headers (cdr response) nil))
(link-header (mastodon-tl--get-link-header-from-response headers)))