aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-auth.el41
-rw-r--r--lisp/mastodon-client.el18
-rw-r--r--lisp/mastodon-http.el151
-rw-r--r--lisp/mastodon-inspect.el1
-rw-r--r--lisp/mastodon-media.el45
-rw-r--r--lisp/mastodon-notifications.el71
-rw-r--r--lisp/mastodon-profile.el374
-rw-r--r--lisp/mastodon-search.el107
-rw-r--r--lisp/mastodon-tl.el596
-rw-r--r--lisp/mastodon-toot.el320
-rw-r--r--lisp/mastodon-views.el178
-rw-r--r--lisp/mastodon.el15
-rw-r--r--test/mastodon-profile-tests.el76
13 files changed, 844 insertions, 1149 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 0db8a19..96bf877 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -41,7 +41,7 @@
(autoload 'mastodon-client--make-user-active "mastodon-client")
(autoload 'mastodon-client--store-access-token "mastodon-client")
(autoload 'mastodon-http--api "mastodon-http")
-(autoload 'mastodon-http--append-query-string "mastodon-http")
+(autoload 'mastodon-http--concat-params-to-url "mastodon-http")
(autoload 'mastodon-http--get-json "mastodon-http")
(autoload 'mastodon-http--post "mastodon-http")
@@ -83,7 +83,7 @@ We apologize for the inconvenience.
(defun mastodon-auth--get-browser-login-url ()
"Return properly formed browser login url."
- (mastodon-http--append-query-string
+ (mastodon-http--concat-params-to-url
(concat mastodon-instance-url "/oauth/authorize/")
`(("response_type" "code")
("redirect_uri" ,mastodon-client-redirect-uri)
@@ -108,11 +108,9 @@ code. Copy this code and paste it in the minibuffer prompt."
NOTICE is displayed in vertical split occupying 50% of total
width. The buffer name of the buffer being displayed in the
window is BUFFER-NAME.
-
When optional argument ASK is given which should be a string, use
ASK as the minibuffer prompt. Return whatever user types in
response to the prompt.
-
When ASK is absent return nil."
(let ((buffer (get-buffer-create buffer-name))
(inhibit-read-only t)
@@ -170,25 +168,21 @@ When ASK is absent return nil."
(defun mastodon-auth--access-token ()
"Return the access token to use with `mastodon-instance-url'.
-
Generate/save token if none known yet."
(cond (mastodon-auth--token-alist
- ;; user variables are known and
- ;; initialised already.
+ ;; user variables are known and initialised.
(alist-get mastodon-instance-url mastodon-auth--token-alist
nil nil 'equal))
((plist-get (mastodon-client--active-user) :access_token)
- ;; user variables needs to initialised by reading from
- ;; plstore.
+ ;; user variables need to be read from plstore.
(push (cons mastodon-instance-url
(plist-get (mastodon-client--active-user) :access_token))
mastodon-auth--token-alist)
(alist-get mastodon-instance-url mastodon-auth--token-alist
nil nil 'equal))
((null mastodon-active-user)
- ;; user not aware of 2FA related changes and has not set the
- ;; `mastodon-active-user' properly. Make user aware and error
- ;; out.
+ ;; user not aware of 2FA-related changes and has not set
+ ;; `mastodon-active-user'. Make user aware and error out.
(mastodon-auth--show-notice mastodon-auth--user-unaware
"*mastodon-notice*")
(error "Variables not set properly"))
@@ -199,9 +193,7 @@ Generate/save token if none known yet."
(defun mastodon-auth--handle-token-response (response)
"Add token RESPONSE to `mastodon-auth--token-alist'.
-
The token is returned by `mastodon-auth--get-token'.
-
Handle any errors from the server."
(pcase response
((and (let token (plist-get response :access_token))
@@ -210,28 +202,23 @@ Handle any errors from the server."
(mastodon-client--store-access-token token))
(cdar (push (cons mastodon-instance-url token)
mastodon-auth--token-alist)))
-
(`(:error ,class :error_description ,error)
(error "Mastodon-auth--access-token: %s: %s" class error))
(_ (error "Unknown response from mastodon-auth--get-token!"))))
(defun mastodon-auth--get-account-name ()
"Request user credentials and return an account name."
- (alist-get
- 'acct
- (mastodon-http--get-json
- (mastodon-http--api
- "accounts/verify_credentials")
- nil
- :silent)))
+ (alist-get 'acct
+ (mastodon-http--get-json (mastodon-http--api
+ "accounts/verify_credentials")
+ nil
+ :silent)))
(defun mastodon-auth--get-account-id ()
"Request user credentials and return an account name."
- (alist-get
- 'id
- (mastodon-http--get-json
- (mastodon-http--api
- "accounts/verify_credentials"))))
+ (alist-get 'id
+ (mastodon-http--get-json (mastodon-http--api
+ "accounts/verify_credentials"))))
(defun mastodon-auth--user-acct ()
"Return a mastodon user acct name."
diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el
index b358ed7..9b4fee9 100644
--- a/lisp/mastodon-client.el
+++ b/lisp/mastodon-client.el
@@ -62,14 +62,13 @@
(defun mastodon-client--register ()
"POST client to Mastodon."
- (mastodon-http--post
- (mastodon-http--api "apps")
- `(("client_name" . "mastodon.el")
- ("redirect_uris" . ,mastodon-client-redirect-uri)
- ("scopes" . ,mastodon-client-scopes)
- ("website" . ,mastodon-client-website))
- nil
- :unauthenticated))
+ (mastodon-http--post (mastodon-http--api "apps")
+ `(("client_name" . "mastodon.el")
+ ("redirect_uris" . ,mastodon-client-redirect-uri)
+ ("scopes" . ,mastodon-client-scopes)
+ ("website" . ,mastodon-client-website))
+ nil
+ :unauthenticated))
(defun mastodon-client--fetch ()
"Return JSON from `mastodon-client--register' call."
@@ -154,7 +153,6 @@ Return the plist after the operation."
(defun mastodon-client--form-user-from-vars ()
"Create a username from user variable. Return that username.
-
Username in the form user@instance.com is formed from the
variables `mastodon-instance-url' and `mastodon-active-user'."
(concat mastodon-active-user
@@ -182,7 +180,6 @@ Otherwise return nil."
(defun mastodon-client--active-user ()
"Return the details of the currently active user.
-
Details is a plist."
(let ((active-user-details mastodon-client--active-user-details-plist))
(unless active-user-details
@@ -195,7 +192,6 @@ Details is a plist."
(defun mastodon-client ()
"Return variable client secrets to use for `mastodon-instance-url'.
-
Read plist from `mastodon-client--token-file' if variable is nil.
Fetch and store plist if `mastodon-client--read' returns nil."
(let ((client-details
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 49ffbf8..ba79bd0 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -86,8 +86,6 @@ Message status and JSON error from RESPONSE if unsuccessful."
(mastodon-http--status))))
(if (string-prefix-p "2" status)
(funcall success)
- ;; don't switch to buffer, just with-current-buffer the response:
- ;; (switch-to-buffer response)
;; 404 sometimes returns http response so --process-json fails:
(if (string-prefix-p "404" status)
(message "Error %s: page not found" status)
@@ -104,7 +102,8 @@ Message status and JSON error from RESPONSE if unsuccessful."
(defmacro mastodon-http--authorized-request (method body &optional unauthenticated-p)
"Make a METHOD type request using BODY, with Mastodon authorization.
Unless UNAUTHENTICATED-P is non-nil."
- (declare (debug 'body))
+ (declare (debug 'body)
+ (indent 1))
`(let ((url-request-method ,method)
(url-request-extra-headers
(unless ,unauthenticated-p
@@ -115,14 +114,12 @@ Unless UNAUTHENTICATED-P is non-nil."
(defun mastodon-http--build-params-string (params)
"Build a request parameters string from parameters alist PARAMS."
;; (url-build-query-string args nil))
- ;; url-build-query-string adds 'nil' to empty params so lets stay with our
+ ;; url-build-query-string adds 'nil' for empty params so lets stick with our
;; own:
(mapconcat (lambda (p)
(concat (url-hexify-string (car p))
- "="
- (url-hexify-string (cdr p))))
- params
- "&"))
+ "=" (url-hexify-string (cdr p))))
+ params "&"))
(defun mastodon-http--build-array-params-alist (param-str array)
"Return parameters alist using PARAM-STR and ARRAY param values.
@@ -133,33 +130,33 @@ Used for API form data parameters that take an array."
(defun mastodon-http--post (url &optional params headers unauthenticated-p)
"POST synchronously to URL, optionally with PARAMS and HEADERS.
Authorization header is included by default unless UNAUTHENTICATED-P is non-nil."
- (mastodon-http--authorized-request
- "POST"
- (let ((url-request-data
- (when params
- (mastodon-http--build-params-string params)))
- (url-request-extra-headers
- (append url-request-extra-headers ; auth set in macro
- ;; pleroma compat:
- (unless (assoc "Content-Type" headers)
- '(("Content-Type" . "application/x-www-form-urlencoded")))
- headers)))
- (with-temp-buffer
- (mastodon-http--url-retrieve-synchronously url)))
- unauthenticated-p))
+ (mastodon-http--authorized-request "POST"
+ (let ((url-request-data (when params
+ (mastodon-http--build-params-string params)))
+ (url-request-extra-headers
+ (append url-request-extra-headers ; auth set in macro
+ (unless (assoc "Content-Type" headers) ; pleroma compat:
+ '(("Content-Type" . "application/x-www-form-urlencoded")))
+ headers)))
+ (with-temp-buffer
+ (mastodon-http--url-retrieve-synchronously url)))
+ unauthenticated-p))
+
+(defun mastodon-http--concat-params-to-url (url params)
+ "Build a query string with PARAMS and concat to URL."
+ (if params
+ (concat url "?"
+ (mastodon-http--build-params-string params))
+ url))
(defun mastodon-http--get (url &optional params silent)
"Make synchronous GET request to URL.
PARAMS is an alist of any extra parameters to send with the request.
SILENT means don't message."
- (mastodon-http--authorized-request
- "GET"
- ;; url-request-data doesn't seem to work with GET requests:
- (let ((url (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--url-retrieve-synchronously url silent))))
+ (mastodon-http--authorized-request "GET"
+ ;; url-request-data doesn't seem to work with GET requests?:
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--url-retrieve-synchronously url silent))))
(defun mastodon-http--get-response (url &optional params no-headers silent vector)
"Make synchronous GET request to URL. Return JSON and response headers.
@@ -197,17 +194,14 @@ Callback to `mastodon-http--get-response-async', usually
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(let ((json-array-type (if vector 'vector 'list))
- (json-string
- (decode-coding-string
- (buffer-substring-no-properties (point) (point-max))
- 'utf-8)))
+ (json-string (decode-coding-string
+ (buffer-substring-no-properties (point) (point-max))
+ 'utf-8)))
(kill-buffer)
- ;; (unless (or (string-empty-p json-string) (null json-string))
(cond ((or (string-empty-p json-string) (null json-string))
nil)
- ;; if we don't have json, maybe we have a plain string error
- ;; message (misskey works like this for instance, but there are
- ;; probably less dunce ways to do this):
+ ;; if no json, maybe we have a plain string error message (misskey
+ ;; does this, but there are probably better ways to do this):
;; FIXME: friendica at least sends plain html if endpoint not found.
((not (or (string-prefix-p "\n{" json-string)
(string-prefix-p "\n[" json-string)))
@@ -232,37 +226,24 @@ Callback to `mastodon-http--get-response-async', usually
"Make DELETE request to URL.
PARAMS is an alist of any extra parameters to send with the request."
;; url-request-data only works with POST requests?
- (let ((url
- (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--authorized-request
- "DELETE"
- (with-temp-buffer
- (mastodon-http--url-retrieve-synchronously url)))))
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--authorized-request "DELETE"
+ (with-temp-buffer
+ (mastodon-http--url-retrieve-synchronously url)))))
(defun mastodon-http--put (url &optional params headers)
"Make PUT request to URL.
PARAMS is an alist of any extra parameters to send with the request.
HEADERS is an alist of any extra headers to send with the request."
- (mastodon-http--authorized-request
- "PUT"
- (let ((url-request-data
- (when params (mastodon-http--build-params-string params)))
- (url-request-extra-headers
- (append url-request-extra-headers ; auth set in macro
- ;; pleroma compat:
- (unless (assoc "Content-Type" headers)
- '(("Content-Type" . "application/x-www-form-urlencoded")))
- headers)))
- (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)))
+ (mastodon-http--authorized-request "PUT"
+ (let ((url-request-data
+ (when params (mastodon-http--build-params-string params)))
+ (url-request-extra-headers
+ (append url-request-extra-headers ; auth set in macro
+ (unless (assoc "Content-Type" headers) ; pleroma compat:
+ '(("Content-Type" . "application/x-www-form-urlencoded")))
+ headers)))
+ (with-temp-buffer (mastodon-http--url-retrieve-synchronously url)))))
;; profile update functions
@@ -275,12 +256,9 @@ Optionally specify the PARAMS to send."
(defun mastodon-http--patch (base-url &optional params)
"Make synchronous PATCH request to BASE-URL.
Optionally specify the PARAMS to send."
- (mastodon-http--authorized-request
- "PATCH"
- (let ((url
- (concat base-url "?"
- (mastodon-http--build-params-string params))))
- (mastodon-http--url-retrieve-synchronously url))))
+ (mastodon-http--authorized-request "PATCH"
+ (let ((url (mastodon-http--concat-params-to-url base-url params)))
+ (mastodon-http--url-retrieve-synchronously url))))
;; Asynchronous functions
@@ -288,13 +266,9 @@ Optionally specify the PARAMS to send."
"Make GET request to URL.
Pass response buffer to CALLBACK function with args CBARGS.
PARAMS is an alist of any extra parameters to send with the request."
- (let ((url (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--authorized-request
- "GET"
- (url-retrieve url callback cbargs))))
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--authorized-request "GET"
+ (url-retrieve url callback cbargs))))
(defun mastodon-http--get-response-async (url &optional params callback &rest cbargs)
"Make GET request to URL. Call CALLBACK with http response and CBARGS.
@@ -303,7 +277,7 @@ PARAMS is an alist of any extra parameters to send with the request."
url
params
(lambda (status)
- (when status ;; only when we actually get sth?
+ (when status ; for flakey servers
(apply callback (mastodon-http--process-response) cbargs)))))
(defun mastodon-http--get-json-async (url &optional params callback &rest cbargs)
@@ -320,14 +294,12 @@ PARAMS is an alist of any extra parameters to send with the request."
"POST asynchronously to URL with PARAMS and HEADERS.
Then run function CALLBACK with arguements CBARGS.
Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
- (mastodon-http--authorized-request
- "POST"
- (let ((request-timeout 5)
- (url-request-data
- (when params
- (mastodon-http--build-params-string params))))
- (with-temp-buffer
- (url-retrieve url callback cbargs)))))
+ (mastodon-http--authorized-request "POST"
+ (let ((request-timeout 5)
+ (url-request-data (when params
+ (mastodon-http--build-params-string params))))
+ (with-temp-buffer
+ (url-retrieve url callback cbargs)))))
;; TODO: test for curl first?
(defun mastodon-http--post-media-attachment (url filename caption)
@@ -369,9 +341,12 @@ item uploaded, and `mastodon-toot--update-status-fields' is run."
;; handle mastodon api errors
;; they have the form (error http 401)
((= (car (last error-thrown)) 401)
- (message "Got error: %s Unauthorized: The access token is invalid" error-thrown))
+ (message "Got error: %s Unauthorized: The access token is invalid"
+ error-thrown))
((= (car (last error-thrown)) 422)
- (message "Got error: %s Unprocessable entity: file or file type is unsupported or invalid" error-thrown))
+ (message "Got error: %s Unprocessable entity: file or file\
+ type is unsupported or invalid"
+ error-thrown))
(t
(message "Got error: %s Shit went south"
error-thrown))))))))
diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el
index 112a753..c332dde 100644
--- a/lisp/mastodon-inspect.el
+++ b/lisp/mastodon-inspect.el
@@ -6,7 +6,6 @@
;; Marty Hiatt <martianhiatus@riseup.net>
;; Maintainer: Marty Hiatt <martianhiatus@riseup.net>
;; Version: 1.0.0
-;; Package-Requires: ((emacs "27.1"))
;; Homepage: https://codeberg.org/martianh/mastodon.el
;; This file is not part of GNU Emacs.
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el
index 4d36f47..fd5bb77 100644
--- a/lisp/mastodon-media.el
+++ b/lisp/mastodon-media.el
@@ -145,7 +145,7 @@ IMAGE-OPTIONS are the precomputed options to apply to the image.
MARKER is the marker to where the response should be visible.
REGION-LENGTH is the length of the region that should be replaced
with the image."
- (when (marker-buffer marker) ; only if the buffer hasn't been kill in the meantime
+ (when (marker-buffer marker) ; if buffer hasn't been killed
(let ((url-buffer (current-buffer))
(is-error-response-p (eq :error (car status-plist))))
(unwind-protect
@@ -193,8 +193,7 @@ REGION-LENGTH is the range from start to propertize."
`(:max-height ,mastodon-media--preview-max-height))))))
(let ((buffer (current-buffer))
(marker (copy-marker start))
- ;; Keep url.el from spamming us with messages about connecting to hosts:
- (url-show-status nil))
+ (url-show-status nil)) ; stop url.el from spamming us about connecting
(condition-case nil
;; catch any errors in url-retrieve so as to not abort
;; whatever called us
@@ -204,11 +203,12 @@ REGION-LENGTH is the range from start to propertize."
(with-current-buffer (url-fetch-from-cache url)
(set-buffer-multibyte nil)
(goto-char (point-min))
- (zlib-decompress-region (goto-char (search-forward "\n\n")) (point-max))
- (mastodon-media--process-image-response nil marker image-options region-length url))
+ (zlib-decompress-region
+ (goto-char (search-forward "\n\n")) (point-max))
+ (mastodon-media--process-image-response
+ nil marker image-options region-length url))
;; else fetch as usual and process-image-response will cache it
- (url-retrieve url
- #'mastodon-media--process-image-response
+ (url-retrieve url #'mastodon-media--process-image-response
(list marker image-options region-length url)))
(error (with-current-buffer buffer
;; TODO: Consider adding retries
@@ -224,20 +224,20 @@ Returns the list of (`start' . `end', `media-symbol') points of
that line and string found or nil no more media links were
found."
(let ((next-pos (point)))
- (while (and (setq next-pos (next-single-property-change next-pos 'media-state))
- (or (not (eq 'needs-loading (get-text-property next-pos 'media-state)))
- (null (get-text-property next-pos 'media-url))
- (null (get-text-property next-pos 'media-type))))
+ (while
+ (and
+ (setq next-pos (next-single-property-change next-pos 'media-state))
+ (or (not (eq 'needs-loading (get-text-property next-pos 'media-state)))
+ (null (get-text-property next-pos 'media-url))
+ (null (get-text-property next-pos 'media-type))))
;; do nothing - the loop will proceed
)
(when (and next-pos (< next-pos end-pos))
(let ((media-type (get-text-property next-pos 'media-type)))
(cond
- ;; Avatars are just one character in the buffer
- ((eq media-type 'avatar)
+ ((eq media-type 'avatar) ; avatars are one character
(list next-pos (+ next-pos 1) 'avatar))
- ;; Media links are 5 character ("[img]")
- ((eq media-type 'media-link)
+ ((eq media-type 'media-link) ; media links are 5 characters: [img]
(list next-pos (+ next-pos 5) 'media-link)))))))
(defun mastodon-media--valid-link-p (link)
@@ -254,8 +254,8 @@ Replace them with the referenced image."
(save-excursion
(goto-char search-start)
(let (line-details)
- (while (setq line-details (mastodon-media--select-next-media-line
- search-end))
+ (while (setq line-details
+ (mastodon-media--select-next-media-line search-end))
(let* ((start (car line-details))
(end (cadr line-details))
(media-type (cadr (cdr line-details)))
@@ -302,17 +302,18 @@ Replace them with the referenced image."
t image-options))
" ")))
-(defun mastodon-media--get-media-link-rendering (media-url &optional full-remote-url
- type caption)
+(defun mastodon-media--get-media-link-rendering
+ (media-url &optional full-remote-url type caption)
"Return the string to be written that renders the image at MEDIA-URL.
FULL-REMOTE-URL is used for `shr-browse-image'.
TYPE is the attachment's type field on the server.
CAPTION is the image caption if provided."
- (let* ((help-echo-base "RET/i: load full image (prefix: copy URL), +/-: zoom, r: rotate, o: save preview")
+ (let* ((help-echo-base
+ "RET/i: load full image (prefix: copy URL), +/-: zoom,\
+ r: rotate, o: save preview")
(help-echo (if caption
(concat help-echo-base
- "\n\""
- caption "\"")
+ "\n\"" caption "\"")
help-echo-base)))
(concat
(mastodon-tl--propertize-img-str-or-url
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index bed2d9a..df96122 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -80,8 +80,7 @@
"Alist of subjects for notification types.")
(defvar mastodon-notifications--map
- (let ((map
- (copy-keymap mastodon-mode-map)))
+ (let ((map (copy-keymap mastodon-mode-map)))
(define-key map (kbd "a") #'mastodon-notifications--follow-request-accept)
(define-key map (kbd "j") #'mastodon-notifications--follow-request-reject)
(define-key map (kbd "C-k") #'mastodon-notifications--clear-current)
@@ -90,11 +89,8 @@
(defun mastodon-notifications--byline-concat (message)
"Add byline for TOOT with MESSAGE."
- (concat
- " "
- (propertize message 'face 'highlight)
- " "
- (cdr (assoc message mastodon-notifications--response-alist))))
+ (concat " " (propertize message 'face 'highlight)
+ " " (cdr (assoc message mastodon-notifications--response-alist))))
(defun mastodon-notifications--follow-request-process (&optional reject)
"Process the follow request at point.
@@ -108,31 +104,26 @@ follow-requests view."
(plist-get mastodon-tl--buffer-spec 'endpoint)))
(f-req-p (or (string= "follow_request" (alist-get 'type toot-json)) ;notifs
f-reqs-view-p)))
- (if f-req-p
- (let* ((account (or (alist-get 'account toot-json) ;notifs
- toot-json)) ;f-reqs
- (id (alist-get 'id account))
- (handle (alist-get 'acct account))
- (name (alist-get 'username account)))
- (if id
- (let ((response
- (mastodon-http--post
- (concat
- (mastodon-http--api "follow_requests")
- (format "/%s/%s" id (if reject
- "reject"
- "authorize"))))))
- (mastodon-http--triage response
- (lambda ()
- (if f-reqs-view-p
- (mastodon-views--view-follow-requests)
- (mastodon-tl--reload-timeline-or-profile))
- (message "Follow request of %s (@%s) %s!"
- name handle (if reject
- "rejected"
- "accepted")))))
- (message "No account result at point?")))
- (message "No follow request at point?")))))
+ (if (not f-req-p)
+ (message "No follow request at point?")
+ (let-alist (or (alist-get 'account toot-json) ;notifs
+ toot-json) ;f-reqs
+ (if .id
+ (let ((response
+ (mastodon-http--post
+ (concat
+ (mastodon-http--api "follow_requests")
+ (format "/%s/%s" .id (if reject "reject" "authorize"))))))
+ (mastodon-http--triage response
+ (lambda ()
+ (if f-reqs-view-p
+ (mastodon-views--view-follow-requests)
+ (mastodon-tl--reload-timeline-or-profile))
+ (message "Follow request of %s (@%s) %s!"
+ .username .acct (if reject
+ "rejected"
+ "accepted")))))
+ (message "No account result at point?")))))))
(defun mastodon-notifications--follow-request-accept ()
"Accept a follow request.
@@ -186,6 +177,7 @@ Status notifications are given when
(status (mastodon-tl--field 'status note))
(follower (alist-get 'username (alist-get 'account note))))
(mastodon-notifications--insert-status
+ ;; toot
(cond ((or (equal type 'follow)
(equal type 'follow-request))
;; Using reblog with an empty id will mark this as something
@@ -198,6 +190,7 @@ Status notifications are given when
note)
(t
status))
+ ;; body
(if (or (equal type 'follow)
(equal type 'follow-request))
(propertize (if (equal type 'follow)
@@ -209,13 +202,14 @@ Status notifications are given when
(if (mastodon-tl--has-spoiler status)
(mastodon-tl--spoiler status)
(mastodon-tl--content status))))
+ ;; author-byline
(if (or (equal type 'follow)
(equal type 'follow-request)
(equal type 'mention))
'mastodon-tl--byline-author
(lambda (_status)
- (mastodon-tl--byline-author
- note)))
+ (mastodon-tl--byline-author note)))
+ ;; action-byline
(lambda (_status)
(mastodon-notifications--byline-concat
(cond ((equal type 'boost)
@@ -235,13 +229,13 @@ Status notifications are given when
((equal type 'edit)
"Edited"))))
id
+ ;; base toot
(when (or (equal type 'favourite)
(equal type 'boost))
status))))
-(defun mastodon-notifications--insert-status (toot body
- author-byline action-byline id
- &optional base-toot)
+(defun mastodon-notifications--insert-status
+ (toot body author-byline action-byline id &optional base-toot)
"Display the content and byline of timeline element TOOT.
BODY will form the section of the toot above the byline.
@@ -306,8 +300,7 @@ Status notifications are created when you call
(defun mastodon-notifications--filter-types-list (type)
"Return a list of notification types with TYPE removed."
- (let ((types
- (mapcar #'car mastodon-notifications--types-alist)))
+ (let ((types (mapcar #'car mastodon-notifications--types-alist)))
(remove type types)))
(defun mastodon-notifications--clear-all ()
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 241fbbe..0c6e3b2 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -91,11 +91,6 @@
(defvar mastodon-profile-mode-map
(let ((map (make-sparse-keymap)))
- ;; conflicts with `s' keybinding to translate toot at point
- ;; seeing as we now have the C-c C-c cycle functionality,
- ;; maybe we can retire both of these awful bindings
- ;; (define-key map (kbd "s") #'mastodon-profile--open-followers)
- ;; (define-key map (kbd "g") #'mastodon-profile--open-following)
(define-key map (kbd "C-c C-c") #'mastodon-profile--account-view-cycle)
map)
"Keymap for `mastodon-profile-mode'.")
@@ -105,7 +100,6 @@
This minor mode is used for mastodon profile pages and adds a couple of
extra keybindings."
:init-value nil
- ;; modeline indicator:
:lighter " Profile"
:keymap mastodon-profile-mode-map
:group 'mastodon
@@ -169,7 +163,7 @@ NO-REBLOGS means do not display boosts in statuses."
(mastodon-profile--make-profile-buffer-for
mastodon-profile--account
"following"
- #'mastodon-profile--add-author-bylines
+ #'mastodon-profile--format-user
nil
:headers)
(error "Not in a mastodon profile")))
@@ -181,7 +175,7 @@ NO-REBLOGS means do not display boosts in statuses."
(mastodon-profile--make-profile-buffer-for
mastodon-profile--account
"followers"
- #'mastodon-profile--add-author-bylines
+ #'mastodon-profile--format-user
nil
:headers)
(error "Not in a mastodon profile")))
@@ -213,6 +207,7 @@ NO-REBLOGS means do not display boosts in statuses."
(handle (alist-get 'acct profile)))
(mastodon-views--add-account-to-list nil id handle))))
+
;;; ACCOUNT PREFERENCES
(defun mastodon-profile--get-json-value (val)
@@ -247,9 +242,7 @@ NO-REBLOGS means do not display boosts in statuses."
(msg-str "Edit your profile note. C-c C-c to send, C-c C-k to cancel."))
(switch-to-buffer-other-window buffer)
(text-mode)
- (mastodon-tl--set-buffer-spec (buffer-name buffer)
- endpoint
- nil)
+ (mastodon-tl--set-buffer-spec (buffer-name buffer) endpoint nil)
(setq-local header-line-format
(propertize msg-str
'face font-lock-comment-face))
@@ -263,7 +256,7 @@ NO-REBLOGS means do not display boosts in statuses."
'note-header t)
"\n")
(make-local-variable 'after-change-functions)
- (push #'mastodon-profile--update-note-count after-change-functions)
+ (cl-pushnew #'mastodon-profile--update-note-count after-change-functions)
(let ((start-point (point)))
(insert note)
(goto-char start-point))
@@ -348,9 +341,7 @@ Only do so if `mastodon-profile-account-settings' is nil."
Store the values in `mastodon-profile-account-settings'.
Run in `mastodon-mode-hook'.
If NO-FORCE, only fetch if `mastodon-profile-account-settings' is nil."
- (unless
- (and no-force
- mastodon-profile-account-settings)
+ (unless (and no-force mastodon-profile-account-settings)
(let ((keys '(locked discoverable display_name bot))
(source-keys '(privacy sensitive language)))
(mapc (lambda (k)
@@ -403,11 +394,10 @@ Current settings are fetched from the server."
(mastodon-profile--get-source-value key)
(mastodon-profile--get-json-value key)))
(prompt (format "Account setting %s is %s. Toggle?" key val)))
- (if val
- (when (y-or-n-p prompt)
- (mastodon-profile--update-preference (symbol-name key) "false" source))
- (when (y-or-n-p prompt)
- (mastodon-profile--update-preference (symbol-name key) "true" source)))))
+ (when (y-or-n-p prompt)
+ (mastodon-profile--update-preference (symbol-name key)
+ (if val "false" "true")
+ source))))
(defun mastodon-profile--edit-string-value (key)
"Edit the string for account preference KEY."
@@ -430,10 +420,8 @@ Returns an alist."
(format "fields_attributes[%s][value]" count)))))
(cl-loop for a-pair in keys
for b-pair in fields
- append (list (cons (car a-pair)
- (car b-pair))
- (cons (cdr a-pair)
- (cdr b-pair))))))
+ append (list (cons (car a-pair) (car b-pair))
+ (cons (cdr a-pair) (cdr b-pair))))))
(defun mastodon-profile--update-meta-fields ()
"Prompt for new metadata fields information and PATCH the server."
@@ -469,7 +457,6 @@ Returns the results as an alist."
(read-string
(format "Metadata value [%s/4] (max. 255 chars): " x)
(cdr f))))))
- ;; hack to avoiding using `string-limit', which req. 28.1:
(mapcar (lambda (x)
(cons (mastodon-profile--limit-to-255 (car x))
(mastodon-profile--limit-to-255 (cdr x))))
@@ -506,30 +493,28 @@ This endpoint only holds a few preferences. For others, see
"\n\n")))
(goto-char (point-min)))))
-;; PROFILE VIEW DETAILS
+
+;;; PROFILE VIEW DETAILS
(defun mastodon-profile--relationships-get (id)
"Fetch info about logged-in user's relationship to user with id ID."
(let* ((their-id id)
(args `(("id[]" . ,their-id)))
(url (mastodon-http--api "accounts/relationships")))
- ;; FIXME: not sure why we need to do this for relationships only!
- (car (mastodon-http--get-json url args))))
+ (car (mastodon-http--get-json url args)))) ; API takes array, just get 1st
(defun mastodon-profile--fields-get (&optional account fields)
"Fetch the fields vector (aka profile metadata) from profile of ACCOUNT.
Returns an alist.
FIELDS means provide a fields vector fetched by other means."
- (let ((fields (or fields
- (mastodon-profile--account-field account 'fields))))
+ (let ((fields (or fields (alist-get 'fields account))))
(when fields
(mastodon-tl--map-alist-vals-to-alist 'name 'value fields))))
(defun mastodon-profile--fields-insert (fields)
"Format and insert field pairs (a.k.a profile metadata) in FIELDS."
(let* ((car-fields (mapcar #'car fields))
- (left-width (cl-reduce
- #'max (mapcar #'length car-fields))))
+ (left-width (cl-reduce #'max (mapcar #'length car-fields))))
(mapconcat (lambda (field)
(mastodon-tl--render-text
(concat
@@ -541,7 +526,7 @@ FIELDS means provide a fields vector fetched by other means."
(defun mastodon-profile--get-statuses-pinned (account)
"Fetch the pinned toots for ACCOUNT."
- (let* ((id (mastodon-profile--account-field account 'id))
+ (let* ((id (alist-get 'id account))
(args `(("pinned" . "true")))
(url (mastodon-http--api (format "accounts/%s/statuses" id))))
(mastodon-http--get-json url args)))
@@ -549,143 +534,122 @@ FIELDS means provide a fields vector fetched by other means."
(defun mastodon-profile--insert-statuses-pinned (pinned-statuses)
"Insert each of the PINNED-STATUSES for a given account."
(mapc (lambda (pinned-status)
- (insert (mastodon-tl--set-face
- " :pinned: " 'success))
+ (insert (mastodon-tl--set-face " :pinned: " 'success))
(mastodon-tl--toot pinned-status))
pinned-statuses))
-(defun mastodon-profile--make-profile-buffer-for (account endpoint-type
- update-function
- &optional no-reblogs headers)
+(defun mastodon-profile--follows-p (list)
+ "T if you have any relationship with the accounts in LIST."
+ (let (result)
+ (dolist (x list result)
+ (when (not (equal :json-false x))
+ (setq result x)))))
+
+(defun mastodon-profile--make-profile-buffer-for
+ (account endpoint-type update-function &optional no-reblogs headers)
"Display profile of ACCOUNT, using ENDPOINT-TYPE and UPDATE-FUNCTION.
NO-REBLOGS means do not display boosts in statuses.
HEADERS means also fetch link headers for pagination."
- (let* ((id (mastodon-profile--account-field account 'id))
- (args `(("limit" . ,mastodon-tl--timeline-posts-count)))
- (args (if no-reblogs (push '("exclude_reblogs" . "t") args) args))
- (endpoint (format "accounts/%s/%s" id endpoint-type))
- (url (mastodon-http--api endpoint))
- (acct (mastodon-profile--account-field account 'acct))
- (buffer (concat "*mastodon-" acct "-"
- (if no-reblogs
- (concat endpoint-type "-no-boosts")
- endpoint-type)
- "*"))
- (response (if headers
- (mastodon-http--get-response url args)
- (mastodon-http--get-json url args)))
- (json (if headers (car response) response))
- (link-header (when headers
- (mastodon-tl--get-link-header-from-response
- (cdr response))))
- (note (mastodon-profile--account-field account 'note))
- (locked (mastodon-profile--account-field account 'locked))
- (followers-count (mastodon-tl--as-string
- (mastodon-profile--account-field
- account 'followers_count)))
- (following-count (mastodon-tl--as-string
- (mastodon-profile--account-field
- account 'following_count)))
- (toots-count (mastodon-tl--as-string
- (mastodon-profile--account-field
- account 'statuses_count)))
- (relationships (mastodon-profile--relationships-get id))
- (requested-you (when (not (seq-empty-p relationships))
- (alist-get 'requested_by relationships)))
- (followed-by-you (when (not (seq-empty-p relationships))
- (alist-get 'following relationships)))
- (follows-you (when (not (seq-empty-p relationships))
- (alist-get 'followed_by relationships)))
- (followsp (or (equal follows-you 't) (equal followed-by-you 't)
- (equal requested-you 't)))
- (fields (mastodon-profile--fields-get account))
- (pinned (mastodon-profile--get-statuses-pinned account))
- (joined (mastodon-profile--account-field account 'created_at)))
- (with-mastodon-buffer buffer #'mastodon-mode nil
- (mastodon-profile-mode)
- (setq mastodon-profile--account account)
- (mastodon-tl--set-buffer-spec buffer
- endpoint
- update-function
- link-header)
- (let* ((inhibit-read-only t)
- (is-statuses (string= endpoint-type "statuses"))
- (is-followers (string= endpoint-type "followers"))
- (is-following (string= endpoint-type "following"))
- (endpoint-name (cond
- (is-statuses (if no-reblogs
- " TOOTS (no boosts)"
- " TOOTS "))
- (is-followers " FOLLOWERS ")
- (is-following " FOLLOWING "))))
- (insert
- (propertize
- (concat
- "\n"
- (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)
- 'face 'mastodon-display-name-face)
- "\n"
- (propertize (concat "@" acct)
- 'face 'default)
- (if (equal locked t)
- (concat " " (mastodon-tl--symbol 'locked))
- "")
- "\n " mastodon-tl--horiz-bar "\n"
- ;; profile note:
- ;; account here to enable tab-stops in profile note
- (mastodon-tl--render-text note account)
- ;; meta fields:
- (if fields
- (concat "\n"
- (mastodon-tl--set-face
- (mastodon-profile--fields-insert fields)
- 'success))
- "")
- "\n"
- ;; Joined date:
+ (let-alist account
+ (let* ((args `(("limit" . ,mastodon-tl--timeline-posts-count)))
+ (args (if no-reblogs (push '("exclude_reblogs" . "t") args) args))
+ (endpoint (format "accounts/%s/%s" .id endpoint-type))
+ (url (mastodon-http--api endpoint))
+ (buffer (concat "*mastodon-" .acct "-"
+ (if no-reblogs
+ (concat endpoint-type "-no-boosts")
+ endpoint-type)
+ "*"))
+ (response (if headers
+ (mastodon-http--get-response url args)
+ (mastodon-http--get-json url args)))
+ (json (if headers (car response) response))
+ (link-header (when headers
+ (mastodon-tl--get-link-header-from-response
+ (cdr response))))
+ (fields (mastodon-profile--fields-get account))
+ (pinned (mastodon-profile--get-statuses-pinned account))
+ (relationships (mastodon-profile--relationships-get .id)))
+ (with-mastodon-buffer buffer #'mastodon-mode nil
+ (mastodon-profile-mode)
+ (setq mastodon-profile--account account)
+ (mastodon-tl--set-buffer-spec buffer endpoint
+ update-function link-header)
+ (let* ((inhibit-read-only t)
+ (is-statuses (string= endpoint-type "statuses"))
+ (is-followers (string= endpoint-type "followers"))
+ (is-following (string= endpoint-type "following"))
+ (endpoint-name (cond
+ (is-statuses (if no-reblogs
+ " TOOTS (no boosts)"
+ " TOOTS "))
+ (is-followers " FOLLOWERS ")
+ (is-following " FOLLOWING "))))
+ (insert
(propertize
- (mastodon-profile--format-joined-date-string joined)
- 'face 'success)
- "\n\n")
- 'profile-json account)
- ;; insert counts
- (mastodon-tl--set-face
- (concat " " mastodon-tl--horiz-bar "\n"
- " TOOTS: " toots-count " | "
- "FOLLOWERS: " followers-count " | "
- "FOLLOWING: " following-count "\n"
- " " mastodon-tl--horiz-bar "\n\n")
- 'success)
- ;; insert relationship (follows)
- (if followsp
- (mastodon-tl--set-face
- (concat (when (equal follows-you 't)
- " | FOLLOWS YOU")
- (when (equal followed-by-you 't)
- " | FOLLOWED BY YOU")
- (when (equal requested-you 't)
- " | REQUESTED TO FOLLOW YOU")
- "\n\n")
- 'success)
- "") ; if no followsp we still need str-or-char-p for insert
- ;; insert endpoint
- (mastodon-tl--set-face
- (concat " " mastodon-tl--horiz-bar "\n"
- endpoint-name "\n"
- " " mastodon-tl--horiz-bar "\n")
- 'success))
- (setq mastodon-tl--update-point (point))
- (mastodon-media--inline-images (point-min) (point))
- ;; insert pinned toots first
- (when (and pinned (equal endpoint-type "statuses"))
- (mastodon-profile--insert-statuses-pinned pinned)
- (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots
- (funcall update-function json)))
- (goto-char (point-min))))
+ (concat
+ "\n"
+ (mastodon-profile--image-from-account account 'avatar_static)
+ (mastodon-profile--image-from-account account 'header_static)
+ "\n"
+ (propertize .display_name 'face 'mastodon-display-name-face)
+ "\n"
+ (propertize (concat "@" .acct) 'face 'default)
+ (if (equal .locked t)
+ (concat " " (mastodon-tl--symbol 'locked))
+ "")
+ "\n " mastodon-tl--horiz-bar "\n"
+ ;; profile note:
+ (mastodon-tl--render-text .note account) ; account = tab-stops in profile
+ ;; meta fields:
+ (if fields
+ (concat "\n" (mastodon-tl--set-face
+ (mastodon-profile--fields-insert fields)
+ 'success))
+ "")
+ "\n"
+ ;; Joined date:
+ (propertize
+ (mastodon-profile--format-joined-date-string .created_at)
+ 'face 'success)
+ "\n\n")
+ 'profile-json account)
+ ;; insert counts
+ (mastodon-tl--set-face
+ (concat " " mastodon-tl--horiz-bar "\n"
+ " TOOTS: " (mastodon-tl--as-string .statuses_count) " | "
+ "FOLLOWERS: " (mastodon-tl--as-string .followers_count) " | "
+ "FOLLOWING: " (mastodon-tl--as-string .following_count) "\n"
+ " " mastodon-tl--horiz-bar "\n\n")
+ 'success)
+ ;; insert relationship (follows)
+ (let-alist relationships
+ (let ((followsp (mastodon-profile--follows-p
+ (list .requested_by .following .followed_by))))
+ (if followsp
+ (mastodon-tl--set-face
+ (concat (when (equal .following 't)
+ " | FOLLOWS YOU")
+ (when (equal .followed_by 't)
+ " | FOLLOWED BY YOU")
+ (when (equal .requested_by 't)
+ " | REQUESTED TO FOLLOW YOU")
+ "\n\n")
+ 'success)
+ ""))) ; for insert call
+ ;; insert endpoint
+ (mastodon-tl--set-face (concat " " mastodon-tl--horiz-bar "\n"
+ endpoint-name "\n"
+ " " mastodon-tl--horiz-bar "\n")
+ 'success))
+ (setq mastodon-tl--update-point (point))
+ (mastodon-media--inline-images (point-min) (point))
+ ;; insert pinned toots first
+ (when (and pinned (equal endpoint-type "statuses"))
+ (mastodon-profile--insert-statuses-pinned pinned)
+ (setq mastodon-tl--update-point (point))) ; updates after pinned toots
+ (funcall update-function json)))
+ (goto-char (point-min)))))
(defun mastodon-profile--format-joined-date-string (joined)
"Format a human-readable Joined string from timestamp JOINED.
@@ -721,9 +685,9 @@ IMG-TYPE is the JSON key from the account data."
user-handles
nil ; predicate
'confirm)))))
- (if (not (or
- ;; own profile has no need for toot-json test:
+ (if (not (or ; own profile has no need for toot-json test:
(equal user-handle (mastodon-auth--get-account-name))
+ (mastodon-tl--profile-buffer-p)
(mastodon-tl--property 'toot-json :no-move)))
(message "Looks like there's no toot or user at point?")
(let ((account (mastodon-profile--lookup-account-in-status
@@ -741,24 +705,17 @@ IMG-TYPE is the JSON key from the account data."
(message "Loading your profile...")
(mastodon-profile--show-user (mastodon-auth--get-account-name)))
-(defun mastodon-profile--account-field (account field)
- "Return FIELD from the ACCOUNT.
-FIELD is used to identify regions under `account'."
- (cdr (assoc field account)))
-
-(defun mastodon-profile--add-author-bylines (tootv)
- "Convert TOOTV into a author-bylines and insert.
+(defun mastodon-profile--format-user (tootv)
+ "Convert TOOTV into author-bylines and insert.
Also insert their profile note.
Used to view a user's followers and those they're following."
- ;;FIXME change the name of this fun now that we've edited what it does!
(let ((inhibit-read-only t))
(unless (seq-empty-p tootv)
(mapc (lambda (toot)
(let ((start-pos (point)))
(insert "\n"
(propertize
- (mastodon-tl--byline-author `((account . ,toot))
- :avatar)
+ (mastodon-tl--byline-author `((account . ,toot)) :avatar)
'byline 't
'toot-id (alist-get 'id toot)
'base-toot-id (mastodon-tl--toot-id toot)
@@ -767,7 +724,7 @@ Used to view a user's followers and those they're following."
(insert "\n"
(propertize
(mastodon-tl--render-text (alist-get 'note toot) nil)
- 'toot-json toot) '
+ 'toot-json toot)
"\n")))
tootv))))
@@ -778,13 +735,12 @@ If the handle does not match a search return then retun NIL."
(substring handle 1 (length handle))
handle))
(args `(("q" . ,handle)))
- (matching-account
- (seq-remove
- (lambda (x)
- (not (string= (alist-get 'acct x) handle)))
- (mastodon-http--get-json
- (mastodon-http--api "accounts/search")
- args))))
+ (matching-account (seq-remove
+ (lambda (x)
+ (not (string= (alist-get 'acct x) handle)))
+ (mastodon-http--get-json
+ (mastodon-http--api "accounts/search")
+ args))))
(when (equal 1 (length matching-account))
(elt matching-account 0))))
@@ -797,21 +753,19 @@ If the handle does not match a search return then retun NIL."
"Return all user handles found in STATUS.
These include the author, author of reblogged entries and any user mentioned."
(when status
- (let ((this-account
- (or (alist-get 'account status) ; status is a toot
- status)) ; status is a user listing
- (mentions (or (alist-get 'mentions (alist-get 'status status))
+ (let ((this-account (or (alist-get 'account status) ; status is a toot
+ status)) ; status is a user listing
+ (mentions (or (alist-get 'mentions (alist-get 'status status))
(alist-get 'mentions status)))
- (reblog (or (alist-get 'reblog (alist-get 'status status))
+ (reblog (or (alist-get 'reblog (alist-get 'status status))
(alist-get 'reblog status))))
- (seq-filter
- #'stringp
- (seq-uniq
- (seq-concatenate
- 'list
- (list (alist-get 'acct this-account))
- (mastodon-profile--extract-users-handles reblog)
- (mastodon-tl--map-alist 'acct mentions)))))))
+ (seq-filter #'stringp
+ (seq-uniq
+ (seq-concatenate
+ 'list
+ (list (alist-get 'acct this-account))
+ (mastodon-profile--extract-users-handles reblog)
+ (mastodon-tl--map-alist 'acct mentions)))))))
(defun mastodon-profile--lookup-account-in-status (handle status)
"Return account for HANDLE using hints in STATUS if possible."
@@ -819,15 +773,12 @@ These include the author, author of reblogged entries and any user mentioned."
(reblog-account (alist-get 'account (alist-get 'reblog status)))
(mention-id (seq-some
(lambda (mention)
- (when (string= handle
- (alist-get 'acct mention))
+ (when (string= handle (alist-get 'acct mention))
(alist-get 'id mention)))
(alist-get 'mentions status))))
- (cond ((string= handle
- (alist-get 'acct this-account))
+ (cond ((string= handle (alist-get 'acct this-account))
this-account)
- ((string= handle
- (alist-get 'acct reblog-account))
+ ((string= handle (alist-get 'acct reblog-account))
reblog-account)
(mention-id
(mastodon-profile--account-from-id mention-id))
@@ -842,8 +793,7 @@ Optionally provide the ID of the account to remove."
(id (or id (alist-get 'id account)))
(handle (if account
(alist-get 'acct account)
- (let ((account
- (mastodon-profile--account-from-id id)))
+ (let ((account (mastodon-profile--account-from-id id)))
(alist-get 'acct account))))
(url (mastodon-http--api
(format "accounts/%s/remove_from_followers" id))))
@@ -858,8 +808,7 @@ Optionally provide the ID of the account to remove."
(interactive)
(let* ((handles (mastodon-profile--extract-users-handles
(mastodon-profile--toot-json)))
- (handle (completing-read "Remove from followers: "
- handles nil))
+ (handle (completing-read "Remove from followers: " handles nil))
(account (mastodon-profile--lookup-account-in-status
handle (mastodon-profile--toot-json)))
(id (alist-get 'id account)))
@@ -873,11 +822,9 @@ Currently limited to 100 handles. If not found, try
(let* ((endpoint (format "accounts/%s/followers"
(mastodon-auth--get-account-id)))
(url (mastodon-http--api endpoint))
- (response (mastodon-http--get-json url
- `(("limit" . "100"))))
+ (response (mastodon-http--get-json url `(("limit" . "100"))))
(handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id response))
- (choice (completing-read "Remove from followers: "
- handles))
+ (choice (completing-read "Remove from followers: " handles))
(id (alist-get choice handles nil nil 'equal)))
(mastodon-profile--remove-user-from-followers id)))
@@ -962,16 +909,15 @@ the given account."
(defun mastodon-profile--get-familiar-followers (id)
"Return JSON data of familiar followers for account ID."
- ;; the server can handle multiple IDs, but for now we just handle one.
+ ;; the server handles multiple IDs, but we just handle one.
(let* ((params `(("id" . ,id)))
(url (mastodon-http--api "accounts/familiar_followers"))
(json (mastodon-http--get-json url params))
- (accounts (alist-get 'accounts (car json))) ; first id result
+ (accounts (alist-get 'accounts (car json))) ; first id
(handles (mastodon-tl--map-alist 'acct accounts)))
(if (null handles)
(message "Looks like there are no familiar followers for this account")
- (let ((choice (completing-read "Show profile of user: "
- handles)))
+ (let ((choice (completing-read "Show profile of user: " handles)))
(mastodon-profile--show-user choice)))))
(provide 'mastodon-profile)
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index 4b5f2e0..1d78cc2 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -62,9 +62,12 @@
"Prompt for a search QUERY and return accounts synchronously.
Returns a nested list containing user handle, display name, and URL."
(let* ((url (mastodon-http--api "accounts/search"))
- (response (if (equal mastodon-toot--completion-style-for-mentions "following")
- (mastodon-http--get-json url `(("q" . ,query) ("following" . "true")) :silent)
- (mastodon-http--get-json url `(("q" . ,query)) :silent))))
+ (response
+ (if (equal mastodon-toot--completion-style-for-mentions "following")
+ (mastodon-http--get-json
+ url `(("q" . ,query) ("following" . "true"))
+ :silent)
+ (mastodon-http--get-json url `(("q" . ,query)) :silent))))
(mapcar #'mastodon-search--get-user-info-@ response)))
;; functions for tags completion:
@@ -73,8 +76,7 @@ Returns a nested list containing user handle, display name, and URL."
"Return an alist containing tag strings plus their URLs.
QUERY is the string to search."
(let* ((url (format "%s/api/v2/search" mastodon-instance-url))
- (params `(("q" . ,query)
- ("type" . "hashtags")))
+ (params `(("q" . ,query) ("type" . "hashtags")))
(response (mastodon-http--get-json url params :silent))
(tags (alist-get 'hashtags response)))
(mapcar #'mastodon-search--get-hashtag-info tags)))
@@ -95,10 +97,8 @@ QUERY is the string to search."
(defun mastodon-search--get-full-statuses-data (response)
"For statuses list in RESPONSE, fetch and return full status JSON."
- (let ((status-ids-list
- (mapcar #'mastodon-search--get-id-from-status response)))
- (mapcar #'mastodon-search--fetch-full-status-from-id
- status-ids-list)))
+ (let ((status-ids (mapcar #'mastodon-search--get-id-from-status response)))
+ (mapcar #'mastodon-search--fetch-full-status-from-id status-ids)))
(defun mastodon-search--view-trending (type print-fun)
"Display a list of tags trending on your instance.
@@ -108,18 +108,16 @@ PRINT-FUN is the function used to print the data from the response."
(format "trends/%s" type)))
;; max for statuses = 40, for others = 20
(params (if (equal type "statuses")
- `(("limit" . "40"))
- `(("limit" . "20")) ))
+ '(("limit" . "40"))
+ '(("limit" . "20"))))
(response (mastodon-http--get-json url params))
(data (cond ((equal type "tags")
- (mapcar #'mastodon-search--get-hashtag-info
- response))
+ (mapcar #'mastodon-search--get-hashtag-info response))
((equal type "statuses")
(mastodon-search--get-full-statuses-data response))
((equal type "links")
(message "todo"))))
- (buffer (get-buffer-create
- (format "*mastodon-trending-%s*" type))))
+ (buffer (get-buffer-create (format "*mastodon-trending-%s*" type))))
(with-mastodon-buffer buffer #'mastodon-mode nil
(mastodon-tl--set-buffer-spec (buffer-name buffer)
(format "api/v1/trends/%s" type)
@@ -135,6 +133,14 @@ PRINT-FUN is the function used to print the data from the response."
;; functions for mastodon search
+(defun mastodon-search--format-heading (heading)
+ "Format HEADING as a heading."
+ (insert
+ (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n "
+ heading "\n"
+ " " mastodon-tl--horiz-bar "\n")
+ 'success)))
+
(defun mastodon-search--search-query (query)
"Prompt for a search QUERY and return accounts, statuses, and hashtags."
(interactive "sSearch mastodon for: ")
@@ -144,37 +150,18 @@ PRINT-FUN is the function used to print the data from the response."
(accts (alist-get 'accounts response))
(tags (alist-get 'hashtags response))
(statuses (alist-get 'statuses response))
- ;; this is now done in search--insert-users-propertized
- ;; (user-ids (mapcar #'mastodon-search--get-user-info
- ;; accts)) ; returns a list of three-item lists
- (tags-list (mapcar #'mastodon-search--get-hashtag-info
- tags))
- (toots-list-json
- (mastodon-search--get-full-statuses-data statuses)))
+ (tags-list (mapcar #'mastodon-search--get-hashtag-info tags))
+ (toots-list-json (mastodon-search--get-full-statuses-data statuses)))
(with-mastodon-buffer buffer #'mastodon-mode nil
- (mastodon-tl--set-buffer-spec buffer
- "api/v2/search"
- nil)
+ (mastodon-tl--set-buffer-spec buffer "api/v2/search" nil)
;; user results:
- (insert (mastodon-tl--set-face
- (concat "\n " mastodon-tl--horiz-bar "\n"
- " USERS\n"
- " " mastodon-tl--horiz-bar "\n\n")
- 'success))
+ (mastodon-search--format-heading "USERS")
(mastodon-search--insert-users-propertized accts :note)
;; hashtag results:
- (insert (mastodon-tl--set-face
- (concat "\n " mastodon-tl--horiz-bar "\n"
- " HASHTAGS\n"
- " " mastodon-tl--horiz-bar "\n\n")
- 'success))
+ (mastodon-search--format-heading "HASHTAGS")
(mastodon-search--print-tags-list tags-list)
;; status results:
- (insert (mastodon-tl--set-face
- (concat "\n " mastodon-tl--horiz-bar "\n"
- " STATUSES\n"
- " " mastodon-tl--horiz-bar "\n")
- 'success))
+ (mastodon-search--format-heading "STATUSES")
(mapc #'mastodon-tl--toot toots-list-json)
(goto-char (point-min)))))
@@ -194,32 +181,32 @@ user's profile note. This is also called by
"Propertize display string for ACCT, optionally including profile NOTE."
(let ((user (mastodon-search--get-user-info acct)))
(propertize
- (concat (propertize (car user)
- 'face 'mastodon-display-name-face
- 'byline t
- 'toot-id "0")
- " : \n : "
- (propertize (concat "@" (cadr user))
- 'face 'mastodon-handle-face
- 'mouse-face 'highlight
- 'mastodon-tab-stop 'user-handle
- 'keymap mastodon-tl--link-keymap
- 'mastodon-handle (concat "@" (cadr user))
- 'help-echo (concat "Browse user profile of @" (cadr user)))
- " : \n"
- (if note
- (mastodon-tl--render-text (cadddr user) acct)
- "")
- "\n")
- 'toot-json acct))) ; so named for compat w other processing functions
+ (concat
+ (propertize (car user)
+ 'face 'mastodon-display-name-face
+ 'byline t
+ 'toot-id "0")
+ " : \n : "
+ (propertize (concat "@" (cadr user))
+ 'face 'mastodon-handle-face
+ 'mouse-face 'highlight
+ 'mastodon-tab-stop 'user-handle
+ 'keymap mastodon-tl--link-keymap
+ 'mastodon-handle (concat "@" (cadr user))
+ 'help-echo (concat "Browse user profile of @" (cadr user)))
+ " : \n"
+ (if note
+ (mastodon-tl--render-text (cadddr user) acct)
+ "")
+ "\n")
+ 'toot-json acct))) ; for compat w other processing functions
(defun mastodon-search--print-tags-list (tags)
"Insert a propertized list of TAGS."
(mapc (lambda (el)
(insert
" : "
- (propertize (concat "#"
- (car el))
+ (propertize (concat "#" (car el))
'face '(:box t)
'mouse-face 'highlight
'mastodon-tag (car el)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index f9db25a..79897bd 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -60,7 +60,6 @@
(autoload 'mastodon-media--inline-images "mastodon-media")
(autoload 'mastodon-notifications--filter-types-list "mastodon-notifications")
(autoload 'mastodon-notifications--get-mentions "mastodon-notifications")
-(autoload 'mastodon-profile--account-field "mastodon-profile")
(autoload 'mastodon-profile--account-from-id "mastodon-profile")
(autoload 'mastodon-profile--extract-users-handles "mastodon-profile")
(autoload 'mastodon-profile--get-preferences-pref "mastodon-profile")
@@ -283,7 +282,8 @@ than `switch-to-buffer'."
"Move to the next interesting item.
This could be the next toot, link, or image; whichever comes first.
Don't move if nothing else to move to is found, i.e. near the end of the buffer.
-This also skips tab items in invisible text, i.e. hidden spoiler text."
+This also skips tab items in invisible text, i.e. hidden spoiler text.
+PREVIOUS means move to previous item."
(interactive)
(let (next-range
(search-pos (point)))
@@ -425,15 +425,12 @@ With a double PREFIX arg, limit results to your own instance."
(let ((list (mastodon-http--build-array-params-alist "any[]" (cdr tag))))
(while list
(push (pop list) params))))
- (mastodon-tl--init (if (listp tag)
- "tags-multiple"
- (concat "tag-" tag))
- (concat "timelines/tag/" (if (listp tag)
- ;; endpoint must be /tag/:sth
- (car tag) tag))
- 'mastodon-tl--timeline
- nil
- params)))
+ (mastodon-tl--init
+ (if (listp tag) "tags-multiple" (concat "tag-" tag))
+ (concat "timelines/tag/" (if (listp tag) (car tag) tag)) ; must be /tag/:sth
+ 'mastodon-tl--timeline
+ nil
+ params)))
;;; BYLINES, etc.
@@ -441,9 +438,8 @@ With a double PREFIX arg, limit results to your own instance."
(defun mastodon-tl--message-help-echo ()
"Call message on `help-echo' property at point.
Do so if type of status at poins is not follow_request/follow."
- (let ((type (alist-get
- 'type
- (mastodon-tl--property 'toot-json :no-move)))
+ (let ((type (alist-get 'type
+ (mastodon-tl--property 'toot-json :no-move)))
(echo (mastodon-tl--property 'help-echo :no-move)))
(when echo ; not for followers/following in profile
(unless (or (string= type "follow_request")
@@ -453,25 +449,20 @@ Do so if type of status at poins is not follow_request/follow."
(defun mastodon-tl--byline-author (toot &optional avatar)
"Propertize author of TOOT.
With arg AVATAR, include the account's avatar image."
- (let* ((account (alist-get 'account toot))
- (handle (alist-get 'acct account))
- (name (if (not (string-empty-p (alist-get 'display_name account)))
- (alist-get 'display_name account)
- (alist-get 'username account)))
- (profile-url (alist-get 'url account))
- (avatar-url (alist-get 'avatar account)))
+ (let-alist toot
(concat
- ;; avatar insertion moved up to `mastodon-tl--byline' by default in order
- ;; to be outside of text prop 'byline t. arg avatar is used by
- ;; `mastodon-profile--add-author-bylines'
- (when (and avatar
+ ;; avatar insertion moved up to `mastodon-tl--byline' by default to be
+ ;; outside 'byline propt.
+ (when (and avatar ; used by `mastodon-profile--format-user'
mastodon-tl--show-avatars
mastodon-tl--display-media-p
(if (version< emacs-version "27.1")
(image-type-available-p 'imagemagick)
(image-transforms-p)))
- (mastodon-media--get-avatar-rendering avatar-url))
- (propertize name
+ (mastodon-media--get-avatar-rendering .account.avatar))
+ (propertize (if (not (string-empty-p .account.display_name))
+ .account.display_name
+ .account.username)
'face 'mastodon-display-name-face
;; enable playing of videos when point is on byline:
'attachments (mastodon-tl--get-attachments-for-byline toot)
@@ -485,15 +476,15 @@ With arg AVATAR, include the account's avatar image."
(string-suffix-p "-following*" (buffer-name)))
(mastodon-tl--format-byline-help-echo toot)))
" ("
- (propertize (concat "@" handle)
+ (propertize (concat "@" .account.acct)
'face 'mastodon-handle-face
'mouse-face 'highlight
- 'mastodon-tab-stop 'user-handle
- 'account account
- 'shr-url profile-url
- 'keymap mastodon-tl--link-keymap
- 'mastodon-handle (concat "@" handle)
- 'help-echo (concat "Browse user profile of @" handle))
+ 'mastodon-tab-stop 'user-handle
+ 'account .account
+ 'shr-url .account.url
+ 'keymap mastodon-tl--link-keymap
+ 'mastodon-handle (concat "@" .account.acct)
+ 'help-echo (concat "Browse user profile of @" .account.acct))
")")))
(defun mastodon-tl--format-byline-help-echo (toot)
@@ -503,11 +494,10 @@ moving image media from the byline.
Used when point is at the start of a byline, i.e. where
`mastodon-tl--goto-next-toot' leaves point."
(let* ((toot-to-count
- (or
- ;; simply praying this order works
+ (or ; simply praying this order works
(alist-get 'status toot) ; notifications timeline
- ;; fol-req notif, has 'type
- ;; placed before boosts coz fol-reqs have a (useless) reblog entry:
+ ;; fol-req notif, has 'type placed before boosts coz fol-reqs have
+ ;; a (useless) reblog entry:
(when (and (or (mastodon-tl--buffer-type-eq 'notifications)
(mastodon-tl--buffer-type-eq 'mentions))
(alist-get 'type toot))
@@ -521,9 +511,8 @@ Used when point is at the start of a byline, i.e. where
(format-media (when media-types
(format "media: %s"
(mapconcat #'identity media-types " "))))
- (format-media-binding (when (and (or
- (member "video" media-types)
- (member "gifv" media-types))
+ (format-media-binding (when (and (or (member "video" media-types)
+ (member "gifv" media-types))
(require 'mpv nil :no-error))
(format " | C-RET to view with mpv"))))
(format "%s" (concat format-media format-media-binding))))))
@@ -537,25 +526,19 @@ Used when point is at the start of a byline, i.e. where
"Return a list of attachment URLs and types for TOOT.
The result is added as an attachments property to author-byline."
(let ((media-attachments (mastodon-tl--field 'media_attachments toot)))
- (mapcar
- (lambda (attachement)
- (let ((remote-url
- (or (alist-get 'remote_url attachement)
- ;; fallback b/c notifications don't have remote_url
- (alist-get 'url attachement)))
- (type (alist-get 'type attachement)))
- `(:url ,remote-url :type ,type)))
- media-attachments)))
+ (mapcar (lambda (attachment)
+ (let-alist attachment
+ (list :url (or .remote_url .url) ; fallback for notifications
+ :type .type)))
+ media-attachments)))
(defun mastodon-tl--byline-boosted (toot)
"Add byline for boosted data from TOOT."
(let ((reblog (alist-get 'reblog toot)))
(when reblog
(concat
- "\n "
- (propertize "Boosted" 'face 'mastodon-boosted-face)
- " "
- (mastodon-tl--byline-author reblog)))))
+ "\n " (propertize "Boosted" 'face 'mastodon-boosted-face)
+ " " (mastodon-tl--byline-author reblog)))))
(defun mastodon-tl--format-faved-or-boosted-byline (letter)
"Format the byline marker for a boosted or favourited status.
@@ -583,8 +566,7 @@ DETAILED-P means display more detailed info. For now
this just means displaying toot client."
(let* ((created-time
;; bosts and faves in notifs view
- ;; (makes timestamps be for the original toot
- ;; not the boost/fave):
+ ;; (makes timestamps be for the original toot not the boost/fave):
(or (mastodon-tl--field 'created_at
(mastodon-tl--field 'status toot))
;; all other toots, inc. boosts/faves in timelines:
@@ -653,10 +635,10 @@ this just means displaying toot client."
'face 'mastodon-display-name-face
'follow-link t
'mouse-face 'highlight
- 'mastodon-tab-stop 'shr-url
- 'shr-url app-url
+ 'mastodon-tab-stop 'shr-url
+ 'shr-url app-url
'help-echo app-url
- 'keymap mastodon-tl--shr-map-replacement)))))
+ 'keymap mastodon-tl--shr-map-replacement)))))
(if edited-time
(concat
" "
@@ -793,13 +775,10 @@ START and END are the boundaries of the link in the toot."
url toot-instance-url))
(maybe-userhandle
(if (proper-list-p toot) ; fails for profile buffers?
- (or (mastodon-tl--userhandle-from-mentions toot
- link-str)
+ (or (mastodon-tl--userhandle-from-mentions toot link-str)
;; FIXME: if prev always works, cut this:
- (mastodon-tl--extract-userhandle-from-url
- url link-str))
- (mastodon-tl--extract-userhandle-from-url
- url link-str))))
+ (mastodon-tl--extract-userhandle-from-url url link-str))
+ (mastodon-tl--extract-userhandle-from-url url link-str))))
(cond (;; Hashtags:
maybe-hashtag
(setq mastodon-tab-stop-type 'hashtag
@@ -820,9 +799,7 @@ START and END are the boundaries of the link in the toot."
(when maybe-userid
(list 'account-id maybe-userid))))))
;; Anything else:
- (t
- ;; Leave it as a url handled by shr.el.
- ;; (We still have to replace the keymap so that tabbing works.)
+ (t ; Leave it as a url handled by shr.el.
(setq keymap (if (eq shr-map (get-text-property start 'keymap))
mastodon-tl--shr-map-replacement
mastodon-tl--shr-image-map-replacement)
@@ -836,18 +813,18 @@ START and END are the boundaries of the link in the toot."
(defun mastodon-tl--userhandle-from-mentions (toot link)
"Extract a user handle from mentions in json TOOT.
-LINK is maybe the '@handle' to search for."
+LINK is maybe the `@handle' to search for."
(mastodon-tl--extract-el-from-mentions 'acct toot link))
(defun mastodon-tl--extract-userid-toot (toot link)
"Extract a user id for an ACCT from mentions in a TOOT.
-LINK is maybe the '@handle' to search for."
+LINK is maybe the `@handle' to search for."
(mastodon-tl--extract-el-from-mentions 'id toot link))
(defun mastodon-tl--extract-el-from-mentions (el toot link)
"Extract element EL from TOOT mentions that matches LINK.
-LINK should be a simple handle string with no domain, i.e. @user.
-Return nil if no matching element"
+LINK should be a simple handle string with no domain, i.e. \"@user\".
+Return nil if no matching element."
;; Must return nil if nothing found!
;; TODO: we should break the while loop as soon as we get sth
(let ((mentions (append (alist-get 'mentions toot) nil)))
@@ -856,8 +833,7 @@ Return nil if no matching element"
(name (substring-no-properties link 1 (length link))) ; cull @
return)
(while mention
- (when (string= (alist-get 'username mention)
- name)
+ (when (string= name (alist-get 'username mention))
(setq return (alist-get el mention)))
(setq mention (pop mentions)))
return))))
@@ -874,7 +850,7 @@ this should be of the form <at-sign><user id>, e.g. \"@Gargon\"."
(string= (downcase buffer-text)
(downcase (substring (url-filename parsed-url) 1))))
(if local-p
- buffer-text ; no instance suffic for local mention
+ buffer-text ; no instance suffix for local mention
(concat buffer-text "@" (url-host parsed-url))))))
(defun mastodon-tl--extract-hashtag-from-url (url instance-url)
@@ -898,17 +874,15 @@ the toot)."
(defun mastodon-tl--make-link (string link-type)
"Return a propertized version of STRING that will act like link.
LINK-TYPE is the type of link to produce."
- (let ((help-text (cond
- ((eq link-type 'content-warning)
- "Toggle hidden text")
- (t
- (error "Unknown link type %s" link-type)))))
- (propertize
- string
- 'mastodon-tab-stop link-type
- 'mouse-face 'highlight
- 'keymap mastodon-tl--link-keymap
- 'help-echo help-text)))
+ (let ((help-text (cond ((eq link-type 'content-warning)
+ "Toggle hidden text")
+ (t
+ (error "Unknown link type %s" link-type)))))
+ (propertize string
+ 'mastodon-tab-stop link-type
+ 'mouse-face 'highlight
+ 'keymap mastodon-tl--link-keymap
+ 'help-echo help-text)))
(defun mastodon-tl--do-link-action-at-point (position)
"Do the action of the link at POSITION.
@@ -918,7 +892,8 @@ Used for hitting RET on a given link."
(cond ((eq link-type 'content-warning)
(mastodon-tl--toggle-spoiler-text position))
((eq link-type 'hashtag)
- (mastodon-tl--show-tag-timeline nil (get-text-property position 'mastodon-tag)))
+ (mastodon-tl--show-tag-timeline
+ nil (get-text-property position 'mastodon-tag)))
;; 'account / 'account-id is not set for mentions, only bylines
((eq link-type 'user-handle)
(let ((account-json (get-text-property position 'account))
@@ -1005,17 +980,15 @@ content warning message are displayed. The content warning
message is a link which unhides/hides the main body."
(let* ((spoiler (mastodon-tl--field 'spoiler_text toot))
(string (mastodon-tl--set-face
- ;; remove trailing whitespace
(mastodon-tl--clean-tabs-and-nl
(mastodon-tl--render-text spoiler toot))
'default))
- (message (concat
- " " mastodon-tl--horiz-bar "\n "
- (mastodon-tl--make-link
- (concat "CW: " string)
- 'content-warning)
- "\n "
- mastodon-tl--horiz-bar "\n"))
+ (message (concat " " mastodon-tl--horiz-bar "\n "
+ (mastodon-tl--make-link
+ (concat "CW: " string)
+ 'content-warning)
+ "\n "
+ mastodon-tl--horiz-bar "\n"))
(cw (mastodon-tl--set-face message 'mastodon-cw-face)))
(concat
cw
@@ -1048,10 +1021,8 @@ message is a link which unhides/hides the main body."
(defun mastodon-tl--media-attachment (media-attachment)
"Return a propertized string for MEDIA-ATTACHMENT."
(let* ((preview-url (alist-get 'preview_url media-attachment))
- (remote-url
- (or (alist-get 'remote_url media-attachment)
- ;; fallback b/c notifications don't have remote_url
- (alist-get 'url media-attachment)))
+ (remote-url (or (alist-get 'remote_url media-attachment)
+ (alist-get 'url media-attachment))) ; for notifs
(type (alist-get 'type media-attachment))
(caption (alist-get 'description media-attachment))
(display-str
@@ -1065,18 +1036,17 @@ message is a link which unhides/hides the main body."
preview-url remote-url type caption) ; 2nd arg for shr-browse-url
;; return URL/caption:
(concat (mastodon-tl--propertize-img-str-or-url
- (concat "Media:: " preview-url) ;; string
+ (concat "Media:: " preview-url) ; string
preview-url remote-url type caption
- display-str ;; display
+ display-str ; display
;; FIXME: shr-link underlining is awful for captions with
;; newlines, as the underlining runs to the edge of the
- ;; frame even if the text doesn'
+ ;; frame even if the text doesn't
'shr-link)
"\n"))))
-(defun mastodon-tl--propertize-img-str-or-url (str media-url full-remote-url
- type help-echo
- &optional display face)
+(defun mastodon-tl--propertize-img-str-or-url
+ (str media-url full-remote-url type help-echo &optional display face)
"Propertize an media placeholder string \"[img]\" or media URL.
STR is the string to propertize, MEDIA-URL is the preview link,
FULL-REMOTE-URL is the link to the full resolution image on the
@@ -1095,62 +1065,58 @@ HELP-ECHO, DISPLAY, and FACE are the text properties to add."
'keymap mastodon-tl--shr-image-map-replacement
'help-echo (if (or (string= type "image")
(string= type nil)
- (string= type "unknown")) ;handle borked images
+ (string= type "unknown")) ; handle borked images
help-echo
(concat help-echo "\nC-RET: play " type " with mpv"))))
;; POLLS
+(defun mastodon-tl--format-poll-option (option option-counter longest-option)
+ "Format poll OPTION. OPTION-COUNTER is just a counter.
+LONGEST-OPTION is the option whose length determines the formatting."
+ (format "%s: %s%s%s\n"
+ (setq option-counter (1+ option-counter))
+ (propertize (alist-get 'title option)
+ 'face 'success)
+ (make-string (1+ (- (length longest-option)
+ (length (alist-get 'title option))))
+ ?\ )
+ ;; TODO: disambiguate no votes from hidden votes
+ (format "[%s votes]" (or (alist-get 'votes_count option)
+ "0"))))
+
(defun mastodon-tl--get-poll (toot)
"If TOOT includes a poll, return it as a formatted string."
- (let* ((poll (mastodon-tl--field 'poll toot))
- (expiry (mastodon-tl--field 'expires_at poll))
- (expired-p (if (eq (mastodon-tl--field 'expired poll) :json-false) nil t))
- ;; (multi (mastodon-tl--field 'multiple poll))
- (voters-count (mastodon-tl--field 'voters_count poll))
- (vote-count (mastodon-tl--field 'votes_count poll))
- (options (mastodon-tl--field 'options poll))
- (option-titles (mastodon-tl--map-alist 'title options))
- (longest-option (car (sort option-titles
- (lambda (x y)
- (> (length x)
- (length y))))))
- (option-counter 0))
- (concat "\nPoll: \n\n"
- (mapconcat (lambda (option)
- (progn
- (format "%s: %s%s%s\n"
- (setq option-counter (1+ option-counter))
- (propertize (alist-get 'title option)
- 'face 'success)
- (make-string
- (1+
- (- (length longest-option)
- (length (alist-get 'title
- option))))
- ?\ )
- ;; TODO: disambiguate no votes from hidden votes
- (format "[%s votes]" (or (alist-get 'votes_count option)
- "0")))))
- options
- "\n")
- "\n"
- (propertize
- (cond (voters-count ; sometimes it is nil
- (if (= voters-count 1)
- (format "%s person | " voters-count)
- (format "%s people | " voters-count)))
- (vote-count
- (format "%s votes | " vote-count))
- (t
- ""))
- 'face 'font-lock-comment-face)
- (let ((str (if expired-p
- "Poll expired."
- (mastodon-tl--format-poll-expiry expiry))))
- (propertize str 'face 'font-lock-comment-face))
- "\n")))
+ (let-alist (mastodon-tl--field 'poll toot) ; toot or reblog
+ (let* ((option-titles (mastodon-tl--map-alist 'title .options))
+ (longest-option (car (sort option-titles
+ (lambda (x y)
+ (> (length x)
+ (length y))))))
+ (option-counter 0))
+ (concat "\nPoll: \n\n"
+ (mapconcat (lambda (option)
+ (mastodon-tl--format-poll-option
+ option option-counter longest-option))
+ .options
+ "\n")
+ "\n"
+ (propertize
+ (cond (.voters_count ; sometimes it is nil
+ (if (= .voters_count 1)
+ (format "%s person | " .voters_count)
+ (format "%s people | " .voters_count)))
+ (.vote_count
+ (format "%s votes | " .vote_count))
+ (t
+ ""))
+ 'face 'font-lock-comment-face)
+ (let ((str (if (eq .expired :json-false)
+ (mastodon-tl--format-poll-expiry .expires_at)
+ "Poll expired.")))
+ (propertize str 'face 'font-lock-comment-face))
+ "\n"))))
(defun mastodon-tl--format-poll-expiry (timestamp)
"Convert poll expiry TIMESTAMP into a descriptive string."
@@ -1166,40 +1132,39 @@ HELP-ECHO, DISPLAY, and FACE are the text properties to add."
(plist-get parsed :minutes)))
((> (plist-get parsed :minutes) 0)
(format "%s minutes left" (plist-get parsed :minutes)))
- (t ;; we failed to guess:
+ (t ; we failed to guess:
(format "%s days, %s hours, %s minutes left"
(plist-get parsed :days)
(plist-get parsed :hours)
(plist-get parsed :minutes))))))
+(defun mastodon-tl--read-poll-option ()
+ "Read a poll option to vote on a poll."
+ (list (let* ((toot (mastodon-tl--property 'toot-json))
+ (poll (mastodon-tl--field 'poll toot))
+ (options (mastodon-tl--field 'options poll))
+ (options-titles (mastodon-tl--map-alist 'title options))
+ (options-number-seq (number-sequence 1 (length options)))
+ (options-numbers (mapcar #'number-to-string options-number-seq))
+ (options-alist (cl-mapcar #'cons options-numbers options-titles))
+ ;; we display both option number and the option title
+ ;; but also store both as cons cell as cdr, as we need it below
+ (candidates (mapcar (lambda (cell)
+ (cons (format "%s | %s" (car cell) (cdr cell))
+ cell))
+ options-alist)))
+ (if (null poll)
+ (message "No poll here.")
+ ;; var "option" = just the cdr, a cons of option number and desc
+ (cdr (assoc (completing-read "Poll option to vote for: "
+ candidates
+ nil
+ t) ; require match
+ candidates))))))
+
(defun mastodon-tl--poll-vote (option)
"If there is a poll at point, prompt user for OPTION to vote on it."
- (interactive
- (list
- (let* ((toot (mastodon-tl--property 'toot-json))
- (reblog (alist-get 'reblog toot))
- (poll (or (alist-get 'poll reblog)
- (mastodon-tl--field 'poll toot)))
- (options (mastodon-tl--field 'options poll))
- (options-titles (mastodon-tl--map-alist 'title options))
- (options-number-seq (number-sequence 1 (length options)))
- (options-numbers (mapcar #'number-to-string options-number-seq))
- (options-alist (cl-mapcar #'cons options-numbers options-titles))
- ;; we display both option number and the option title
- ;; but also store both as cons cell as cdr, as we need it below
- (candidates (mapcar (lambda (cell)
- (cons (format "%s | %s" (car cell) (cdr cell))
- cell))
- options-alist)))
- (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json)))
- (message "No poll here.")
- ;; var "option" = just the cdr, a cons of option number and desc
- (cdr (assoc
- (completing-read "Poll option to vote for: "
- candidates
- nil ; (predicate)
- t) ; require match
- candidates))))))
+ (interactive (mastodon-tl--read-poll-option))
(if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json)))
(message "No poll here.")
(let* ((toot (mastodon-tl--property 'toot-json))
@@ -1243,15 +1208,11 @@ HELP-ECHO, DISPLAY, and FACE are the text properties to add."
URL and TYPE are provided when called while point is on byline,
in which case play first video or gif from current toot."
(interactive)
- (let ((url (or
- ;; point in byline:
- url
- ;; point in toot:
- (mastodon-tl--property 'image-url :no-move)))
- (type (or ;; in byline:
- type
- ;; point in toot:
- (mastodon-tl--property 'mastodon-media-type :no-move))))
+ (let ((url (or url ; point in byline:
+ (mastodon-tl--property 'image-url :no-move))) ; point in toot
+ (type (or type ; in byline
+ ;; point in toot:
+ (mastodon-tl--property 'mastodon-media-type :no-move))))
(if url
(if (or (equal type "gifv")
(equal type "video"))
@@ -1272,18 +1233,16 @@ Runs `mastodon-tl--render-text' and fetches poll or media."
(poll-p (if reblog
(alist-get 'poll reblog)
(alist-get 'poll toot))))
- (concat
- (mastodon-tl--render-text content toot)
- (when poll-p
- (mastodon-tl--get-poll toot))
- (mastodon-tl--media toot))))
+ (concat (mastodon-tl--render-text content toot)
+ (when poll-p
+ (mastodon-tl--get-poll toot))
+ (mastodon-tl--media toot))))
(defun mastodon-tl--prev-toot-id ()
"Return the id of the last toot inserted into the buffer."
- (let ((prev-pos (1- (save-excursion
- (previous-single-property-change
- (point)
- 'base-toot-id)))))
+ (let ((prev-pos
+ (1- (save-excursion
+ (previous-single-property-change (point) 'base-toot-id)))))
(get-text-property prev-pos 'base-toot-id)))
(defun mastodon-tl--after-reply-status (reply-to-id)
@@ -1328,7 +1287,6 @@ THREAD means the status will be displayed in a thread view."
'line-prefix bar
'wrap-prefix bar))
body)
- ;; body
" \n"
(mastodon-tl--byline toot author-byline action-byline detailed-p))
'toot-id (or id ; notification's own id
@@ -1337,8 +1295,7 @@ THREAD means the status will be displayed in a thread view."
;; if status is a notif, get id from base-toot
;; (-tl--toot-id toot) will not work here:
(or base-toot
- ;; else normal toot with reblog check:
- toot))
+ toot)) ; else normal toot with reblog check
'toot-json toot
'base-toot base-toot)
"\n")
@@ -1366,38 +1323,31 @@ When the TOOT is a reblog (boost), statistics from reblogged
toots are returned.
To disable showing the stats, customize
`mastodon-tl--show-stats'."
- (when-let ((toot (mastodon-tl--toot-for-stats toot)))
- (let* ((favourites-count (alist-get 'favourites_count toot))
- (favourited (equal 't (alist-get 'favourited toot)))
- (faves-prop (propertize (format "%s" favourites-count)
- 'favourites-count favourites-count))
- (boosts-count (alist-get 'reblogs_count toot))
- (boosted (equal 't (alist-get 'reblogged toot)))
- (boosts-prop (propertize (format "%s" boosts-count)
- 'boosts-count boosts-count))
- (replies-count (alist-get 'replies_count toot))
- (favourites (format "%s %s" faves-prop ;favourites-count
- (mastodon-tl--symbol 'favourite)))
- (boosts (format "%s %s" boosts-prop ;boosts-count
- (mastodon-tl--symbol 'boost)))
- (replies (format "%s %s" replies-count (mastodon-tl--symbol 'reply)))
+ (let-alist (mastodon-tl--toot-for-stats toot)
+ (let* ((faves-prop (propertize (format "%s" .favourites_count)
+ 'favourites-count .favourites_count))
+ (boosts-prop (propertize (format "%s" .reblogs_count)
+ 'boosts-count .reblogs_count))
+ (faves (format "%s %s" faves-prop (mastodon-tl--symbol 'favourite)))
+ (boosts (format "%s %s" boosts-prop (mastodon-tl--symbol 'boost)))
+ (replies (format "%s %s" .replies_count (mastodon-tl--symbol 'reply)))
(status (concat
- (propertize favourites
- 'favourited-p favourited
+ (propertize faves
+ 'favourited-p (eq 't .favourited)
'favourites-field t
- 'help-echo (format "%s favourites" favourites-count)
+ 'help-echo (format "%s favourites" .favourites_count)
'face font-lock-comment-face)
(propertize " | " 'face font-lock-comment-face)
(propertize boosts
- 'boosted-p boosted
+ 'boosted-p (eq 't .reblogged)
'boosts-field t
- 'help-echo (format "%s boosts" boosts-count)
+ 'help-echo (format "%s boosts" .reblogs_count)
'face font-lock-comment-face)
(propertize " | " 'face font-lock-comment-face)
(propertize replies
'replies-field t
- 'replies-count replies-count
- 'help-echo (format "%s replies" replies-count)
+ 'replies-count .replies_count
+ 'help-echo (format "%s replies" .replies_count)
'face font-lock-comment-face)))
(status
(concat
@@ -1419,16 +1369,11 @@ this just means displaying toot client.
THREAD means the status will be displayed in a thread view."
(mastodon-tl--insert-status
toot
- (mastodon-tl--clean-tabs-and-nl
- (if (mastodon-tl--has-spoiler toot)
- (mastodon-tl--spoiler toot)
- (mastodon-tl--content toot)))
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted
- nil
- nil
- detailed-p
- thread))
+ (mastodon-tl--clean-tabs-and-nl (if (mastodon-tl--has-spoiler toot)
+ (mastodon-tl--spoiler toot)
+ (mastodon-tl--content toot)))
+ 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted
+ nil nil detailed-p thread))
(defun mastodon-tl--timeline (toots &optional thread)
"Display each toot in TOOTS.
@@ -1443,8 +1388,8 @@ THREAD means the status will be displayed in a thread view."
(mastodon-tl--get-buffer-property 'hide-replies nil :no-error)
;; loading a tl with a prefix arg:
(mastodon-tl--hide-replies-p current-prefix-arg))
- (cl-remove-if-not #'mastodon-tl--is-reply toots)
- toots)))
+ (cl-remove-if-not #'mastodon-tl--is-reply toots)
+ toots)))
(goto-char (point-min)))
@@ -1480,19 +1425,18 @@ Optionally get it for BUFFER."
(defun mastodon-tl--get-buffer-property (property &optional buffer no-error)
"Get PROPERTY from `mastodon-tl--buffer-spec' in BUFFER or `current-buffer'.
If NO-ERROR is non-nil, do not error when property is empty."
- (with-current-buffer (or buffer (current-buffer))
+ (with-current-buffer (or buffer (current-buffer))
(if no-error
(plist-get mastodon-tl--buffer-spec property)
(or (plist-get mastodon-tl--buffer-spec property)
(error "Mastodon-tl--buffer-spec is not defined for buffer %s"
(or buffer (current-buffer)))))))
-(defun mastodon-tl--set-buffer-spec (buffer endpoint update-function
- &optional link-header update-params
- hide-replies)
+(defun mastodon-tl--set-buffer-spec
+ (buffer endpoint update-fun &optional link-header update-params hide-replies)
"Set `mastodon-tl--buffer-spec' for the current buffer.
BUFFER is buffer name, ENDPOINT is buffer's enpoint,
-UPDATE-FUNCTION is its update function.
+UPDATE-FUN is its update function.
LINK-HEADER is the http Link header if present.
UPDATE-PARAMS is any http parameters needed for the update function.
HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer."
@@ -1501,13 +1445,14 @@ HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer."
mastodon-instance-url)
buffer-name ,buffer
endpoint ,endpoint
- update-function ,update-function
+ update-function ,update-fun
link-header ,link-header
update-params ,update-params
hide-replies ,hide-replies)))
;;; BUFFERS
+
(defun mastodon-tl--endpoint-str-= (str &optional type)
"Return T if STR is equal to the current buffer's endpoint.
TYPE may be :prefix or :suffix, in which case, T if STR is a prefix or suffix."
@@ -1555,12 +1500,8 @@ call this function after it is set or use something else."
;; profiles:
((mastodon-tl--profile-buffer-p)
(cond
- ;; own profile:
- ;; perhaps not needed, and needlessly confusing,
- ;; e.g. for `mastodon-profile--account-view-cycle':
- ;; ((equal (mastodon-tl--buffer-name)
- ;; (concat "*mastodon-" (mastodon-auth--get-account-name) "-statuses*"))
- ;; 'own-profile-statuses)
+ ;; an own profile option is needlessly confusing e.g. for
+ ;; `mastodon-profile--account-view-cycle'
;; profile note:
((string-suffix-p "update-profile*" buffer-name)
'update-profile-note)
@@ -1619,8 +1560,8 @@ This includes the update profile note buffer, but not the preferences one."
(defun mastodon-tl--timeline-proper-p ()
"Return non-nil if the current buffer is a 'proper' timeline.
-A proper timeline excludes notifications, threads, and other toot
-buffers that aren't strictly mastodon timelines."
+A proper timeline excludes notifications, threads, profiles, and
+other toot buffers that aren't strictly mastodon timelines."
(let ((timeline-buffers
'(home federated local tag-timeline list-timeline profile-statuses)))
(member (mastodon-tl--get-buffer-type) timeline-buffers)))
@@ -1708,9 +1649,8 @@ BACKWARD means move backward (up) the timeline."
(cond ((numberp numeric)
(number-to-string numeric))
((stringp numeric) numeric)
- (t (error
- "Numeric:%s must be either a string or a number"
- numeric))))
+ (t (error "Numeric:%s must be either a string or a number"
+ numeric))))
(defun mastodon-tl--toot-id (json)
"Find approproiate toot id in JSON.
@@ -1718,9 +1658,8 @@ If the toot has been boosted use the id found in the
reblog portion of the toot. Otherwise, use the body of
the toot. This is the same behaviour as the mastodon.social
webapp"
- (let ((id (alist-get 'id json))
- (reblog (alist-get 'reblog json)))
- (if reblog (alist-get 'id reblog) id)))
+ (let-alist json
+ (if .reblog .reblog.id .id)))
(defun mastodon-tl--toot-or-base (json)
"Return the base toot or just the toot from toot JSON."
@@ -1765,12 +1704,9 @@ view all branches of a thread."
(let* ((endpoint (format "statuses/%s/context" id))
(url (mastodon-http--api endpoint))
(buffer (format "*mastodon-thread-%s*" id))
- (toot
- ;; refetch current toot in case we just faved/boosted:
- (mastodon-http--get-json
- (mastodon-http--api (concat "statuses/" id))
- nil
- :silent))
+ (toot (mastodon-http--get-json ; refetch in case we just faved/boosted:
+ (mastodon-http--api (concat "statuses/" id))
+ nil :silent))
(context (mastodon-http--get-json url nil :silent)))
(if (equal (caar toot) 'error)
(message "Error: %s" (cdar toot))
@@ -1782,8 +1718,7 @@ view all branches of a thread."
;; if we have a thread:
(with-mastodon-buffer buffer #'mastodon-mode nil
(let ((marker (make-marker)))
- (mastodon-tl--set-buffer-spec buffer
- endpoint
+ (mastodon-tl--set-buffer-spec buffer endpoint
#'mastodon-tl--thread)
(mastodon-tl--timeline (alist-get 'ancestors context) :thread)
(goto-char (point-max))
@@ -1882,8 +1817,7 @@ If NOTIFY is \"false\", disable notifications when that user posts.
Can be called to toggle NOTIFY on users already being followed.
LANGS is an array parameters alist of languages to filer user's posts by."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "follow")))
+ (list (mastodon-tl--interactive-user-handles-get "follow")))
(mastodon-tl--do-if-toot
(mastodon-tl--do-user-action-and-response
user-handle "follow" nil notify langs)))
@@ -1891,16 +1825,14 @@ LANGS is an array parameters alist of languages to filer user's posts by."
(defun mastodon-tl--enable-notify-user-posts (user-handle)
"Query for USER-HANDLE and enable notifications when they post."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "enable")))
+ (list (mastodon-tl--interactive-user-handles-get "enable")))
(mastodon-tl--do-if-toot
(mastodon-tl--follow-user user-handle "true")))
(defun mastodon-tl--disable-notify-user-posts (user-handle)
"Query for USER-HANDLE and disable notifications when they post."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "disable")))
+ (list (mastodon-tl--interactive-user-handles-get "disable")))
(mastodon-tl--follow-user user-handle "false"))
(defun mastodon-tl--filter-user-user-posts-by-language (user-handle)
@@ -1923,8 +1855,7 @@ LANGS is the accumulated array param alist if we re-run recursively."
(when choice
(setq langs-alist
(push `("languages[]" . ,(alist-get choice mastodon-iso-639-1
- nil nil
- #'string=))
+ nil nil #'string=))
langs-alist))
(if (y-or-n-p "Filter by another language? ")
(mastodon-tl--read-filter-langs langs-alist)
@@ -1933,24 +1864,21 @@ LANGS is the accumulated array param alist if we re-run recursively."
(defun mastodon-tl--unfollow-user (user-handle)
"Query for USER-HANDLE from current status and unfollow that user."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "unfollow")))
+ (list (mastodon-tl--interactive-user-handles-get "unfollow")))
(mastodon-tl--do-if-toot
(mastodon-tl--do-user-action-and-response user-handle "unfollow" t)))
(defun mastodon-tl--block-user (user-handle)
"Query for USER-HANDLE from current status and block that user."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "block")))
+ (list (mastodon-tl--interactive-user-handles-get "block")))
(mastodon-tl--do-if-toot
(mastodon-tl--do-user-action-and-response user-handle "block")))
(defun mastodon-tl--unblock-user (user-handle)
"Query for USER-HANDLE from list of blocked users and unblock that user."
(interactive
- (list
- (mastodon-tl--interactive-blocks-or-mutes-list-get "unblock")))
+ (list (mastodon-tl--get-blocks-or-mutes-list "unblock")))
(if (not user-handle)
(message "Looks like you have no blocks to unblock!")
(mastodon-tl--do-user-action-and-response user-handle "unblock" t)))
@@ -1958,16 +1886,14 @@ LANGS is the accumulated array param alist if we re-run recursively."
(defun mastodon-tl--mute-user (user-handle)
"Query for USER-HANDLE from current status and mute that user."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "mute")))
+ (list (mastodon-tl--interactive-user-handles-get "mute")))
(mastodon-tl--do-if-toot
(mastodon-tl--do-user-action-and-response user-handle "mute")))
(defun mastodon-tl--unmute-user (user-handle)
"Query for USER-HANDLE from list of muted users and unmute that user."
(interactive
- (list
- (mastodon-tl--interactive-blocks-or-mutes-list-get "unmute")))
+ (list (mastodon-tl--get-blocks-or-mutes-list "unmute")))
(if (not user-handle)
(message "Looks like you have no mutes to unmute!")
(mastodon-tl--do-user-action-and-response user-handle "unmute" t)))
@@ -1975,8 +1901,7 @@ LANGS is the accumulated array param alist if we re-run recursively."
(defun mastodon-tl--dm-user (user-handle)
"Query for USER-HANDLE from current status and compose a message to that user."
(interactive
- (list
- (mastodon-tl--interactive-user-handles-get "message")))
+ (list (mastodon-tl--interactive-user-handles-get "message")))
(mastodon-tl--do-if-toot
(mastodon-toot--compose-buffer (concat "@" user-handle))
(setq mastodon-toot--visibility "direct")
@@ -1990,11 +1915,10 @@ LANGS is the accumulated array param alist if we re-run recursively."
;; follow suggests / search / foll requests compat:
(mastodon-tl--buffer-type-eq 'search)
(mastodon-tl--buffer-type-eq 'follow-requests)
- ;; profile view follows/followers compat:
- ;; but not for profile statuses:
- ;; fetch 'toot-json:
+ ;; profile follows/followers but not statuses:
(mastodon-tl--buffer-type-eq 'profile-followers)
(mastodon-tl--buffer-type-eq 'profile-following))
+ ;; fetch 'toot-json:
(list (alist-get 'acct
(mastodon-tl--property 'toot-json :no-move))))
;; profile view, no toots
@@ -2016,7 +1940,7 @@ LANGS is the accumulated array param alist if we re-run recursively."
nil ; predicate
'confirm)))))
-(defun mastodon-tl--interactive-blocks-or-mutes-list-get (action)
+(defun mastodon-tl--get-blocks-or-mutes-list (action)
"Fetch the list of accounts for ACTION from the server.
Action must be either \"unblock\" or \"unmute\"."
(let* ((endpoint (cond ((equal action "unblock")
@@ -2028,9 +1952,7 @@ Action must be either \"unblock\" or \"unmute\"."
(accts (mastodon-tl--map-alist 'acct json)))
(when accts
(completing-read (format "Handle of user to %s: " action)
- accts
- nil ; predicate
- t))))
+ accts nil t)))) ; require match
(defun mastodon-tl--do-user-action-and-response
(user-handle action &optional negp notify langs)
@@ -2041,23 +1963,20 @@ If NOTIFY is \"false\", disable notifications when that user posts.
NOTIFY is only non-nil when called by `mastodon-tl--follow-user'.
LANGS is an array parameters alist of languages to filer user's posts by."
(let* ((account (if negp
- ;; if unmuting/unblocking, we got handle from mute/block list
- (mastodon-profile--search-account-by-handle
- user-handle)
- ;; if profile view, use 'profile-json as status:
+ ;; unmuting/unblocking, handle from mute/block list
+ (mastodon-profile--search-account-by-handle user-handle)
+ ;; profile view, use 'profile-json as status:
(if (mastodon-tl--profile-buffer-p)
(mastodon-profile--lookup-account-in-status
user-handle (mastodon-profile--profile-json))
- ;; if muting/blocking, we select from handles in current status
+ ;; muting/blocking, select from handles in current status
(mastodon-profile--lookup-account-in-status
user-handle (mastodon-profile--toot-json)))))
- (user-id (mastodon-profile--account-field account 'id))
- (name (if (not (string-empty-p
- (mastodon-profile--account-field account 'display_name)))
- (mastodon-profile--account-field account 'display_name)
- (mastodon-profile--account-field account 'username)))
- (args (cond (notify
- `(("notify" . ,notify)))
+ (user-id (alist-get 'id account))
+ (name (if (not (string-empty-p (alist-get 'display_name account)))
+ (alist-get 'display_name account)
+ (alist-get 'username account)))
+ (args (cond (notify `(("notify" . ,notify)))
(langs langs)
(t nil)))
(url (mastodon-http--api (format "accounts/%s/%s" user-id action))))
@@ -2119,8 +2038,7 @@ If TAG is provided, unfollow it."
(let* ((followed-tags-json (unless tag (mastodon-tl--followed-tags)))
(tags (unless tag
(mastodon-tl--map-alist 'name followed-tags-json)))
- (tag (or tag (completing-read "Unfollow tag: "
- tags)))
+ (tag (or tag (completing-read "Unfollow tag: " tags)))
(url (mastodon-http--api (format "tags/%s/unfollow" tag)))
(response (mastodon-http--post url)))
(mastodon-http--triage response
@@ -2149,7 +2067,7 @@ PREFIX is sent to `mastodon-tl--show-tag-timeline', which see."
(defun mastodon-tl--some-followed-tags-timeline (&optional prefix)
"Prompt for some tags, and open a timeline for them.
The suggestions are from followed tags, but any other tags are also allowed.
-PREFIX us sent to `mastodon-tl--show-tag-timeline', which see."
+PREFIX is for `mastodon-tl--show-tag-timeline', which see."
(interactive "p")
(let* ((followed-tags-json (mastodon-tl--followed-tags))
(tags (mastodon-tl--map-alist 'name followed-tags-json))
@@ -2169,7 +2087,7 @@ PREFIX us sent to `mastodon-tl--show-tag-timeline', which see."
(defun mastodon-tl--report-params (account toot)
"Query user and return report params alist.
ACCOUNT and TOOT are the data to use."
- (let* ((account-id (mastodon-profile--account-field account 'id))
+ (let* ((account-id (alist-get 'id account))
(comment (read-string "Add comment [optional]: "))
(toot-id (when (y-or-n-p "Also report status at point? ")
(mastodon-tl--toot-id toot))) ; base toot if poss
@@ -2219,7 +2137,6 @@ report the account for spam."
(handle (alist-get 'acct account))
(params (mastodon-tl--report-params account toot))
(response (mastodon-http--post url params)))
- ;; (setq masto-report-response response)
(mastodon-http--triage response
(lambda ()
(message "User %s reported!" handle)))))))
@@ -2227,7 +2144,7 @@ report the account for spam."
(defvar crm-separator)
(defun mastodon-tl--map-rules-alist (rules)
- "Return an alist of the text and id fields of RULES."
+ "Convert RULES text and id fields into an alist."
(mapcar (lambda (x)
(let-alist x
(cons .text .id)))
@@ -2254,7 +2171,8 @@ report the account for spam."
(url (mastodon-http--api endpoint)))
(mastodon-http--get-json url args)))
-(defun mastodon-tl--more-json-async (endpoint id &optional params callback &rest cbargs)
+(defun mastodon-tl--more-json-async
+ (endpoint id &optional params callback &rest cbargs)
"Return JSON for timeline ENDPOINT before ID.
Then run CALLBACK with arguments CBARGS.
PARAMS is used to send any parameters needed to correctly update
@@ -2301,10 +2219,9 @@ POS is a number, where point will be placed."
endpoint)
(mastodon-tl--thread
(match-string 2 endpoint))))))
- ;; TODO: sends point to POS, which was where point was in buffer before
- ;; reload. This is very rough; we may have removed an item (deleted a
- ;; toot, cleared a notif), so the buffer will be smaller, point will end
- ;; up past where we were, etc.
+ ;; TODO: sends point to where point was in buffer. This is very rough; we
+ ;; may have removed an item , so the buffer will be smaller, point will
+ ;; end up past where we were, etc.
(when pos
(goto-char pos)
(mastodon-tl--goto-prev-item))))
@@ -2380,7 +2297,8 @@ HEADERS is the http headers returned in the response, if any."
link-header))
(message "Loading older toots... done.")))))
-(defun mastodon-tl--find-property-range (property start-point &optional search-backwards)
+(defun mastodon-tl--find-property-range (property start-point
+ &optional search-backwards)
"Return `nil` if no such range is found.
If PROPERTY is set at START-POINT returns a range around
START-POINT otherwise before/after START-POINT.
@@ -2402,14 +2320,13 @@ before (non-nil) or after (nil)"
(and (not (equal start-point (point-min)))
(get-text-property (1- start-point) property)
start-point)))
- (start (and
- end
- (previous-single-property-change end property nil (point-min)))))
+ (start (and end (previous-single-property-change
+ end property nil (point-min)))))
(when end
(cons start end)))
(let* ((start (next-single-property-change start-point property))
- (end (and start
- (next-single-property-change start property nil (point-max)))))
+ (end (and start (next-single-property-change
+ start property nil (point-max)))))
(when start
(cons start end))))))
@@ -2458,7 +2375,8 @@ no-op."
;; We need to re-schedule for an earlier time
(cancel-timer mastodon-tl--timestamp-update-timer)
(setq mastodon-tl--timestamp-update-timer
- (run-at-time (time-to-seconds (time-subtract this-update (current-time)))
+ (run-at-time (time-to-seconds (time-subtract this-update
+ (current-time)))
nil ;; don't repeat
#'mastodon-tl--update-timestamps-callback
(current-buffer) nil)))))))
@@ -2468,7 +2386,7 @@ no-op."
Start searching for more timestamps from PREVIOUS-MARKER or
from the start if it is nil."
;; only do things if the buffer hasn't been killed in the meantime
- (when (and mastodon-tl--enable-relative-timestamps ;; should be true but just in case...
+ (when (and mastodon-tl--enable-relative-timestamps ; just in case
(buffer-live-p buffer))
(save-excursion
(with-current-buffer buffer
@@ -2478,8 +2396,7 @@ from the start if it is nil."
(iteration 0)
next-timestamp-range)
(if previous-marker
- ;; This is a follow-up call to process the next batch of
- ;; timestamps.
+ ;; a follow-up call to process the next batch of timestamps.
;; Release the marker to not slow things down.
(set-marker previous-marker nil)
;; Otherwise this is a rew run, so let's initialize the next-run time.
@@ -2498,8 +2415,9 @@ from the start if it is nil."
(unless (string= current-display new-display)
(let ((inhibit-read-only t))
(add-text-properties
- start end (list 'display
- (mastodon-tl--relative-time-description timestamp)))))
+ start end
+ (list 'display
+ (mastodon-tl--relative-time-description timestamp)))))
(mastodon-tl--consider-timestamp-for-updates timestamp)
(setq iteration (1+ iteration)
previous-timestamp (1+ (cdr next-timestamp-range)))))
@@ -2575,12 +2493,12 @@ HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer."
(let ((url (mastodon-http--api endpoint))
(buffer (concat "*mastodon-" buffer-name "*")))
(if headers
- (mastodon-http--get-response-async url params
- 'mastodon-tl--init* buffer endpoint update-function
- headers params hide-replies)
- (mastodon-http--get-json-async url params
- 'mastodon-tl--init* buffer endpoint update-function nil
- params hide-replies))))
+ (mastodon-http--get-response-async
+ url params 'mastodon-tl--init*
+ buffer endpoint update-function headers params hide-replies)
+ (mastodon-http--get-json-async
+ url params 'mastodon-tl--init*
+ buffer endpoint update-function nil params hide-replies))))
(defun mastodon-tl--init* (response buffer endpoint update-function
&optional headers update-params hide-replies)
@@ -2591,16 +2509,12 @@ RESPONSE is the data returned from the server by
JSON and http headers, without it just the JSON."
(let ((json (if headers (car response) response)))
(if (not json) ; praying this is right here, else try "\n[]"
- (message "Looks like nothing returned from endpoint: %s" endpoint)
+ (message "Looks like nothing returned from endpoint: %s" endpoint)
(let* ((headers (if headers (cdr response) nil))
(link-header (mastodon-tl--get-link-header-from-response headers)))
(with-mastodon-buffer buffer #'mastodon-mode nil
- (mastodon-tl--set-buffer-spec buffer
- endpoint
- update-function
- link-header
- update-params
- hide-replies)
+ (mastodon-tl--set-buffer-spec buffer endpoint update-function
+ link-header update-params hide-replies)
(funcall update-function json)
(setq
;; Initialize with a minimal interval; we re-scan at least once
@@ -2619,7 +2533,8 @@ JSON and http headers, without it just the JSON."
(unless (mastodon-tl--profile-buffer-p)
(mastodon-tl--goto-first-item)))))))
-(defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type)
+(defun mastodon-tl--init-sync (buffer-name endpoint update-function
+ &optional note-type)
"Initialize BUFFER-NAME with timeline targeted by ENDPOINT.
UPDATE-FUNCTION is used to receive more toots.
Runs synchronously.
@@ -2628,8 +2543,6 @@ Optional arg NOTE-TYPE means only get that type of note."
(mastodon-notifications--filter-types-list note-type)))
(args (when note-type (mastodon-http--build-array-params-alist
"exclude_types[]" exclude-types)))
- ;; NB: we now store 'update-params separately in `mastodon-tl--buffer-spec'
- ;; and -http.el handles all conversion of params alists into query strings.
(url (mastodon-http--api endpoint))
(buffer (concat "*mastodon-" buffer-name "*"))
(json (mastodon-http--get-json url args)))
@@ -2651,7 +2564,6 @@ Optional arg NOTE-TYPE means only get that type of note."
(current-buffer)
nil)))
(unless (mastodon-tl--profile-buffer-p)
- ;; FIXME: this breaks test (because test has empty buffer)
(mastodon-tl--goto-first-item)))
buffer))
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 825831d..cbf0447 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -281,13 +281,11 @@ NO-TOOT means we are not calling from a toot buffer."
"Set max_toot_chars returned in JSON-RESPONSE and display in new toot buffer.
NO-TOOT means we are not calling from a toot buffer."
(let ((max-chars
- (or
- (alist-get 'max_toot_chars json-response)
- ;; some servers have this instead:
- (alist-get 'max_characters
- (alist-get 'statuses
- (alist-get 'configuration
- json-response))))))
+ (or (alist-get 'max_toot_chars json-response)
+ (alist-get 'max_characters ; some servers have this instead
+ (alist-get 'statuses
+ (alist-get 'configuration
+ json-response))))))
(setq mastodon-toot--max-toot-chars max-chars)
(unless no-toot
(with-current-buffer "*new toot*"
@@ -327,10 +325,8 @@ Remove MARKER if REMOVE is non-nil, otherwise add it."
Makes a POST request to the server. Used for favouriting,
boosting, or bookmarking toots."
(let* ((id (mastodon-tl--property 'base-toot-id))
- (url (mastodon-http--api (concat "statuses/"
- (mastodon-tl--as-string id)
- "/"
- action))))
+ (url (mastodon-http--api
+ (concat "statuses/" (mastodon-tl--as-string id) "/" action))))
(let ((response (mastodon-http--post url)))
(mastodon-http--triage response callback))))
@@ -339,9 +335,9 @@ boosting, or bookmarking toots."
TYPE is a symbol, either `favourite' or `boost.'"
(mastodon-tl--do-if-toot-strict
(let* ((boost-p (equal type 'boost))
- (has-id (mastodon-tl--property 'base-toot-id))
- (byline-region (when has-id
- (mastodon-tl--find-property-range 'byline (point))))
+ ;; (has-id (mastodon-tl--property 'base-toot-id))
+ (byline-region ;(when has-id
+ (mastodon-tl--find-property-range 'byline (point)))
(id (when byline-region
(mastodon-tl--as-string (mastodon-tl--property 'base-toot-id))))
(boosted (when byline-region
@@ -354,9 +350,9 @@ TYPE is a symbol, either `favourite' or `boost.'"
(msg (if boosted "unboosted" "boosted"))
(action-string (if boost-p "boost" "favourite"))
(remove (if boost-p (when boosted t) (when faved t)))
- (toot-type (alist-get 'type (mastodon-tl--property 'toot-json)))
- (visibility (mastodon-tl--field 'visibility
- (mastodon-tl--property 'toot-json))))
+ (toot-json (mastodon-tl--property 'toot-json))
+ (toot-type (alist-get 'type toot-json))
+ (visibility (mastodon-tl--field 'visibility toot-json)))
(if byline-region
(if (and (or (equal visibility "direct")
(equal visibility "unlisted"))
@@ -387,11 +383,10 @@ TYPE is a symbol, either `favourite' or `boost.'"
(list 'boosted-p (not boosted))
(list 'favourited-p (not faved))))
(mastodon-toot--update-stats-on-action type remove)
- (mastodon-toot--action-success
- (if boost-p
- (mastodon-tl--symbol 'boost)
- (mastodon-tl--symbol 'favourite))
- byline-region remove))
+ (mastodon-toot--action-success (if boost-p
+ (mastodon-tl--symbol 'boost)
+ (mastodon-tl--symbol 'favourite))
+ byline-region remove))
(message (format "%s #%s" (if boost-p msg action) id)))))))
(message (format "Nothing to %s here?!?" action-string))))))
@@ -413,16 +408,15 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement."
(inhibit-read-only 1))
;; TODO another way to implement this would be to async fetch counts again
;; and re-display from count-properties
- (add-text-properties
- (car count-prop-range)
- (cdr count-prop-range)
- (list 'display ; update the display prop:
- (number-to-string
- (mastodon-toot--inc-or-dec count subtract))
- ;; update the count prop
- ;; we rely on this for any subsequent actions:
- count-prop
- (mastodon-toot--inc-or-dec count subtract)))))
+ (add-text-properties (car count-prop-range)
+ (cdr count-prop-range)
+ (list 'display
+ (number-to-string
+ (mastodon-toot--inc-or-dec count subtract))
+ ;; update the count prop
+ ;; we rely on this for any subsequent actions:
+ count-prop
+ (mastodon-toot--inc-or-dec count subtract)))))
(defun mastodon-toot--toggle-boost ()
"Boost/unboost toot at `point'."
@@ -439,16 +433,13 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement."
"Bookmark or unbookmark toot at point."
(interactive)
(mastodon-tl--do-if-toot-strict
- (let* ( ;(toot (mastodon-tl--property 'toot-json))
- (id (mastodon-tl--property 'base-toot-id))
- ;; (mastodon-tl--as-string (mastodon-tl--toot-id toot)))
+ (let* ((id (mastodon-tl--property 'base-toot-id))
(bookmarked-p (mastodon-tl--property 'bookmarked-p))
(prompt (if bookmarked-p
(format "Toot already bookmarked. Remove? ")
(format "Bookmark this toot? ")))
- (byline-region
- (when id
- (mastodon-tl--find-property-range 'byline (point))))
+ (byline-region (when id
+ (mastodon-tl--find-property-range 'byline (point))))
(action (if bookmarked-p "unbookmark" "bookmark"))
(bookmark-str (mastodon-tl--symbol 'bookmark))
(message (if bookmarked-p
@@ -464,9 +455,8 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement."
(add-text-properties (car byline-region)
(cdr byline-region)
(list 'bookmarked-p (not bookmarked-p))))
- (mastodon-toot--action-success
- bookmark-str
- byline-region remove)
+ (mastodon-toot--action-success bookmark-str
+ byline-region remove)
(message (format "%s #%s" message id)))))
(message (format "Nothing to %s here?!?" action))))))
@@ -486,23 +476,20 @@ With FAVOURITE, list favouriters, else list boosters."
(mastodon-tl--do-if-toot-strict
(let* ((base-toot (mastodon-tl--property 'base-toot-id))
(endpoint (if favourite "favourited_by" "reblogged_by"))
- (url (mastodon-http--api
- (format "statuses/%s/%s" base-toot endpoint)))
+ (url (mastodon-http--api (format "statuses/%s/%s" base-toot endpoint)))
(params '(("limit" . "80")))
(json (mastodon-http--get-json url params)))
(if (eq (caar json) 'error)
- (error "%s (Status does not exist or is private)"
- (alist-get 'error json))
+ (error "%s (Status does not exist or is private)" (alist-get 'error json))
(let ((handles (mastodon-tl--map-alist 'acct json))
(type-string (if favourite "Favouriters" "Boosters")))
(if (not handles)
(error "Looks like this toot has no %s" type-string)
- (let ((choice
- (completing-read
- (format "%s (enter to view profile): " type-string)
- handles
- nil
- t)))
+ (let ((choice (completing-read
+ (format "%s (enter to view profile): " type-string)
+ handles
+ nil
+ t)))
(mastodon-profile--show-user choice))))))))
(defun mastodon-toot--copy-toot-url ()
@@ -528,7 +515,6 @@ base toot."
(kill-new (mastodon-tl--content toot))
(message "Toot content copied to the clipboard.")))
-;; (when (require 'lingva nil :no-error)
(defun mastodon-toot--translate-toot-text ()
"Translate text of toot at point.
Uses `lingva.el'."
@@ -536,13 +522,12 @@ Uses `lingva.el'."
(if (not (require 'lingva nil :no-error))
(message "Looks like you need to install lingva.el first.")
(if mastodon-tl--buffer-spec
- (let ((toot (mastodon-tl--property 'toot-json)))
- (if toot
- (lingva-translate nil
- (mastodon-tl--content toot)
- (when mastodon-tl--enable-proportional-fonts
- t))
- (message "No toot to translate?")))
+ (if-let ((toot (mastodon-tl--property 'toot-json)))
+ (lingva-translate nil
+ (mastodon-tl--content toot)
+ (when mastodon-tl--enable-proportional-fonts
+ t))
+ (message "No toot to translate?"))
(message "No mastodon buffer?"))))
(defun mastodon-toot--own-toot-p (toot)
@@ -629,9 +614,8 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved."
;; TODO set new lang/scheduled props here
nil))))
-(defun mastodon-toot--set-toot-properties (reply-id visibility cw lang
- &optional scheduled
- scheduled-id)
+(defun mastodon-toot--set-toot-properties
+ (reply-id visibility cw lang &optional scheduled scheduled-id)
"Set the toot properties for the current redrafted or edited toot.
REPLY-ID, VISIBILITY, CW, SCHEDULED, and LANG are the properties to set."
(when reply-id
@@ -691,18 +675,20 @@ TEXT-ONLY means don't check for attachments or polls."
'emojify-insert-emoji
"Prompt to insert an emoji.")
+
+(defun mastodon-toot--emoji-dir ()
+ "Return the file path for the mastodon custom emojis directory."
+ (concat (expand-file-name emojify-emojis-dir)
+ "/mastodon-custom-emojis/"))
+
(defun mastodon-toot--download-custom-emoji ()
"Download `mastodon-instance-url's custom emoji.
Emoji images are stored in a subdir of `emojify-emojis-dir'.
To use the downloaded emoji, run `mastodon-toot--enable-custom-emoji'."
(interactive)
- (let ((custom-emoji (mastodon-http--get-json
- (mastodon-http--api "custom_emojis")))
- (mastodon-custom-emoji-dir (file-name-as-directory
- (concat (file-name-as-directory
- (expand-file-name
- emojify-emojis-dir))
- "mastodon-custom-emojis"))))
+ (let* ((url (mastodon-http--api "custom_emojis"))
+ (custom-emoji (mastodon-http--get-json url))
+ (mastodon-custom-emoji-dir (mastodon-toot--emoji-dir)))
(if (not (file-directory-p emojify-emojis-dir))
(message "Looks like you need to set up emojify first.")
(unless (file-directory-p mastodon-custom-emoji-dir)
@@ -715,11 +701,10 @@ To use the downloaded emoji, run `mastodon-toot--enable-custom-emoji'."
(string-match-p "^[a-zA-Z0-9-_]+$" shortcode)
(string-match-p "^[a-zA-Z]+$" (file-name-extension url)))
(url-copy-file url
- (concat
- mastodon-custom-emoji-dir
- shortcode
- "."
- (file-name-extension url))
+ (concat mastodon-custom-emoji-dir
+ shortcode
+ "."
+ (file-name-extension url))
t))))
custom-emoji)
(message "Custom emoji for %s downloaded to %s"
@@ -729,13 +714,11 @@ To use the downloaded emoji, run `mastodon-toot--enable-custom-emoji'."
(defun mastodon-toot--collect-custom-emoji ()
"Return a list of `mastodon-instance-url's custom emoji.
The list is formatted for `emojify-user-emojis', which see."
- (let* ((mastodon-custom-emojis-dir (concat (expand-file-name
- emojify-emojis-dir)
- "/mastodon-custom-emojis/"))
+ (let* ((mastodon-custom-emojis-dir (mastodon-toot--emoji-dir))
(custom-emoji-files (directory-files mastodon-custom-emojis-dir
nil ; not full path
"^[^.]")) ; no dot files
- (mastodon-emojify-user-emojis))
+ mastodon-emojify-user-emojis)
(mapc (lambda (x)
(push
`(,(concat ":"
@@ -753,9 +736,7 @@ Custom emoji must first be downloaded with
`mastodon-toot--download-custom-emoji'. Custom emoji are appended
to `emojify-user-emojis', and the emoji data is updated."
(interactive)
- (unless (file-exists-p (concat (expand-file-name
- emojify-emojis-dir)
- "/mastodon-custom-emojis/"))
+ (unless (file-exists-p (mastodon-toot--emoji-dir))
(when (y-or-n-p "Looks like you haven't downloaded your
instance's custom emoji yet. Download now? ")
(mastodon-toot--download-custom-emoji)))
@@ -800,12 +781,9 @@ instance to edit a toot."
(scheduled mastodon-toot--scheduled-for)
(scheduled-id mastodon-toot--scheduled-id)
(edit-id mastodon-toot--edit-toot-id)
- (endpoint
- (if edit-id
- ;; we are sending an edit:
- (mastodon-http--api (format "statuses/%s"
- edit-id))
- (mastodon-http--api "statuses")))
+ (endpoint (if edit-id ; we are sending an edit:
+ (mastodon-http--api (format "statuses/%s" edit-id))
+ (mastodon-http--api "statuses")))
(cw (mastodon-toot--read-cw-string))
(args-no-media (append `(("status" . ,toot)
("in_reply_to_id" . ,mastodon-toot--reply-to-id)
@@ -843,8 +821,7 @@ instance to edit a toot."
((mastodon-toot--empty-p)
(message "Empty toot. Cowardly refusing to post this."))
(t
- (let ((response (if edit-id
- ;; we are sending an edit:
+ (let ((response (if edit-id ; we are sending an edit:
(mastodon-http--put endpoint args)
(mastodon-http--post endpoint args))))
(mastodon-http--triage
@@ -868,7 +845,7 @@ instance to edit a toot."
(defun mastodon-toot--edit-toot-at-point ()
"Edit the user's toot at point."
(interactive)
- (let ((toot (or (mastodon-tl--property 'base-toot); fave/boost notifs
+ (let ((toot (or (mastodon-tl--property 'base-toot) ; fave/boost notifs
(mastodon-tl--property 'toot-json))))
(if (not (mastodon-toot--own-toot-p toot))
(message "You can only edit your own toots.")
@@ -882,7 +859,6 @@ instance to edit a toot."
(when (y-or-n-p "Edit this toot? ")
(mastodon-toot--compose-buffer nil reply-id nil content :edit)
(goto-char (point-max))
- ;; (insert content)
;; adopt reply-to-id, visibility, CW, and language:
(mastodon-toot--set-toot-properties reply-id toot-visibility
source-cw toot-language)
@@ -943,7 +919,7 @@ Buffer-local variable `mastodon-toot-previous-window-config' holds the config."
"Apply `mastodon-toot--process-local' function to each mention in MENTIONS.
Remove empty string (self) from result and joins the sequence with whitespace."
(mapconcat (lambda (mention) mention)
- (remove "" (mapcar #'mastodon-toot--process-local mentions))
+ (remove "" (mapcar #'mastodon-toot--process-local mentions))
" "))
(defun mastodon-toot--process-local (acct)
@@ -964,24 +940,22 @@ The mentioned users look like this:
Local user (including the logged in): `username`.
Federated user: `username@host.co`."
(let* ((boosted (mastodon-tl--field 'reblog status))
- (mentions
- (if boosted
- (alist-get 'mentions (alist-get 'reblog status))
- (alist-get 'mentions status))))
+ (mentions (if boosted
+ (alist-get 'mentions (alist-get 'reblog status))
+ (alist-get 'mentions status))))
;; reverse does not work on vectors in 24.5
(mastodon-tl--map-alist 'acct (reverse mentions))))
(defun mastodon-toot--get-bounds (regex)
"Get bounds of tag or handle before point using REGEX."
- ;; needed because # and @ are not part of any existing thing at point
+ ;; # and @ are not part of any existing thing at point
(save-match-data
(save-excursion
;; match full handle inc. domain, or tag including #
;; (see the regexes for subexp 2)
(when (re-search-backward regex
- (save-excursion
- (forward-whitespace -1)
- (point))
+ (save-excursion (forward-whitespace -1)
+ (point))
:no-error)
(cons (match-beginning 2)
(match-end 2))))))
@@ -1004,51 +978,43 @@ If TAGS, we search for tags, else we search for handles."
(defun mastodon-toot--mentions-capf ()
"Build a mentions completion backend for `completion-at-point-functions'."
- (let* ((bounds
- (mastodon-toot--get-bounds mastodon-toot-handle-regex))
+ (let* ((bounds (mastodon-toot--get-bounds mastodon-toot-handle-regex))
(start (car bounds))
(end (cdr bounds)))
(when bounds
(list start
end
- ;; only search when necessary:
- (completion-table-dynamic
+ (completion-table-dynamic ; only search when necessary
(lambda (_)
- ;; Interruptible candidate computation
- ;; suggestion from minad (d mendler), thanks!
+ ;; Interruptible candidate computation, from minad/d mendler, thanks!
(let ((result
(while-no-input
(mastodon-toot--fetch-completion-candidates start end))))
(and (consp result) result))))
:exclusive 'no
:annotation-function
- (lambda (candidate)
- (concat " "
- (mastodon-toot--mentions-annotation-fun candidate)))))))
+ (lambda (cand)
+ (concat " " (mastodon-toot--mentions-annotation-fun cand)))))))
(defun mastodon-toot--tags-capf ()
"Build a tags completion backend for `completion-at-point-functions'."
- (let* ((bounds
- (mastodon-toot--get-bounds mastodon-toot-tag-regex))
+ (let* ((bounds (mastodon-toot--get-bounds mastodon-toot-tag-regex))
(start (car bounds))
(end (cdr bounds)))
(when bounds
(list start
end
- ;; only search when necessary:
- (completion-table-dynamic
+ (completion-table-dynamic ; only search when necessary:
(lambda (_)
- ;; Interruptible candidate computation
- ;; suggestion from minad (d mendler), thanks!
+ ;; Interruptible candidate computation, from minad/d mendler, thanks!
(let ((result
(while-no-input
(mastodon-toot--fetch-completion-candidates start end :tags))))
(and (consp result) result))))
:exclusive 'no
:annotation-function
- (lambda (candidate)
- (concat " "
- (mastodon-toot--tags-annotation-fun candidate)))))))
+ (lambda (cand)
+ (concat " " (mastodon-toot--tags-annotation-fun cand)))))))
(defun mastodon-toot--mentions-annotation-fun (candidate)
"Given a handle completion CANDIDATE, return its annotation string, a username."
@@ -1056,8 +1022,8 @@ If TAGS, we search for tags, else we search for handles."
(defun mastodon-toot--tags-annotation-fun (candidate)
"Given a tag string CANDIDATE, return an annotation, the tag's URL."
- ;; FIXME check the list returned here? should be cadr
- ;;or make it an alist and use cdr
+ ;; TODO: check the list returned here? should be cadr
+ ;; or make it an alist and use cdr
(cadr (assoc candidate mastodon-toot-completions)))
(defun mastodon-toot--reply ()
@@ -1067,8 +1033,7 @@ text of the toot being replied to in the compose buffer."
(interactive)
(mastodon-tl--do-if-toot-strict
(let* ((toot (mastodon-tl--property 'toot-json))
- ;; no-move arg for base toot, because if it doesn't have one, it is
- ;; fetched from next toot!
+ ;; no-move arg for base toot: don't try next toot
(base-toot (mastodon-tl--property 'base-toot :no-move)) ; for new notifs handling
(id (mastodon-tl--as-string (mastodon-tl--field 'id (or base-toot toot))))
(account (mastodon-tl--field 'account toot))
@@ -1084,17 +1049,17 @@ text of the toot being replied to in the compose buffer."
(if (and (not (equal user booster))
(not (member booster mentions)))
;; different booster, user and mentions:
- (mastodon-toot--mentions-to-string (append (list user booster) mentions nil))
+ (mastodon-toot--mentions-to-string (append (list user booster) mentions nil))
;; booster is either user or in mentions:
(if (not (member user mentions))
;; user not already in mentions:
- (mastodon-toot--mentions-to-string (append (list user) mentions nil))
+ (mastodon-toot--mentions-to-string (append (list user) mentions nil))
;; user already in mentions:
(mastodon-toot--mentions-to-string (copy-sequence mentions))))
;; ELSE no booster:
(if (not (member user mentions))
;; user not in mentions:
- (mastodon-toot--mentions-to-string (append (list user) mentions nil))
+ (mastodon-toot--mentions-to-string (append (list user) mentions nil))
;; user in mentions already:
(mastodon-toot--mentions-to-string (copy-sequence mentions)))))
id
@@ -1163,8 +1128,7 @@ File is actually attached to the toot upon posting."
"Upload a single ATTACHMENT using `mastodon-http--post-media-attachment'.
The item's id is added to `mastodon-toot--media-attachment-ids',
which is used to attach it to a toot when posting."
- (let* ((filename (expand-file-name
- (alist-get :filename attachment)))
+ (let* ((filename (expand-file-name (alist-get :filename attachment)))
(caption (alist-get :description attachment))
(url (concat mastodon-instance-url "/api/v2/media")))
(message "Uploading %s..." (file-name-nondirectory filename))
@@ -1203,7 +1167,7 @@ which is used to attach it to a toot when posting."
(list "None")))
(defun mastodon-toot--fetch-max-poll-options (instance)
- "Return the maximum number of poll options from INSTANCE, which is json."
+ "Return the maximum number of poll options from JSON data INSTANCE."
(mastodon-toot--fetch-poll-field 'max_options instance))
(defun mastodon-toot--fetch-max-poll-option-chars (instance)
@@ -1215,7 +1179,7 @@ INSTANCE is JSON."
50))) ; masto default
(defun mastodon-toot--fetch-poll-field (field instance)
- "Return FIELD from the poll settings from INSTANCE, which is json."
+ "Return FIELD from the poll settings from JSON data INSTANCE."
(let* ((polls (if (alist-get 'pleroma instance)
(alist-get 'poll_limits instance)
(alist-get 'polls
@@ -1225,8 +1189,7 @@ INSTANCE is JSON."
(defun mastodon-toot--read-poll-options-count (max)
"Read the user's choice of the number of options the poll should have.
MAX is the maximum number set by their instance."
- (let ((number (read-number
- (format "Number of options [2-%s]: " max) 2)))
+ (let ((number (read-number (format "Number of options [2-%s]: " max) 2)))
(if (> number max)
(error "You need to choose a number between 2 and %s" max)
number)))
@@ -1234,7 +1197,6 @@ MAX is the maximum number set by their instance."
(defun mastodon-toot--create-poll ()
"Prompt for new poll options and return as a list."
(interactive)
- ;; re length, API docs show a poll 9 options.
(let* ((instance (mastodon-http--get-json (mastodon-http--api "instance")))
(max-options (mastodon-toot--fetch-max-poll-options instance))
(count (mastodon-toot--read-poll-options-count max-options))
@@ -1251,11 +1213,10 @@ MAX is the maximum number set by their instance."
(defun mastodon-toot--read-poll-options (count length)
"Read a list of options for poll with COUNT options.
LENGTH is the maximum character length allowed for a poll option."
- (let* ((choices
- (cl-loop for x from 1 to count
- collect (read-string
- (format "Poll option [%s/%s] [max %s chars]: "
- x count length))))
+ (let* ((choices (cl-loop for x from 1 to count
+ collect (read-string
+ (format "Poll option [%s/%s] [max %s chars]: "
+ x count length))))
(longest (cl-reduce #'max (mapcar #'length choices))))
(if (> longest length)
(progn
@@ -1276,7 +1237,7 @@ LENGTH is the maximum character length allowed for a poll option."
response))))
(defun mastodon-toot--poll-expiry-options-alist ()
- "Return an alist of seconds options."
+ "Return an alist of expiry options options in seconds."
`(("5 minutes" . ,(number-to-string (* 60 5)))
("30 minutes" . ,(number-to-string (* 60 30)))
("1 hour" . ,(number-to-string (* 60 60)))
@@ -1308,29 +1269,27 @@ With RESCHEDULE, reschedule the scheduled toot at point without editing."
(message "You can't schedule toots you're editing."))
((not (or (mastodon-tl--buffer-type-eq 'new-toot)
(mastodon-tl--buffer-type-eq 'scheduled-statuses)))
- (message "You can only schedule toots from the compose toot buffer or the scheduled toots view."))
+ (message "You can only schedule toots from the compose buffer or scheduled toots view."))
(t
(let* ((id (when reschedule (mastodon-tl--property 'id :no-move)))
(ts (when reschedule
(alist-get 'scheduled_at
(mastodon-tl--property 'scheduled-json :no-move))))
- (time-value
- (org-read-date t t nil "Schedule toot:"
- ;; default to scheduled timestamp if already set:
- (mastodon-toot--iso-to-org
- ;; we are rescheduling without editing:
- (or ts
- ;; we are maybe editing the scheduled toot:
- mastodon-toot--scheduled-for))))
+ (time-value (org-read-date t t nil "Schedule toot:"
+ ;; default to scheduled timestamp if already set:
+ (mastodon-toot--iso-to-org
+ ;; we are rescheduling without editing:
+ (or ts
+ ;; we are maybe editing the scheduled toot:
+ mastodon-toot--scheduled-for))))
(iso8601-str (format-time-string "%FT%T%z" time-value))
(msg-str (format-time-string "%d-%m-%y at %H:%M[%z]" time-value)))
(if (not reschedule)
(progn
(setq-local mastodon-toot--scheduled-for iso8601-str)
(message (format "Toot scheduled for %s." msg-str)))
- (let* ((args (when reschedule `(("scheduled_at" . ,iso8601-str))))
- (url (when reschedule (mastodon-http--api
- (format "scheduled_statuses/%s" id))))
+ (let* ((args `(("scheduled_at" . ,iso8601-str)))
+ (url (mastodon-http--api (format "scheduled_statuses/%s" id)))
(response (mastodon-http--put url args)))
(mastodon-http--triage response
(lambda ()
@@ -1350,13 +1309,12 @@ With RESCHEDULE, reschedule the scheduled toot at point without editing."
(when ts (let* ((decoded (iso8601-parse ts)))
(encode-time decoded))))
-;; we'll need to revisit this if the binds get
-;; more diverse than two-chord bindings
(defun mastodon-toot--get-mode-kbinds ()
"Get a list of the keybindings in the mastodon-toot-mode."
(let* ((binds (copy-tree mastodon-toot-mode-map))
(prefix (car (cadr binds)))
- (bindings (remove nil (mapcar (lambda (i) (if (listp i) i))
+ (bindings (remove nil (mapcar (lambda (i)
+ (when (listp i) i))
(cadr binds)))))
(mapcar (lambda (b)
(setf (car b) (vector prefix (car b)))
@@ -1402,17 +1360,14 @@ LONGEST is the length of the longest binding."
(defun mastodon-toot--formatted-kbinds-longest (kbinds-list)
"Return the length of the longest item in KBINDS-LIST."
- (let ((lengths (mapcar (lambda (x)
- (length x))
- kbinds-list)))
+ (let ((lengths (mapcar #'length kbinds-list)))
(car (sort lengths #'>))))
(defun mastodon-toot--make-mode-docs ()
"Create formatted documentation text for the mastodon-toot-mode."
(let* ((kbinds (mastodon-toot--get-mode-kbinds))
- (longest-kbind
- (mastodon-toot--formatted-kbinds-longest
- (mastodon-toot--format-kbinds kbinds))))
+ (longest-kbind (mastodon-toot--formatted-kbinds-longest
+ (mastodon-toot--format-kbinds kbinds))))
(concat
" Compose a new toot here. The following keybindings are available:"
(mapconcat #'identity
@@ -1425,15 +1380,12 @@ LONGEST is the length of the longest binding."
"Format a REPLY-TEXT for display in compose buffer docs."
(let* ((rendered (mastodon-tl--render-text reply-text))
(no-props (substring-no-properties rendered))
- ;; FIXME: this regex replaces \n at end of every post
- ;; so we have to trim:
+ ;; FIXME: this replaces \n at end of every post, so we have to trim:
(no-newlines (string-trim
(replace-regexp-in-string "[\n]+" " " no-props)))
(reply-to (concat " Reply to: \"" no-newlines "\""))
- (crop (truncate-string-to-width
- ;; (string-limit
- reply-to
- mastodon-toot-orig-in-reply-length)))
+ (crop (truncate-string-to-width reply-to
+ mastodon-toot-orig-in-reply-length)))
(if (> (length no-newlines)
(length crop)) ; we cropped:
(concat crop "\n")
@@ -1491,17 +1443,16 @@ REPLY-TEXT is the text of the toot being replied to."
The default is given by `mastodon-toot--default-reply-visibility'."
(unless (null reply-visibility)
(let ((less-restrictive (member (intern mastodon-toot--default-reply-visibility)
- mastodon-toot-visibility-list)))
+ mastodon-toot-visibility-list)))
(if (member (intern reply-visibility) less-restrictive)
- mastodon-toot--default-reply-visibility reply-visibility))))
+ mastodon-toot--default-reply-visibility reply-visibility))))
(defun mastodon-toot--setup-as-reply (reply-to-user reply-to-id reply-json)
"If REPLY-TO-USER is provided, inject their handle into the message.
If REPLY-TO-ID is provided, set `mastodon-toot--reply-to-id'.
REPLY-JSON is the full JSON of the toot being replied to."
- (let ((reply-visibility
- (mastodon-toot--most-restrictive-visibility
- (alist-get 'visibility reply-json)))
+ (let ((reply-visibility (mastodon-toot--most-restrictive-visibility
+ (alist-get 'visibility reply-json)))
(reply-cw (alist-get 'spoiler_text reply-json)))
(when reply-to-user
(when (> (length reply-to-user) 0) ; self is "" unforch
@@ -1581,10 +1532,7 @@ CW is the content warning, which contributes to the character count."
(replace-match "xxxxxxxxxxxxxxxxxxxxxxx")) ; 23 x's
;; handle @handles
(goto-char (point-min))
- (while (search-forward-regexp (concat "\\(?2:@[^ @\n]+\\)" ; a handle only
- "\\(@[^ \n]+\\)?" ; with poss domain
- "\\b")
- nil t)
+ (while (search-forward-regexp mastodon-toot-handle-regex nil t)
(replace-match (match-string 2))) ; replace with handle only
(+ (length cw)
(length (buffer-substring (point-min) (point-max))))))
@@ -1628,8 +1576,7 @@ Added to `after-change-functions' in new toot buffers."
mastodon-toot-draft-toots-list
nil t)))
(setq mastodon-toot-draft-toots-list
- (cl-delete draft mastodon-toot-draft-toots-list
- :test 'equal))
+ (cl-delete draft mastodon-toot-draft-toots-list :test 'equal))
(message "Draft deleted!"))
(message "No drafts to delete.")))
@@ -1643,9 +1590,8 @@ Added to `after-change-functions' in new toot buffers."
"Propertize tags and handles in toot compose buffer.
Added to `after-change-functions'."
(when (mastodon-toot--compose-buffer-p)
- (let ((header-region
- (mastodon-tl--find-property-range 'toot-post-header
- (point-min)))
+ (let ((header-region (mastodon-tl--find-property-range 'toot-post-header
+ (point-min)))
(face (when mastodon-toot--proportional-fonts-compose
'variable-pitch)))
;; cull any prev props:
@@ -1681,14 +1627,10 @@ Added to `after-change-functions'."
(save-match-data
(let* ((fill-column 67))
(goto-char (point-min))
- ;; while-let shoulndn't be needed here, as we really should only have
- ;; one. if we have more, the bug is elsewhere.
(when-let ((prop (text-property-search-forward 'toot-reply)))
(fill-region (prop-match-beginning prop)
(point)))))))
-;; NB: now that we have toot drafts, to ensure offline composing remains
-;; possible, avoid any direct requests here:
(defun mastodon-toot--compose-buffer
(&optional reply-to-user reply-to-id reply-json initial-text edit)
"Create a new buffer to capture text for a new toot.
@@ -1732,10 +1674,9 @@ EDIT means we are editing an existing toot, not composing a new one."
(mastodon-toot--get-max-toot-chars))
;; set up completion:
(when mastodon-toot--enable-completion
- (set ; (setq-local
- (make-local-variable 'completion-at-point-functions)
- (add-to-list 'completion-at-point-functions
- #'mastodon-toot--mentions-capf))
+ (set (make-local-variable 'completion-at-point-functions)
+ (add-to-list 'completion-at-point-functions
+ #'mastodon-toot--mentions-capf))
(add-to-list 'completion-at-point-functions
#'mastodon-toot--tags-capf)
;; company
@@ -1747,10 +1688,10 @@ EDIT means we are editing an existing toot, not composing a new one."
(company-mode-on)))
;; after-change:
(make-local-variable 'after-change-functions)
- (cl-pushnew #'mastodon-toot--update-status-fields after-change-functions)
(cl-pushnew #'mastodon-toot--save-toot-text after-change-functions)
- (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions)
+ (cl-pushnew #'mastodon-toot--update-status-fields after-change-functions)
(mastodon-toot--update-status-fields)
+ (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions)
(mastodon-toot--propertize-tags-and-handles)
(mastodon-toot--refresh-attachments-display)
;; draft toot text saving:
@@ -1764,6 +1705,7 @@ EDIT means we are editing an existing toot, not composing a new one."
;; flyspell ignore masto toot regexes:
(defvar flyspell-generic-check-word-predicate)
+
(defun mastodon-toot-mode-flyspell-verify ()
"A predicate function for `flyspell'.
Only text that is not one of these faces will be spell-checked."
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el
index 4f102a6..c86884f 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -168,26 +168,23 @@ provides the JSON data."
(insert (mastodon-tl--set-face
(concat "\n " mastodon-tl--horiz-bar "\n "
(upcase view-name)
- "\n "
- mastodon-tl--horiz-bar "\n\n")
+ "\n " mastodon-tl--horiz-bar "\n\n")
'success)
(if bindings-string
- (mastodon-tl--set-face
- (concat "[" bindings-string "]"
- "\n\n")
- 'font-lock-comment-face)
+ (mastodon-tl--set-face (concat "[" bindings-string "]\n\n")
+ 'font-lock-comment-face)
""))
(if (seq-empty-p data)
(insert (propertize
(format "Looks like you have no %s for now." view-name)
'face font-lock-comment-face
'byline t
- 'toot-id "0")) ; so point can move here when no filters
+ 'toot-id "0")) ; so point can move here when no item
(funcall insert-fun data)
(goto-char (point-min)))
- ;; (when json
+ ;; (when data
;; FIXME: this seems to trigger a new request, but ideally would run.
- ;; (mastodon-tl--goto-next-toot))))
+ ;; (mastodon-tl--goto-next-toot))
)
@@ -196,8 +193,7 @@ provides the JSON data."
(defun mastodon-views--view-lists ()
"Show the user's lists in a new buffer."
(interactive)
- (mastodon-tl--init-sync "lists"
- "lists"
+ (mastodon-tl--init-sync "lists" "lists"
'mastodon-views--insert-lists)
(with-current-buffer "*mastodon-lists*"
(use-local-map mastodon-views--view-lists-keymap)))
@@ -214,8 +210,7 @@ provides the JSON data."
(defun mastodon-views--print-list-set (lists)
"Print each account plus a separator for each list in LISTS."
- (let ((lists-names
- (mastodon-tl--map-alist 'title lists)))
+ (let ((lists-names (mastodon-tl--map-alist 'title lists)))
(mapc (lambda (x)
(mastodon-views--print-list-accounts x)
(insert (propertize (concat " " mastodon-tl--horiz-bar "\n\n")
@@ -237,16 +232,14 @@ a: add account to this list, r: remove account from this list"
'keymap mastodon-views--list-name-keymap
'list-name list-name
'list-id id)
- (propertize
- "\n\n"
- 'list t
- 'keymap mastodon-views--list-name-keymap
- 'list-name list-name
- 'list-id id)
+ (propertize "\n\n"
+ 'list t
+ 'keymap mastodon-views--list-name-keymap
+ 'list-name list-name
+ 'list-id id)
(propertize
(mapconcat #'mastodon-search--propertize-user accounts
" ")
- ;; (mastodon-search--insert-users-propertized accounts)
'list t
'keymap mastodon-views--list-name-keymap
'list-name list-name
@@ -293,13 +286,12 @@ If ID is provided, use that list."
(let* ((list-names (unless id (mastodon-views--get-lists-names)))
(name-old (if id
(mastodon-tl--property 'list-name :no-move)
- (completing-read "Edit list: "
- list-names)))
+ (completing-read "Edit list: " list-names)))
(id (or id (mastodon-views--get-list-id name-old)))
(name-choice (read-string "List name: " name-old))
(replies-policy (completing-read "Replies policy: " ; give this a proper name
'("followed" "list" "none")
- nil t nil nil "list"))
+ nil :match nil nil "list"))
(url (mastodon-http--api (format "lists/%s" id)))
(response (mastodon-http--put url
`(("title" . ,name-choice)
@@ -341,7 +333,7 @@ Prompt for name and replies policy."
(let* ((title (read-string "New list name: "))
(replies-policy (completing-read "Replies policy: " ; give this a proper name
'("followed" "list" "none")
- nil t nil nil "list")) ; default
+ nil :match nil nil "list")) ; default
(response (mastodon-http--post (mastodon-http--api "lists")
`(("title" . ,title)
("replies_policy" . ,replies-policy))
@@ -362,8 +354,7 @@ If ID is provided, delete that list."
(let* ((list-names (unless id (mastodon-views--get-lists-names)))
(name (if id
(mastodon-views--get-list-name id)
- (completing-read "Delete list: "
- list-names)))
+ (completing-read "Delete list: " list-names)))
(id (or id (mastodon-views--get-list-id name)))
(url (mastodon-http--api (format "lists/%s" id))))
(when (y-or-n-p (format "Delete list %s?" name))
@@ -402,11 +393,9 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting."
handles nil t)))
(account-id (or account-id (alist-get account handles nil nil 'equal)))
(url (mastodon-http--api (format "lists/%s/accounts" list-id)))
- (response (mastodon-http--post url
- `(("account_ids[]" . ,account-id)))))
+ (response (mastodon-http--post url `(("account_ids[]" . ,account-id)))))
(mastodon-views--list-action-triage
- response
- (message "%s added to list %s!" account list-name))))
+ response (message "%s added to list %s!" account list-name))))
(defun mastodon-views--add-toot-account-at-point-to-list ()
"Prompt for a list, and add the account of the toot at point to it."
@@ -441,8 +430,7 @@ If ID is provided, use that list."
(args (mastodon-http--build-array-params-alist "account_ids[]" `(,account-id)))
(response (mastodon-http--delete url args)))
(mastodon-views--list-action-triage
- response
- (message "%s removed from list %s!" account list-name))))
+ response (message "%s removed from list %s!" account list-name))))
(defun mastodon-views--list-action-triage (response message)
"Call `mastodon-http--triage' on RESPONSE and display MESSAGE."
@@ -505,20 +493,17 @@ JSON is the data returned by the server."
(defun mastodon-views--insert-scheduled-toot (toot)
"Insert scheduled TOOT into the buffer."
- (let* ((id (alist-get 'id toot))
- (scheduled (alist-get 'scheduled_at toot))
- (params (alist-get 'params toot))
- (text (alist-get 'text params)))
+ (let-alist toot
(insert
- (propertize (concat text
+ (propertize (concat .params.text
" | "
- (mastodon-toot--iso-to-human scheduled))
+ (mastodon-toot--iso-to-human .scheduled_at))
'byline t ; so we nav here
'toot-id "0" ; so we nav here
'face 'font-lock-comment-face
'keymap mastodon-views--scheduled-map
'scheduled-json toot
- 'id id)
+ 'id .id)
"\n")))
(defun mastodon-views--get-scheduled-toots (&optional id)
@@ -593,8 +578,7 @@ NO-CONFIRM means there is no ask or message, there is only do."
(defun mastodon-views--view-filters ()
"View the user's filters in a new buffer."
(interactive)
- (mastodon-tl--init-sync "filters"
- "filters"
+ (mastodon-tl--init-sync "filters" "filters"
'mastodon-views--insert-filters)
(with-current-buffer "*mastodon-filters*"
(use-local-map mastodon-views--view-filters-keymap)))
@@ -611,10 +595,7 @@ JSON is what is returned by by the server."
(defun mastodon-views--insert-filter-string-set (json)
"Insert a filter string plus a blank line.
JSON is the filters data."
- (mapc (lambda (x)
- (mastodon-views--insert-filter-string x)
- (insert "\n\n"))
- json))
+ (mapc #'mastodon-views--insert-filter-string json))
(defun mastodon-views--insert-filter-string (filter)
"Insert a single FILTER."
@@ -627,9 +608,8 @@ JSON is the filters data."
(propertize filter-string
'toot-id id ;for goto-next-filter compat
'phrase phrase
- ;;'help-echo "n/p to go to next/prev filter, c to create new filter, d to delete filter at point."
- ;;'keymap mastodon-views--view-filters-keymap
- 'byline t)))) ;for goto-next-filter compat
+ 'byline t) ;for goto-next-filter compat
+ "\n\n")))
(defun mastodon-views--create-filter ()
"Create a filter for a word.
@@ -646,8 +626,7 @@ Prompt for a context, must be a list containting at least one of \"home\",
(completing-read-multiple
"Contexts to filter [TAB for options]: "
'("home" "notifications" "public" "thread")
- nil ; no predicate
- t))) ; require-match, as context is mandatory
+ nil :match)))
(contexts-processed
(if (equal nil contexts)
(error "You must select at least one context for a filter")
@@ -660,7 +639,6 @@ Prompt for a context, must be a list containting at least one of \"home\",
(mastodon-http--triage response
(lambda ()
(message "Filter created for %s!" word)
- ;; reload if we are in filters view:
(when (mastodon-tl--buffer-type-eq 'filters)
(mastodon-views--view-filters))))))
@@ -669,15 +647,15 @@ Prompt for a context, must be a list containting at least one of \"home\",
(interactive)
(let* ((filter-id (mastodon-tl--property 'toot-id :no-move))
(phrase (mastodon-tl--property 'phrase :no-move))
- (url (mastodon-http--api
- (format "filters/%s" filter-id))))
+ (url (mastodon-http--api (format "filters/%s" filter-id))))
(if (null phrase)
(error "No filter at point?")
(when (y-or-n-p (format "Delete filter %s? " phrase)))
(let ((response (mastodon-http--delete url)))
- (mastodon-http--triage response (lambda ()
- (mastodon-views--view-filters)
- (message "Filter for \"%s\" deleted!" phrase)))))))
+ (mastodon-http--triage
+ response (lambda ()
+ (mastodon-views--view-filters)
+ (message "Filter for \"%s\" deleted!" phrase)))))))
;;; FOLLOW SUGGESTIONS
@@ -760,8 +738,7 @@ INSTANCE is an instance domain name."
(let* ((toot (if (mastodon-tl--profile-buffer-p)
;; we may be on profile description itself:
(or (mastodon-tl--property 'profile-json)
- ;; or on profile account listings, which use toot-json:
- ;; or just toots:
+ ;; or on profile account listings, or just toots:
(mastodon-tl--property 'toot-json))
;; normal timeline/account listing:
(mastodon-tl--property 'toot-json)))
@@ -769,18 +746,16 @@ INSTANCE is an instance domain name."
(account (or (alist-get 'account reblog)
(alist-get 'account toot)
toot)) ; else `toot' is already an account listing.
- ;; we can't use --profile-buffer-p as our test here because we may
- ;; be looking at toots/boosts/users in a profile buffer.
- ;; profile-json works as a defacto test for if point is on the
- ;; profile details at the top of a profile buffer.
- (url (if (and (mastodon-tl--profile-buffer-p)
- ;; only call this in profile buffers:
- (mastodon-tl--property 'profile-json))
+ ;; we may be at toots/boosts/users in a profile buffer.
+ ;; profile-json is a defacto test for if point is on the profile
+ ;; details at the top of a profile buffer.
+ (profile-note-p (and (mastodon-tl--profile-buffer-p)
+ ;; only call this in profile buffers:
+ (mastodon-tl--property 'profile-json)))
+ (url (if profile-note-p
(alist-get 'url toot) ; profile description
(alist-get 'url account)))
- (username (if (and (mastodon-tl--profile-buffer-p)
- ;; only call this in profile buffers:
- (mastodon-tl--property 'profile-json))
+ (username (if profile-note-p
(alist-get 'username toot) ;; profile
(alist-get 'username account)))
(instance (mastodon-views--get-instance-url url username instance))
@@ -823,16 +798,14 @@ INSTANCE is the instance were are working with."
(format (concat "%-"
(number-to-string pad)
"s: ")
- (propertize
- (prin1-to-string (car el))
- 'face '(:underline t))))
+ (propertize (prin1-to-string (car el))
+ 'face '(:underline t))))
(defun mastodon-views--print-json-keys (response &optional ind)
"Print the JSON keys and values in RESPONSE.
IND is the optional indentation level to print at."
- (let* ((cars (mapcar
- (lambda (x) (symbol-name (car x)))
- response))
+ (let* ((cars (mapcar (lambda (x) (symbol-name (car x)))
+ response))
(pad (1+ (cl-reduce #'max (mapcar #'length cars)))))
(while response
(let ((el (pop response)))
@@ -841,9 +814,8 @@ IND is the optional indentation level to print at."
((and (vectorp (cdr el))
(not (seq-empty-p (cdr el)))
(consp (seq-elt (cdr el) 0)))
- (insert
- (mastodon-views--format-key el pad)
- "\n\n")
+ (insert (mastodon-views--format-key el pad)
+ "\n\n")
(seq-do #'mastodon-views--print-instance-rules-or-fields (cdr el))
(insert "\n"))
;; vector of strings (media types):
@@ -852,19 +824,17 @@ IND is the optional indentation level to print at."
(< 1 (seq-length (cdr el)))
(stringp (seq-elt (cdr el) 0)))
(when ind (indent-to ind))
- (insert
- (mastodon-views--format-key el pad)
- "\n"
- (seq-mapcat
- (lambda (x) (concat x ", "))
- (cdr el) 'string)
- "\n\n"))
+ (insert (mastodon-views--format-key el pad)
+ "\n"
+ (seq-mapcat
+ (lambda (x) (concat x ", "))
+ (cdr el) 'string)
+ "\n\n"))
;; basic nesting:
((consp (cdr el))
(when ind (indent-to ind))
- (insert
- (mastodon-views--format-key el pad)
- "\n\n")
+ (insert (mastodon-views--format-key el pad)
+ "\n\n")
(mastodon-views--print-json-keys
(cdr el) (if ind (+ ind 4) 4)))
(t
@@ -879,31 +849,23 @@ IND is the optional indentation level to print at."
(insert (mastodon-views--format-key el pad)
" "
(mastodon-views--newline-if-long (cdr el))
- ;; only send strings straight to --render-text
- ;; this makes hyperlinks work:
- (if (not (stringp val))
- (mastodon-tl--render-text
- (prin1-to-string val))
- (mastodon-tl--render-text val))
+ ;; only send strings to --render-text (for hyperlinks):
+ (mastodon-tl--render-text
+ (if (stringp val) val (prin1-to-string val)))
"\n"))))))))
(defun mastodon-views--print-instance-rules-or-fields (alist)
"Print ALIST of instance rules or contact account or emoji fields."
- (let ((key (or (alist-get 'id alist)
- (alist-get 'name alist)
- (alist-get 'shortcode alist)))
- (value (or (alist-get 'text alist)
- (alist-get 'value alist)
- (alist-get 'url alist))))
- (indent-to 4)
- (insert
- (format "%-5s: "
- (propertize key
- 'face '(:underline t)))
- (mastodon-views--newline-if-long value)
- (format "%s" (mastodon-tl--render-text
- value))
- "\n")))
+ (let-alist alist
+ (let ((key (or .id .name .shortcode))
+ (value (or .text .value .url)))
+ (indent-to 4)
+ (insert (format "%-5s: "
+ (propertize key 'face '(:underline t)))
+ (mastodon-views--newline-if-long value)
+ (format "%s" (mastodon-tl--render-text
+ value))
+ "\n"))))
(defun mastodon-views--newline-if-long (el)
"Return a newline string if the cdr of EL is over 50 characters long."
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 21bd763..8b76320 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -306,11 +306,10 @@ from the server and load anew."
(progn (switch-to-buffer buffer)
(mastodon-tl--update))
(message "Loading your notifications...")
- (mastodon-tl--init-sync
- (or buffer-name "notifications")
- "notifications"
- 'mastodon-notifications--timeline
- type)
+ (mastodon-tl--init-sync (or buffer-name "notifications")
+ "notifications"
+ 'mastodon-notifications--timeline
+ type)
(with-current-buffer buffer
(use-local-map mastodon-notifications--map)))))
@@ -329,11 +328,7 @@ not, just browse the URL in the normal fashion."
(mastodon-tl--property 'shr-url :no-move)
(read-string "Lookup URL: "))))
(if (not (mastodon--masto-url-p query))
- ;; this doesn't work as shr-browse-url doesn't take a url arg
- ;; and with no args it can't use our read-string query, but only
- ;; looks for a url at point
- ;; (if (equal major-mode 'mastodon-mode)
- ;; (shr-browse-url query) ;; keep our shr keymap
+ ;; (shr-browse-url query) ; doesn't work (keep our shr keymap)
(browse-url query)
(message "Performing lookup...")
(let* ((url (format "%s/api/v2/search" mastodon-instance-url))
diff --git a/test/mastodon-profile-tests.el b/test/mastodon-profile-tests.el
index 56cb852..1936b99 100644
--- a/test/mastodon-profile-tests.el
+++ b/test/mastodon-profile-tests.el
@@ -122,48 +122,48 @@ When formatting Gargon's state we want to see
- the url of the avatar (yet to be loaded)
- the info attached to the name"
(with-mock
- ;; Don't start any image loading:
- (mock (mastodon-media--inline-images * *) => nil)
- ;; Let's not do formatting as that makes it hard to not rely on
- ;; window width and reflowing the text.
- (mock (shr-render-region * *) => nil)
- (if (version< emacs-version "27.1")
- (mock (image-type-available-p 'imagemagick) => t)
- (mock (image-transforms-p) => t))
+ ;; Don't start any image loading:
+ (mock (mastodon-media--inline-images * *) => nil)
+ ;; Let's not do formatting as that makes it hard to not rely on
+ ;; window width and reflowing the text.
+ (mock (shr-render-region * *) => nil)
+ (if (version< emacs-version "27.1")
+ (mock (image-type-available-p 'imagemagick) => t)
+ (mock (image-transforms-p) => t))
- (with-temp-buffer
- (let ((mastodon-tl--show-avatars t)
- (mastodon-tl--display-media-p t))
- (mastodon-profile--add-author-bylines (list gargron-profile-json)))
+ (with-temp-buffer
+ (let ((mastodon-tl--show-avatars t)
+ (mastodon-tl--display-media-p t))
+ (mastodon-profile--format-user (list gargron-profile-json)))
- (should
- (equal
- (buffer-substring-no-properties (point-min) (point-max))
- "\n Eugen (@Gargron)\n<p>Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.</p>\n"))
+ (should
+ (equal
+ (buffer-substring-no-properties (point-min) (point-max))
+ "\n Eugen (@Gargron)\n<p>Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.</p>\n"))
- ;; Check the avatar at pos 2
- (should
- (equal
- (get-text-property 2 'media-url)
- "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"))
- (should
- (equal
- (get-text-property 2 'media-state)
- 'needs-loading))
+ ;; Check the avatar at pos 2
+ (should
+ (equal
+ (get-text-property 2 'media-url)
+ "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"))
+ (should
+ (equal
+ (get-text-property 2 'media-state)
+ 'needs-loading))
- ;; Check the byline state
- (should
- (equal
- (get-text-property 4 'byline)
- t))
- (should
- (equal
- (get-text-property 4 'toot-id)
- (alist-get 'id gargron-profile-json)))
- (should
- (equal
- (get-text-property 4 'toot-json)
- gargron-profile-json)))))
+ ;; Check the byline state
+ (should
+ (equal
+ (get-text-property 4 'byline)
+ t))
+ (should
+ (equal
+ (get-text-property 4 'toot-id)
+ (alist-get 'id gargron-profile-json)))
+ (should
+ (equal
+ (get-text-property 4 'toot-json)
+ gargron-profile-json)))))
(ert-deftest mastodon-profile--search-account-by-handle--removes-at ()
"Should ignore a leading at-sign in user handle.