From 5d365fd5af58f715cf0e95a407cc6d840054a29b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 26 Apr 2023 21:14:51 +0200 Subject: profile-show-user: allow calling when point on profile header. --- lisp/mastodon-profile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 241fbbe..296616d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -724,6 +724,7 @@ IMG-TYPE is the JSON key from the account data." (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 -- cgit v1.2.3 From 8539f1eb911e8bdcd62488ac974ffc7592ceb1ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 08:13:31 +0200 Subject: let-alist the hell out of --make-profile-buffer-for --- lisp/mastodon-profile.el | 244 ++++++++++++++++++++++------------------------- 1 file changed, 116 insertions(+), 128 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 296616d..0c74dca 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -554,138 +554,126 @@ FIELDS means provide a fields vector fetched by other means." (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." + (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: + ;; 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: + (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) + ""))) ; 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))))) (defun mastodon-profile--format-joined-date-string (joined) "Format a human-readable Joined string from timestamp JOINED. -- cgit v1.2.3 From 825f0526352741f3a992a84124c371d7f317b15f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 18:21:06 +0200 Subject: docstring --- lisp/mastodon-profile.el | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0c74dca..a0fc9a1 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 @@ -555,7 +549,7 @@ FIELDS means provide a fields vector fetched by other means." pinned-statuses)) (defun mastodon-profile--follows-p (list) - "T if you have any relationship." + "T if you have any relationship with the accounts in LIST." (let (result) (dolist (x list result) (when (not (equal :json-false x)) -- cgit v1.2.3 From 3796619f9236ea035ed6f8f61704c16d2b13ac5b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 19:51:23 +0200 Subject: audit profile.el --- lisp/mastodon-profile.el | 73 +++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 45 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index a0fc9a1..b878352 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -207,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) @@ -241,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)) @@ -257,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)) @@ -342,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) @@ -424,10 +421,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." @@ -463,7 +458,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)))) @@ -500,15 +494,15 @@ 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. @@ -522,8 +516,7 @@ FIELDS means provide a fields vector fetched by other means." (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 @@ -543,8 +536,7 @@ 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)) @@ -583,10 +575,8 @@ HEADERS means also fetch link headers for pagination." (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) + (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")) @@ -604,24 +594,20 @@ HEADERS means also fetch link headers for pagination." (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) + (propertize .display_name 'face 'mastodon-display-name-face) "\n" - (propertize (concat "@" .acct) - 'face 'default) + (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) + (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)) + (concat "\n" (mastodon-tl--set-face + (mastodon-profile--fields-insert fields) + 'success)) "") "\n" ;; Joined date: @@ -640,9 +626,8 @@ HEADERS means also fetch link headers for pagination." 'success) ;; insert relationship (follows) (let-alist relationships - (let ((followsp - (mastodon-profile--follows-p - (list .requested_by .following .followed_by)))) + (let ((followsp (mastodon-profile--follows-p + (list .requested_by .following .followed_by)))) (if followsp (mastodon-tl--set-face (concat (when (equal .following 't) @@ -653,19 +638,18 @@ HEADERS means also fetch link headers for pagination." " | REQUESTED TO FOLLOW YOU") "\n\n") 'success) - ""))) ; if no followsp we still need str-or-char-p for insert + ""))) ; for insert call ;; insert endpoint - (mastodon-tl--set-face - (concat " " mastodon-tl--horiz-bar "\n" - endpoint-name "\n" - " " mastodon-tl--horiz-bar "\n") - 'success)) + (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 + (setq mastodon-tl--update-point (point))) ; updates after pinned toots (funcall update-function json))) (goto-char (point-min))))) @@ -703,8 +687,7 @@ 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))) -- cgit v1.2.3 From 549cca828aeb92e882b09346e2ccbb60a3fe9faf Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 19:51:42 +0200 Subject: remove useless fun profile--account-field --- lisp/mastodon-profile.el | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b878352..8c55155 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -509,7 +509,7 @@ This endpoint only holds a few preferences. For others, see Returns an alist. FIELDS means provide a fields vector fetched by other means." (let ((fields (or fields - (mastodon-profile--account-field account 'fields)))) + (alist-get 'fields account)))) (when fields (mastodon-tl--map-alist-vals-to-alist 'name 'value fields)))) @@ -528,7 +528,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))) @@ -707,11 +707,6 @@ 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. Also insert their profile note. -- cgit v1.2.3 From 6493d0dec1cc311ade347327c2b8f9656779abba Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 19:52:00 +0200 Subject: semi-refactor mastodon-profile--toggle-account-key --- lisp/mastodon-profile.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8c55155..68d74df 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -394,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." -- cgit v1.2.3 From f3298f6d51b78cd904f144d54f3b229a7bb70c6b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 19:59:03 +0200 Subject: rename profile--add-author-bylines to profile--format-user --- lisp/mastodon-profile.el | 12 +++---- lisp/mastodon-tl.el | 2 +- test/mastodon-profile-tests.el | 76 +++++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 46 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 68d74df..bd59bac 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -163,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"))) @@ -175,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"))) @@ -706,19 +706,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--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) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index cfa872b..1cd5f86 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -457,7 +457,7 @@ With arg AVATAR, include the account's avatar image." (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' + ;; `mastodon-profile--format-user' (when (and avatar mastodon-tl--show-avatars mastodon-tl--display-media-p 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

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

\n")) + (should + (equal + (buffer-substring-no-properties (point-min) (point-max)) + "\n Eugen (@Gargron)\n

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

\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. -- cgit v1.2.3 From fed797d5ea7ade8c4fdbfd6dbba783d8c67105fb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 20:01:28 +0200 Subject: audit some more profile.el --- lisp/mastodon-profile.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index bd59bac..139301f 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -507,8 +507,7 @@ This endpoint only holds a few preferences. For others, see "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 - (alist-get 'fields account)))) + (let ((fields (or fields (alist-get 'fields account)))) (when fields (mastodon-tl--map-alist-vals-to-alist 'name 'value fields)))) @@ -725,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)))) @@ -736,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)))) -- cgit v1.2.3 From d7b6621df39f9240de80141c7048101261e5c3e9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 8 May 2023 20:35:15 +0200 Subject: finish audit of profile.el --- lisp/mastodon-profile.el | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 139301f..384f9a9 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -753,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 + (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)) (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." @@ -775,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)) @@ -798,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)))) @@ -814,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))) @@ -829,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))) @@ -918,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) -- cgit v1.2.3 From 0152557eb84237425c7fac1aa107b73c7ece98dd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 10 May 2023 14:56:02 +0200 Subject: indent buffers --- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-tl.el | 22 +++++++++++----------- lisp/mastodon-toot.el | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 384f9a9..0c6e3b2 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -755,9 +755,9 @@ 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)) + (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 diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1c0d878..79897bd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -479,12 +479,12 @@ With arg AVATAR, include the account's avatar image." (propertize (concat "@" .account.acct) 'face 'mastodon-handle-face 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle + 'mastodon-tab-stop 'user-handle 'account .account - 'shr-url .account.url - 'keymap mastodon-tl--link-keymap + 'shr-url .account.url + 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .account.acct) - 'help-echo (concat "Browse user profile of @" .account.acct)) + 'help-echo (concat "Browse user profile of @" .account.acct)) ")"))) (defun mastodon-tl--format-byline-help-echo (toot) @@ -635,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 " " @@ -1388,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))) @@ -1918,7 +1918,7 @@ LANGS is the accumulated array param alist if we re-run recursively." ;; profile follows/followers but not statuses: (mastodon-tl--buffer-type-eq 'profile-followers) (mastodon-tl--buffer-type-eq 'profile-following)) - ;; fetch 'toot-json: + ;; fetch 'toot-json: (list (alist-get 'acct (mastodon-tl--property 'toot-json :no-move)))) ;; profile view, no toots @@ -2509,7 +2509,7 @@ 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 diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 11b2bc0..cbf0447 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -919,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) @@ -941,8 +941,8 @@ 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)))) + (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)))) @@ -1049,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 @@ -1443,16 +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))) + (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 -- cgit v1.2.3 From 5a1f2d19de73fa233187b705e4fe72f31db194ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 16 May 2023 09:49:53 +0200 Subject: refactoring in profile--update-note-count --- lisp/mastodon-profile.el | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0c6e3b2..b4684da 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -269,13 +269,12 @@ NO-REBLOGS means do not display boosts in statuses." (header-region (mastodon-tl--find-property-range 'note-header (point-min))) (count-region (mastodon-tl--find-property-range 'note-counter - (point-min)))) + (point-min))) + (count (number-to-string (mastodon-toot--count-toot-chars + (buffer-substring-no-properties + (cdr header-region) (point-max)))))) (add-text-properties (car count-region) (cdr count-region) - (list 'display - (number-to-string - (mastodon-toot--count-toot-chars - (buffer-substring-no-properties - (cdr header-region) (point-max)))))))) + (list 'display count)))) (defun mastodon-profile--update-profile-note-cancel () "Cancel updating user profile and kill buffer and window." -- cgit v1.2.3 From a203ad2fe6a759f3ac340198b4a168fd0d636a16 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 16 May 2023 09:50:16 +0200 Subject: refactoring in update-meta-fields-alist --- lisp/mastodon-profile.el | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b4684da..9aed0da 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -444,18 +444,14 @@ Returns the results as an alist." (mastodon-profile--get-source-value 'fields)))) ;; offer empty fields if user currently has less than four filled: (while (< (length fields-old) 4) - (setq fields-old - (append fields-old '(("" . ""))))) - (let ((alist + (setq fields-old (append fields-old '(("" . ""))))) + (let ((f-str "Metadata %s [%s/4] (max. 255 chars): ") + (alist (cl-loop for f in fields-old for x from 1 to 5 collect - (cons (read-string - (format "Metadata key [%s/4] (max. 255 chars): " x) - (car f)) - (read-string - (format "Metadata value [%s/4] (max. 255 chars): " x) - (cdr f)))))) + (cons (read-string (format f-str "key" x) (car f)) + (read-string (format f-str "value" x) (cdr f)))))) (mapcar (lambda (x) (cons (mastodon-profile--limit-to-255 (car x)) (mastodon-profile--limit-to-255 (cdr x)))) -- cgit v1.2.3 From e40a7844b48e7262b51df573605e542cd621687e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 16 May 2023 10:01:31 +0200 Subject: don't quote keywords --- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-views.el | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 9aed0da..fe1e1dc 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -214,7 +214,7 @@ NO-REBLOGS means do not display boosts in statuses." "Fetch current VAL ue from account." (let* ((url (mastodon-http--api "accounts/verify_credentials")) (response (mastodon-http--get-json url))) - (if (eq (alist-get val response) ':json-false) + (if (eq (alist-get val response) :json-false) nil (alist-get val response)))) @@ -225,7 +225,7 @@ NO-REBLOGS means do not display boosts in statuses." (defun mastodon-profile--get-source-value (pref) "Return account PREF erence from the \"source\" section on the server." (let ((source (mastodon-profile--get-source-values))) - (if (eq (alist-get pref source) ':json-false) + (if (eq (alist-get pref source) :json-false) nil (alist-get pref source)))) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index fbeb1c7..790c548 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -830,7 +830,7 @@ IND is the optional indentation level to print at." (mastodon-views--print-json-keys (cdr el) (if ind (+ ind 4) 4))) (t ; basic handling of raw booleans: - (let ((val (cond ((equal (cdr el) ':json-false) + (let ((val (cond ((equal (cdr el) :json-false) "no") ((equal (cdr el) 't) "yes") -- cgit v1.2.3 From 7b07c95304689e297b72114f0c425a6ce9aada57 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 16 May 2023 10:15:41 +0200 Subject: tiny audits in profile.el and tl.el --- lisp/mastodon-profile.el | 61 +++++++++++++++++++++++------------------------- lisp/mastodon-tl.el | 7 ++---- 2 files changed, 31 insertions(+), 37 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index fe1e1dc..6bfe64c 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -345,13 +345,11 @@ If NO-FORCE, only fetch if `mastodon-profile-account-settings' is nil." (source-keys '(privacy sensitive language))) (mapc (lambda (k) (mastodon-profile--update-preference-plist - k - (mastodon-profile--get-json-value k))) + k (mastodon-profile--get-json-value k))) keys) (mapc (lambda (sk) (mastodon-profile--update-preference-plist - sk - (mastodon-profile--get-source-value sk))) + sk (mastodon-profile--get-source-value sk))) source-keys) ;; hack for max toot chars: (mastodon-toot--get-max-toot-chars :no-toot) @@ -401,9 +399,8 @@ Current settings are fetched from the server." (defun mastodon-profile--edit-string-value (key) "Edit the string for account preference KEY." (let* ((val (mastodon-profile--get-json-value key)) - (new-val - (read-string (format "Edit account setting %s: " key) - val))) + (new-val (read-string (format "Edit account setting %s: " key) + val))) (mastodon-profile--update-preference (symbol-name key) new-val))) (defun mastodon-profile--update-display-name () @@ -432,8 +429,8 @@ Returns an alist." (mastodon-http--triage response (lambda () (mastodon-profile--fetch-server-account-settings) - (message "Account setting %s updated to %s!" - "metadata fields" fields-updated))))) + (message "Metadata fields updated to %s!" + fields-updated))))) (defun mastodon-profile--update-meta-fields-alist () "Prompt for new metadata fields information. @@ -481,11 +478,10 @@ This endpoint only holds a few preferences. For others, see (mastodon-tl--set-buffer-spec (buffer-name buf) "preferences" nil) (while response (let ((el (pop response))) - (insert - (format "%-30s %s" - (prin1-to-string (car el)) - (prin1-to-string (cdr el))) - "\n\n"))) + (insert (format "%-30s %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + "\n\n"))) (goto-char (point-min))))) @@ -706,22 +702,23 @@ Also insert their profile note. Used to view a user's followers and those they're following." (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) - 'byline 't - 'toot-id (alist-get 'id toot) - 'base-toot-id (mastodon-tl--toot-id toot) - 'toot-json toot)) - (mastodon-media--inline-images start-pos (point)) - (insert "\n" - (propertize - (mastodon-tl--render-text (alist-get 'note toot) nil) - 'toot-json toot) - "\n"))) - tootv)))) + (mapc + (lambda (toot) + (let ((start-pos (point))) + (insert "\n" + (propertize + (mastodon-tl--byline-author `((account . ,toot)) :avatar) + 'byline 't + 'toot-id (alist-get 'id toot) + 'base-toot-id (mastodon-tl--toot-id toot) + 'toot-json toot)) + (mastodon-media--inline-images start-pos (point)) + (insert "\n" + (propertize + (mastodon-tl--render-text (alist-get 'note toot) nil) + 'toot-json toot) + "\n"))) + tootv)))) (defun mastodon-profile--search-account-by-handle (handle) "Return an account based on a user's HANDLE. @@ -750,9 +747,9 @@ 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)) + (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 diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8114705..8fb0f5e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2231,11 +2231,8 @@ POS is a number, where point will be placed." ((eq type 'thread) (save-match-data (let ((endpoint (mastodon-tl--get-endpoint))) - (string-match - "statuses/\\(?2:[[:digit:]]+\\)/context" - endpoint) - (mastodon-tl--thread - (match-string 2 endpoint)))))) + (string-match "statuses/\\(?2:[[:digit:]]+\\)/context" endpoint) + (mastodon-tl--thread (match-string 2 endpoint)))))) ;; 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. -- cgit v1.2.3 From 6cdf9565598e5060c568c1503b3d2a80499bc7e6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 17 May 2023 13:15:42 +0200 Subject: remove overlays for profiles also --- lisp/mastodon-profile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 6bfe64c..7865170 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -563,6 +563,7 @@ HEADERS means also fetch link headers for pagination." (relationships (mastodon-profile--relationships-get .id))) (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-profile-mode) + (remove-overlays) (setq mastodon-profile--account account) (mastodon-tl--set-buffer-spec buffer endpoint update-function link-header) -- cgit v1.2.3 From b29306c44b8b112b24f8c14a150fdcd1ef73bb3d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 24 May 2023 09:26:03 +0200 Subject: rename tl--user-handles-get --- lisp/mastodon-profile.el | 8 ++++---- lisp/mastodon-tl.el | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7865170..d9d8a4c 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -63,7 +63,7 @@ (autoload 'mastodon-tl--find-property-range "mastodon-tl.el") (autoload 'mastodon-tl--get-link-header-from-response "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl.el") -(autoload 'mastodon-tl--interactive-user-handles-get "mastodon-tl") +(autoload 'mastodon-tl--user-handles-get "mastodon-tl") (autoload 'mastodon-tl--map-alist "mastodon-tl") (autoload 'mastodon-tl--map-alist-vals-to-alist "mastodon-tl") (autoload 'mastodon-tl--profile-buffer-p "mastodon tl") @@ -867,11 +867,11 @@ NOTE-OLD is the text of any existing note." (defun mastodon-profile--add-or-view-private-note (action-fun &optional message view) "Add or view a private note for an account. ACTION-FUN does the adding or viewing, MESSAGE is a prompt for -`mastodon-tl--interactive-user-handles-get', VIEW is a flag." +`mastodon-tl--user-handles-get', VIEW is a flag." (let* ((profile-json (mastodon-profile--profile-json)) (handle (if (mastodon-tl--profile-buffer-p) (alist-get 'acct profile-json) - (mastodon-tl--interactive-user-handles-get message))) + (mastodon-tl--user-handles-get message))) (account (if (mastodon-tl--profile-buffer-p) profile-json (mastodon-profile--search-account-by-handle handle))) @@ -893,7 +893,7 @@ the given account." (handle (if (mastodon-tl--profile-buffer-p) (alist-get 'acct profile-json) - (mastodon-tl--interactive-user-handles-get "show familiar followers of"))) + (mastodon-tl--user-handles-get "show familiar followers of"))) (account (if (mastodon-tl--profile-buffer-p) profile-json (mastodon-profile--search-account-by-handle handle))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 95a1456..5c39c93 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1803,7 +1803,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--user-handles-get "follow"))) (mastodon-tl--do-if-toot (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify langs))) @@ -1811,14 +1811,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--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--user-handles-get "disable"))) (mastodon-tl--follow-user user-handle "false")) (defun mastodon-tl--filter-user-user-posts-by-language (user-handle) @@ -1826,8 +1826,7 @@ LANGS is an array parameters alist of languages to filer user's posts by." This feature is experimental and for now not easily varified by the instance API." (interactive - (list - (mastodon-tl--interactive-user-handles-get "filter by language"))) + (list (mastodon-tl--user-handles-get "filter by language"))) (let ((langs (mastodon-tl--read-filter-langs))) (mastodon-tl--do-if-toot (mastodon-tl--follow-user user-handle nil langs)))) @@ -1850,14 +1849,14 @@ 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--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--user-handles-get "block"))) (mastodon-tl--do-if-toot (mastodon-tl--do-user-action-and-response user-handle "block"))) @@ -1872,7 +1871,7 @@ 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--user-handles-get "mute"))) (mastodon-tl--do-if-toot (mastodon-tl--do-user-action-and-response user-handle "mute"))) @@ -1887,13 +1886,13 @@ 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--user-handles-get "message"))) (mastodon-tl--do-if-toot (mastodon-toot--compose-buffer (concat "@" user-handle)) (setq mastodon-toot--visibility "direct") (mastodon-toot--update-status-fields))) -(defun mastodon-tl--interactive-user-handles-get (action) +(defun mastodon-tl--user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." (mastodon-tl--do-if-toot (let ((user-handles -- cgit v1.2.3 From e010954eb2b50fbc151e0cea5c2db11a530556d2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 10 Jun 2023 14:15:57 +0200 Subject: profile: switch followed-by/following display --- lisp/mastodon-profile.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index d9d8a4c..b8ac8be 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -621,9 +621,9 @@ HEADERS means also fetch link headers for pagination." (if followsp (mastodon-tl--set-face (concat (when (equal .following 't) - " | FOLLOWS YOU") - (when (equal .followed_by 't) " | FOLLOWED BY YOU") + (when (equal .followed_by 't) + " | FOLLOWS YOU") (when (equal .requested_by 't) " | REQUESTED TO FOLLOW YOU") "\n\n") -- cgit v1.2.3