aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-17 11:49:49 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-17 12:05:15 +0100
commit0996c7eabfd89e6bb5fa3c9f2558c9d6ac23a44b (patch)
tree2d0f5ece6ed9cc27f0bacb17a8aa8ef3920459bd /lisp
parent0bd8213302e4cbeb8483a2bef47f09cf2d8e9da2 (diff)
refactor array params into -http--build-array-args-alist
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el5
-rw-r--r--lisp/mastodon-tl.el8
-rw-r--r--lisp/mastodon-toot.el16
3 files changed, 15 insertions, 14 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 66707b7..a127427 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -121,6 +121,11 @@ Unless UNAUTHENTICATED-P is non-nil."
args
"&"))
+(defun mastodon-http--build-array-args-alist (param-str array)
+ "Return parameters alist using PARAM-STR and ARRAY param values."
+ (cl-loop for x in array
+ collect (cons param-str x)))
+
(defun mastodon-http--post (url args headers &optional unauthenticated-p)
"POST synchronously to URL with ARGS and HEADERS.
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 8c02adf..0db517c 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -70,6 +70,8 @@
(autoload 'mastodon-profile--get-preferences-pref "mastodon-profile")
(autoload 'mastodon-http--get-response-async "mastodon-http")
(autoload 'mastodon-url-lookup "mastodon")
+(autoload 'mastodon-http--build-array-args-alist "mastodon-http")
+
(when (require 'mpv nil :no-error)
(declare-function mpv-start "mpv"))
(defvar mastodon-instance-url)
@@ -2110,10 +2112,8 @@ UPDATE-FUNCTION is used to receive more toots.
Runs synchronously."
(let* ((exclude-types (when note-type
(mastodon-notifications--filter-types-list note-type)))
- (args (when note-type
- (mapcar (lambda (x)
- `("exclude_types[]" . ,x))
- exclude-types)))
+ (args (when note-type (mastodon-http--build-array-args-alist
+ "exclude_types[]" exclude-types)))
(query-string (when note-type
(mastodon-http--build-query-string args)))
;; add note-type exclusions to endpoint so it works in `mastodon-tl--buffer-spec'
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 438e887..17a3938 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -79,6 +79,7 @@
(autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile")
(autoload 'mastodon-tl--render-text "mastodon-tl")
(autoload 'mastodon-profile-fetch-server-account-settings-maybe "mastodon-profile")
+(autoload 'mastodon-http--build-array-args-alist "mastodon-http")
;; for mastodon-toot--translate-toot-text
(autoload 'mastodon-tl--content "mastodon-tl")
@@ -615,7 +616,8 @@ to `emojify-user-emojis', and the emoji data is updated."
(defun mastodon-toot--build-poll-params ()
"Return an alist of parameters for POSTing a poll status."
(append
- (mastodon-toot--make-poll-options-params
+ (mastodon-http--build-array-args-alist
+ "poll[options][]"
(plist-get mastodon-toot-poll :options))
`(("poll[expires_in]" . ,(plist-get mastodon-toot-poll :expiry)))
`(("poll[multiple]" . ,(symbol-name (plist-get mastodon-toot-poll :multi))))
@@ -638,9 +640,9 @@ If media items have been attached and uploaded with
(symbol-name t)))
("spoiler_text" . ,spoiler)))
(args-media (when mastodon-toot--media-attachments
- (mapcar (lambda (id)
- (cons "media_ids[]" id))
- mastodon-toot--media-attachment-ids)))
+ (mastodon-http--build-array-args-alist
+ "media_ids[]"
+ mastodon-toot--media-attachment-ids)))
(args-poll (when mastodon-toot-poll
(mastodon-toot--build-poll-params)))
;; media || polls:
@@ -960,12 +962,6 @@ which is used to attach it to a toot when posting."
mastodon-toot--media-attachments))
(list "None")))
-(defun mastodon-toot--make-poll-options-params (options)
- "Return an parameter query alist from poll OPTIONS."
- (let ((key "poll[options][]"))
- (cl-loop for o in options
- collect `(,key . ,o))))
-
(defun mastodon-toot--fetch-max-poll-options ()
"Return the maximum number of poll options."
(mastodon-toot--fetch-poll-field 'max_options))