aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-tl.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-09 12:22:04 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-09 12:22:04 +0100
commit596a9498a8dcc2aecb28f94f9ba57766583f5fab (patch)
tree0703beefb35fce493c6c0553374aa80b5d3d92d8 /lisp/mastodon-tl.el
parentd3538d7553557350b7bee1743f5403f69ffd89db (diff)
--init: handle json or full response and handle Link header
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el26
1 files changed, 18 insertions, 8 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 813c18c..a2194b7 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1936,13 +1936,23 @@ HEADERS means to also collect the response headers. Used for paginating
favourites."
(let ((url (mastodon-http--api endpoint))
(buffer (concat "*mastodon-" buffer-name "*")))
- (mastodon-http--get-json-async
- url 'mastodon-tl--init* buffer endpoint update-function)))
+ (if headers
+ (mastodon-http--get-response-async
+ url 'mastodon-tl--init* buffer endpoint update-function headers)
+ (mastodon-http--get-json-async
+ url 'mastodon-tl--init* buffer endpoint update-function))))
-(defun mastodon-tl--init* (json buffer endpoint update-function)
+(defun mastodon-tl--init* (response buffer endpoint update-function &optional headers)
"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."
+ (let* ((json (if headers (car response) response))
+ (headers (if headers (cdr response) nil))
+ (link-header (when headers
+ (split-string
+ (car
+ (alist-get "Link" headers nil nil 'equal))
+ ", "))))
(with-output-to-temp-buffer buffer
(switch-to-buffer buffer)
;; mastodon-mode wipes buffer-spec, so order must unforch be:
@@ -1951,8 +1961,8 @@ RESPONSE is the data returned from the server by `mastodon-http--process-json',
;; unless we set it both before and after the others
(mastodon-tl--set-buffer-spec buffer
endpoint
- update-function)
- ;; link-header)
+ update-function
+ link-header)
(setq
;; Initialize with a minimal interval; we re-scan at least once
;; every 5 minutes to catch any timestamps we may have missed
@@ -1963,8 +1973,8 @@ RESPONSE is the data returned from the server by `mastodon-http--process-json',
(with-current-buffer buffer
(mastodon-tl--set-buffer-spec buffer
endpoint
- update-function)
- ;; link-header)
+ update-function
+ link-header)
(setq mastodon-tl--timestamp-update-timer
(when mastodon-tl--enable-relative-timestamps
(run-at-time (time-to-seconds
@@ -1976,7 +1986,7 @@ RESPONSE is the data returned from the server by `mastodon-http--process-json',
nil)))
(unless (string-prefix-p "accounts" endpoint)
;; for everything save profiles
- (mastodon-tl--goto-first-item))))
+ (mastodon-tl--goto-first-item)))))
(defun mastodon-tl--init-sync (buffer-name endpoint update-function)
"Initialize BUFFER-NAME with timeline targeted by ENDPOINT.