aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-http.el17
-rw-r--r--lisp/mastodon-profile.el17
-rw-r--r--lisp/mastodon-tl.el11
-rw-r--r--lisp/mastodon-toot.el5
4 files changed, 32 insertions, 18 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index e3efabe..46a6398 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -154,10 +154,19 @@ SILENT means don't message."
(with-current-buffer (mastodon-http--get url silent)
(mastodon-http--process-json)))
-(defun mastodon-http--process-json ()
+(defun mastodon-http--process-json (&optional headers)
"Process JSON response."
;; view raw response:
- ;; (switch-to-buffer (current-buffer))
+ (switch-to-buffer (current-buffer))
+ (when headers
+ (let* ((head-str (buffer-substring-no-properties
+ (point-min)
+ (re-search-forward "^$" nil 'move)))
+ (head-list (split-string head-str "\n"))
+ (head-alist (mapcar (lambda (x)
+ (split-string x ": "))
+ head-list)))
+ (setq mastodon-http-headers-alist head-alist)))
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(let ((json-string
@@ -241,13 +250,13 @@ Pass response buffer to CALLBACK function with args CBARGS."
"GET"
(url-retrieve url callback cbargs)))
-(defun mastodon-http--get-json-async (url &optional callback &rest args)
+(defun mastodon-http--get-json-async (url &optional headers callback &rest args)
"Make GET request to URL. Call CALLBACK with json-vector and ARGS."
(mastodon-http--get-async
url
(lambda (status)
(when status ;; only when we actually get sth?
- (apply callback (mastodon-http--process-json) args)))))
+ (apply callback (mastodon-http--process-json headers) args)))))
(defun mastodon-http--post-async (url args headers &optional callback &rest cbargs)
"POST asynchronously to URL with ARGS and HEADERS.
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 4aa9310..ebd1b37 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -183,7 +183,8 @@ contains")
(message "Loading your favourited toots...")
(mastodon-tl--init "favourites"
"favourites"
- 'mastodon-tl--timeline))
+ 'mastodon-tl--timeline
+ :headers))
(defun mastodon-profile--view-bookmarks ()
"Open a new buffer displaying the user's bookmarks."
@@ -556,7 +557,8 @@ FIELDS means provide a fields vector fetched by other means."
(propertize
(concat
"\n"
- (mastodon-profile--image-from-account account)
+ (mastodon-profile--image-from-account account 'avatar_static)
+ (mastodon-profile--image-from-account account 'header_static)
"\n"
(propertize (mastodon-profile--account-field
account 'display_name)
@@ -621,11 +623,12 @@ If toot is a boost, opens the profile of the booster."
(mastodon-profile--make-author-buffer
(alist-get 'account (mastodon-profile--toot-json))))
-(defun mastodon-profile--image-from-account (status)
- "Generate an image from a STATUS."
- (let ((url (alist-get 'avatar_static status)))
- (unless (equal url "/avatars/original/missing.png")
- (mastodon-media--get-media-link-rendering url))))
+(defun mastodon-profile--image-from-account (account img_type)
+ "Return a avatar image from ACCOUNT.
+IMG_TYPE is the JSON key from the account data."
+ (let ((img (alist-get img_type account)))
+ (unless (equal img "/avatars/original/missing.png")
+ (mastodon-media--get-media-link-rendering img))))
(defun mastodon-profile--show-user (user-handle)
"Query for USER-HANDLE from current status and show that user's profile."
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index a8c466d..a3ef2ae 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1153,7 +1153,7 @@ Then run CALLBACK with arguments CBARGS."
"?")
"max_id="
(mastodon-tl--as-string id)))))
- (apply 'mastodon-http--get-json-async url callback cbargs)))
+ (apply 'mastodon-http--get-json-async url nil callback cbargs)))
;; TODO
;; Look into the JSON returned here by Local
@@ -1932,14 +1932,15 @@ from the start if it is nil."
(goto-char (or mastodon-tl--update-point (point-min)))
(funcall update-function json)))))
-(defun mastodon-tl--init (buffer-name endpoint update-function)
+(defun mastodon-tl--init (buffer-name endpoint update-function &optional headers)
"Initialize BUFFER-NAME with timeline targeted by ENDPOINT asynchronously.
-
-UPDATE-FUNCTION is used to recieve more toots."
+UPDATE-FUNCTION is used to recieve more toots.
+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)))
+ url headers 'mastodon-tl--init* buffer endpoint update-function)))
(defun mastodon-tl--init* (json buffer endpoint update-function)
"Initialize BUFFER with timeline targeted by ENDPOINT.
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 7a40354..70aaf14 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -203,12 +203,13 @@ send.")
nil t)))
(mastodon-profile--update-preference "privacy" vis :source)))
-(defun mastodon-toot--get-max-toot-chars (&optional _no-toot)
+(defun mastodon-toot--get-max-toot-chars (&optional no-toot)
"Fetch max_toot_chars from `mastodon-instance-url' asynchronously.
NO-TOOT means we are not calling from a toot buffer."
(mastodon-http--get-json-async
(mastodon-http--api "instance")
- 'mastodon-toot--get-max-toot-chars-callback 'no-toot))
+ nil
+ 'mastodon-toot--get-max-toot-chars-callback no-toot))
(defun mastodon-toot--get-max-toot-chars-callback (json-response
&optional no-toot)