From 4c254408ed54dbe7a579b3e2cd6be6f26b56d346 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 12 Sep 2022 22:02:26 +0200 Subject: fix toot--kill test --- lisp/mastodon-toot.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 2f58bfb..5ec58dd 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -462,14 +462,13 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (defun mastodon-toot--kill (&optional cancel) "Kill `mastodon-toot-mode' buffer and window. CANCEL means the toot was not sent, so we save the toot text as a draft." - (with-current-buffer (get-buffer "*new toot*") - (unless (eq mastodon-toot-current-toot-text nil) - (when cancel - (cl-pushnew mastodon-toot-current-toot-text - mastodon-toot-draft-toots-list :test 'equal))) - ;; prevent some weird bug when cancelling a non-empty toot: - (delete #'mastodon-toot-save-toot-text after-change-functions) - (kill-buffer-and-window))) + (unless (eq mastodon-toot-current-toot-text nil) + (when cancel + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal))) + ;; prevent some weird bug when cancelling a non-empty toot: + (delete #'mastodon-toot-save-toot-text after-change-functions) + (kill-buffer-and-window)) (defun mastodon-toot--cancel () "Kill new-toot buffer/window. Does not POST content to Mastodon. -- cgit v1.2.3 From 179f001697703ec88651a181d18212d17f2b6dd8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 12 Sep 2022 21:34:19 +0200 Subject: factor out http--build-query-string for use PATCH reqs also --- lisp/mastodon-http.el | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index a8b3650..f73fd6b 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -73,7 +73,7 @@ "Retrieve URL asynchronously. This is a thin abstraction over the system -`url-retrieve-synchronously`. Depending on which version of this +`url-retrieve-synchronously'. Depending on which version of this is available we will call it with or without a timeout." (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) (url-retrieve-synchronously url) @@ -108,6 +108,18 @@ Unless UNAUTHENTICATED-P is non-nil." (concat "Bearer " (mastodon-auth--access-token))))))) ,body)) +(defun mastodon-http--build-query-string (args) + "Build a request query string from ARGS." + ;; (url-build-query-string args nil)) + ;; url-build-query-string adds 'nil' to empty params so lets stay with our + ;; own: + (mapconcat (lambda (arg) + (concat (url-hexify-string (car arg)) + "=" + (url-hexify-string (cdr arg)))) + args + "&")) + (defun mastodon-http--post (url args headers &optional unauthenticated-p) "POST synchronously to URL with ARGS and HEADERS. @@ -116,12 +128,7 @@ Authorization header is included by default unless UNAUTHENTICATED-P is non-nil. "POST" (let ((url-request-data (when args - (mapconcat (lambda (arg) - (concat (url-hexify-string (car arg)) - "=" - (url-hexify-string (cdr arg)))) - args - "&"))) + (mastodon-http--build-query-string args))) (url-request-extra-headers (append url-request-extra-headers ; auth set in macro ;; pleroma compat: @@ -216,7 +223,9 @@ Optionally specify the PARAMS to send." Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" - (let ((url (mastodon-http--append-query-string base-url params))) + (let ((url + (concat base-url "?" + (mastodon-http--build-query-string params)))) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions @@ -245,12 +254,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." (let ((request-timeout 5) (url-request-data (when args - (mapconcat (lambda (arg) - (concat (url-hexify-string (car arg)) - "=" - (url-hexify-string (cdr arg)))) - args - "&")))) + (mastodon-http--build-query-string args)))) (with-temp-buffer (url-retrieve url callback cbargs))))) -- cgit v1.2.3 From eaaf0b5f5c466d1e998b22f3ae91fc66c50434d8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 12 Sep 2022 21:35:34 +0200 Subject: remove unused --append-query-string --- lisp/mastodon-http.el | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f73fd6b..f32ccd4 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -173,13 +173,6 @@ Pass response buffer to CALLBACK function." (with-temp-buffer (mastodon-http--url-retrieve-synchronously url)))) -(defun mastodon-http--append-query-string (url params) - "Append PARAMS to URL as query strings and return it. - -PARAMS should be an alist as required by `url-build-query-string'." - (let ((query-string (url-build-query-string params))) - (concat url "?" query-string))) - ;; search functions: (defun mastodon-http--process-json-search () "Process JSON returned by a search query to the server." -- cgit v1.2.3 From caa5fdc35c50839a12da60f883f94e55af3a1c8b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 12 Sep 2022 21:40:22 +0200 Subject: format profile preference params to match toot-send ones --- lisp/mastodon-profile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 38aceae..ff729f0 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -274,7 +274,7 @@ Both args are strings. SOURCE means that the preference is in the 'source' part of the account JSON." (let* ((url (mastodon-http--api "accounts/update_credentials")) (pref-formatted (if source (concat "source[" pref "]") pref)) - (response (mastodon-http--patch url `((,pref-formatted ,val))))) + (response (mastodon-http--patch url `((,pref-formatted . ,val))))) (mastodon-http--triage response (lambda () (mastodon-profile-fetch-server-account-settings) -- cgit v1.2.3 From 26897d591e96493b2e724a1fe48928e635bad29b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Sep 2022 10:13:59 +0200 Subject: proper-list-p test in --process-link to handle meta fields --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8e75705..1df8bae 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -647,7 +647,9 @@ START and END are the boundaries of the link in the toot." keymap (help-echo (get-text-property start 'help-echo)) extra-properties - (toot-url (mastodon-tl--field 'url toot)) + ;; handle calling this on non-toots, e.g. for profiles: + (toot-url (when (proper-list-p toot) + (mastodon-tl--field 'url toot))) (toot-url (when toot-url (url-generic-parse-url toot-url))) (toot-instance-url (if toot-url (concat (url-type toot-url) "://" -- cgit v1.2.3 From 154d984a7af43b5e0caa9f3df7ca49f0def1dab1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Sep 2022 10:36:32 +0200 Subject: reload thread on delete toot --- lisp/mastodon-tl.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1df8bae..4726d29 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1702,7 +1702,13 @@ For use after e.g. deleting a toot." (mastodon-notifications--get)) ((equal (mastodon-tl--buffer-name) (concat "*mastodon-" (mastodon-auth--get-account-name) "-statuses*")) - (mastodon-profile--my-profile)))) + (mastodon-profile--my-profile)) + ((save-match-data + (string-match + "statuses/\\(?2:[[:digit:]]+\\)/context" + (mastodon-tl--get-endpoint)) + (mastodon-tl--thread + (match-string 2 (mastodon-tl--get-endpoint))))))) (defun mastodon-tl--more () "Append older toots to timeline, asynchronously." -- cgit v1.2.3