aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-10-13 21:26:39 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-10-13 21:46:26 +0200
commitd7ef5b9512e281befda374c82c89977896b407c3 (patch)
tree536d97620559231dca007e4b4be9d59554c3bb0c
parentaccd94eea7e99e2a2acbf51e0ea877db6ef420fe (diff)
FIX #494. mastodon-tl--more-json-async-offset for pagination.
-rw-r--r--lisp/mastodon-tl.el45
1 files changed, 40 insertions, 5 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 6b7e33d..ddae34a 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -2257,6 +2257,31 @@ the current view."
(mastodon-http--api endpoint))))
(apply #'mastodon-http--get-json-async url args callback cbargs)))
+(defun mastodon-tl--more-json-async-offset (endpoint &optional params
+ callback &rest cbargs)
+ "Return JSON for ENDPOINT, using the \"offset\" query param.
+This is used for pagination with endpoints that implement the
+\"offset\" parameter, rather than using link-headers or
+\"max_id\".
+PARAMS are the update parameters, see
+`mastodon-tl--update-params'. These (\"limit\" and \"offset\")
+must be set in `mastodon-tl--buffer-spec' for pagination to work.
+Then run CALLBACK with arguments CBARGS."
+ (let* ((params (or params
+ (mastodon-tl--update-params)))
+ (limit (string-to-number
+ (alist-get "limit" params nil nil #'equal)))
+ (offset (number-to-string
+ (+ limit ; limit + old offset = new offset
+ (string-to-number
+ (alist-get "offset" params nil nil #'equal)))))
+ (url (if (string-suffix-p "search" endpoint)
+ (mastodon-http--api-search)
+ (mastodon-http--api endpoint))))
+ ;; increment:
+ (setf (alist-get "offset" params nil nil #'equal) offset)
+ (apply #'mastodon-http--get-json-async url params callback cbargs)))
+
(defun mastodon-tl--updated-json (endpoint id &optional params)
"Return JSON for timeline ENDPOINT since ID.
PARAMS is used to send any parameters needed to correctly update
@@ -2335,11 +2360,21 @@ when showing followers or accounts followed."
(url (mastodon-tl--build-link-header-url next)))
(mastodon-http--get-response-async url nil 'mastodon-tl--more* (current-buffer)
(point) :headers))))
- (mastodon-tl--more-json-async
- (mastodon-tl--endpoint)
- (mastodon-tl--oldest-id)
- (mastodon-tl--update-params)
- 'mastodon-tl--more* (current-buffer) (point))))
+ ;; offset (search, trending, user lists, ...?):
+ (if (or (string-prefix-p "*mastodon-trending-" (buffer-name))
+ (mastodon-tl--search-buffer-p))
+ ;; Endpoints that do not implement: follow-suggestions,
+ ;; follow-requests
+ (mastodon-tl--more-json-async-offset
+ (mastodon-tl--endpoint)
+ (mastodon-tl--update-params)
+ 'mastodon-tl--more* (current-buffer) (point))
+ ;; max_id (timelines, items with ids/timestamps):
+ (mastodon-tl--more-json-async
+ (mastodon-tl--endpoint)
+ (mastodon-tl--oldest-id)
+ (mastodon-tl--update-params)
+ 'mastodon-tl--more* (current-buffer) (point)))))
(defun mastodon-tl--more* (response buffer point-before &optional headers)
"Append older toots to timeline, asynchronously.