From 411d57853a026d08493b93b674e2a8b7d7a7bae3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 31 Oct 2022 11:35:00 +0100 Subject: convert :json-false to nil in account settings handling :json-false isn't nil, so doesn't work as we want --- lisp/mastodon-profile.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index cfb3bdb..4aa9310 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -228,7 +228,9 @@ JSON is the data returned by the server." "Fetch current VAL ue from account." (let* ((url (mastodon-http--api "accounts/verify_credentials")) (response (mastodon-http--get-json url))) - (alist-get val response))) + (if (eq (alist-get val response) ':json-false) + nil + (alist-get val response)))) (defun mastodon-profile--get-source-values () "Return the \"source\" preferences from the server." @@ -237,7 +239,9 @@ JSON is the data returned by the server." (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))) - (alist-get pref source))) + (if (eq (alist-get pref source) ':json-false) + nil + (alist-get pref source)))) (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." @@ -348,7 +352,7 @@ 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 (not (equal val :json-false)) + (if val (when (y-or-n-p prompt) (mastodon-profile--update-preference (symbol-name key) "false" source)) (when (y-or-n-p prompt) -- cgit v1.2.3 From 4de094ccce07042f68596ac9dd436c453248dd6a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Nov 2022 22:09:02 +0100 Subject: display profile header image [rough start] plant header image to right of avatar --- lisp/mastodon-profile.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 4aa9310..2e4807c 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -556,7 +556,8 @@ FIELDS means provide a fields vector fetched by other means." (propertize (concat "\n" - (mastodon-profile--image-from-account account) + (mastodon-profile--image-from-account account 'avatar_static) + (mastodon-profile--image-from-account account 'header_static) "\n" (propertize (mastodon-profile--account-field account 'display_name) @@ -621,11 +622,12 @@ If toot is a boost, opens the profile of the booster." (mastodon-profile--make-author-buffer (alist-get 'account (mastodon-profile--toot-json)))) -(defun mastodon-profile--image-from-account (status) - "Generate an image from a STATUS." - (let ((url (alist-get 'avatar_static status))) - (unless (equal url "/avatars/original/missing.png") - (mastodon-media--get-media-link-rendering url)))) +(defun mastodon-profile--image-from-account (account img_type) + "Return a avatar image from ACCOUNT. +IMG_TYPE is the JSON key from the account data." + (let ((img (alist-get img_type account))) + (unless (equal img "/avatars/original/missing.png") + (mastodon-media--get-media-link-rendering img)))) (defun mastodon-profile--show-user (user-handle) "Query for USER-HANDLE from current status and show that user's profile." -- cgit v1.2.3 From 40cf1038e386cfe62cfcc81234794b3a13102176 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 5 Nov 2022 10:40:26 +0100 Subject: add headers arg to http--process-json and --get-json-async --- lisp/mastodon-http.el | 17 +++++++++++++---- lisp/mastodon-profile.el | 3 ++- lisp/mastodon-tl.el | 11 ++++++----- lisp/mastodon-toot.el | 5 +++-- 4 files changed, 24 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index e3efabe..46a6398 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -154,10 +154,19 @@ SILENT means don't message." (with-current-buffer (mastodon-http--get url silent) (mastodon-http--process-json))) -(defun mastodon-http--process-json () +(defun mastodon-http--process-json (&optional headers) "Process JSON response." ;; view raw response: - ;; (switch-to-buffer (current-buffer)) + (switch-to-buffer (current-buffer)) + (when headers + (let* ((head-str (buffer-substring-no-properties + (point-min) + (re-search-forward "^$" nil 'move))) + (head-list (split-string head-str "\n")) + (head-alist (mapcar (lambda (x) + (split-string x ": ")) + head-list))) + (setq mastodon-http-headers-alist head-alist))) (goto-char (point-min)) (re-search-forward "^$" nil 'move) (let ((json-string @@ -241,13 +250,13 @@ Pass response buffer to CALLBACK function with args CBARGS." "GET" (url-retrieve url callback cbargs))) -(defun mastodon-http--get-json-async (url &optional callback &rest args) +(defun mastodon-http--get-json-async (url &optional headers callback &rest args) "Make GET request to URL. Call CALLBACK with json-vector and ARGS." (mastodon-http--get-async url (lambda (status) (when status ;; only when we actually get sth? - (apply callback (mastodon-http--process-json) args))))) + (apply callback (mastodon-http--process-json headers) args))))) (defun mastodon-http--post-async (url args headers &optional callback &rest cbargs) "POST asynchronously to URL with ARGS and HEADERS. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 2e4807c..ebd1b37 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -183,7 +183,8 @@ contains") (message "Loading your favourited toots...") (mastodon-tl--init "favourites" "favourites" - 'mastodon-tl--timeline)) + 'mastodon-tl--timeline + :headers)) (defun mastodon-profile--view-bookmarks () "Open a new buffer displaying the user's bookmarks." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1986979..a9c8b39 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1139,7 +1139,7 @@ Then run CALLBACK with arguments CBARGS." "?") "max_id=" (mastodon-tl--as-string id))))) - (apply 'mastodon-http--get-json-async url callback cbargs))) + (apply 'mastodon-http--get-json-async url nil callback cbargs))) ;; TODO ;; Look into the JSON returned here by Local @@ -1907,14 +1907,15 @@ from the start if it is nil." (goto-char (or mastodon-tl--update-point (point-min))) (funcall update-function json))))) -(defun mastodon-tl--init (buffer-name endpoint update-function) +(defun mastodon-tl--init (buffer-name endpoint update-function &optional headers) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT asynchronously. - -UPDATE-FUNCTION is used to recieve more toots." +UPDATE-FUNCTION is used to recieve more toots. +HEADERS means to also collect the response headers. Used for paginating +favourites." (let ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*"))) (mastodon-http--get-json-async - url 'mastodon-tl--init* buffer endpoint update-function))) + url headers 'mastodon-tl--init* buffer endpoint update-function))) (defun mastodon-tl--init* (json buffer endpoint update-function) "Initialize BUFFER with timeline targeted by ENDPOINT. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 44386f7..25446ef 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -203,12 +203,13 @@ send.") nil t))) (mastodon-profile--update-preference "privacy" vis :source))) -(defun mastodon-toot--get-max-toot-chars (&optional _no-toot) +(defun mastodon-toot--get-max-toot-chars (&optional no-toot) "Fetch max_toot_chars from `mastodon-instance-url' asynchronously. NO-TOOT means we are not calling from a toot buffer." (mastodon-http--get-json-async (mastodon-http--api "instance") - 'mastodon-toot--get-max-toot-chars-callback 'no-toot)) + nil + 'mastodon-toot--get-max-toot-chars-callback no-toot)) (defun mastodon-toot--get-max-toot-chars-callback (json-response &optional no-toot) -- cgit v1.2.3 From 14eb275b966395b04da438a804b0a9a4a5d0dcab Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Nov 2022 11:52:40 +0100 Subject: relationships in print profile buffer - get json list not vect --- 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 ebd1b37..e664ee5 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -466,7 +466,8 @@ This endpoint only holds a few preferences. For others, see (url (mastodon-http--api (format "accounts/relationships?id[]=%s" their-id)))) - (mastodon-http--get-json url))) + ;; FIXME: not sure why we need to do this for relationships only! + (car (mastodon-http--get-json url)))) (defun mastodon-profile--fields-get (&optional account fields) "Fetch the fields vector (aka profile metadata) from profile of ACCOUNT. @@ -528,11 +529,9 @@ FIELDS means provide a fields vector fetched by other means." account 'statuses_count))) (relationships (mastodon-profile--relationships-get id)) (followed-by-you (when (not (seq-empty-p relationships)) - (alist-get 'following - (aref relationships 0)))) + (alist-get 'following relationships))) (follows-you (when (not (seq-empty-p relationships)) - (alist-get 'followed_by - (aref relationships 0)))) + (alist-get 'followed_by relationships))) (followsp (or (equal follows-you 't) (equal followed-by-you 't))) (fields (mastodon-profile--fields-get account)) (pinned (mastodon-profile--get-statuses-pinned account))) -- cgit v1.2.3 From 3ca11d498d1bf386ce302972c202a6222128534d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Nov 2022 21:23:22 +0100 Subject: masto-toot-mode-hook - only fetch acc settings if not set the idea is to be able to start composing a toot without making any unnecessary requests. masto-mode-hook still always fetches (in case settings changed elsewhere). and we always fetch when we change a setting. --- lisp/mastodon-profile.el | 52 ++++++++++++++++++++++++++++-------------------- lisp/mastodon-toot.el | 3 ++- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 4aa9310..99af63a 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -296,30 +296,38 @@ This is done after changing the setting on the server." (setq mastodon-profile-account-settings (plist-put mastodon-profile-account-settings pref val))) -(defun mastodon-profile-fetch-server-account-settings () +(defun mastodon-profile-fetch-server-account-settings-maybe () + "Fetch account settings from the server if `mastodon-profile-account-settings' is nil." + (mastodon-profile-fetch-server-account-settings :no-force)) + +(defun mastodon-profile-fetch-server-account-settings (&optional no-force) "Fetch basic account settings from the server. Store the values in `mastodon-profile-account-settings'. -Run in `mastodon-mode-hook'." - (let ((keys '(locked discoverable display_name bot)) - (source-keys '(privacy sensitive language))) - (mapc (lambda (k) - (mastodon-profile-update-preference-plist - k - (mastodon-profile--get-json-value k))) - keys) - (mapc (lambda (sk) - (mastodon-profile-update-preference-plist - sk - (mastodon-profile--get-source-value sk))) - source-keys) - ;; hack for max toot chars: - (mastodon-toot--get-max-toot-chars :no-toot) - (mastodon-profile-update-preference-plist 'max_toot_chars - mastodon-toot--max-toot-chars) - ;; TODO: remove now redundant vars, replace with fetchers from the plist - (setq mastodon-toot--visibility (mastodon-profile--get-pref 'privacy) - mastodon-toot--content-nsfw (mastodon-profile--get-pref 'sensitive)) - mastodon-profile-account-settings)) +Run in `mastodon-mode-hook'. +If NO-FORCE is non-nil, only fetch if `mastodon-profile-account-settings' is nil." + (unless + (and no-force + mastodon-profile-account-settings) + (let ((keys '(locked discoverable display_name bot)) + (source-keys '(privacy sensitive language))) + (mapc (lambda (k) + (mastodon-profile-update-preference-plist + k + (mastodon-profile--get-json-value k))) + keys) + (mapc (lambda (sk) + (mastodon-profile-update-preference-plist + sk + (mastodon-profile--get-source-value sk))) + source-keys) + ;; hack for max toot chars: + (mastodon-toot--get-max-toot-chars :no-toot) + (mastodon-profile-update-preference-plist 'max_toot_chars + mastodon-toot--max-toot-chars) + ;; TODO: remove now redundant vars, replace with fetchers from the plist + (setq mastodon-toot--visibility (mastodon-profile--get-pref 'privacy) + mastodon-toot--content-nsfw (mastodon-profile--get-pref 'sensitive)) + mastodon-profile-account-settings))) (defun mastodon-profile-account-locked-toggle () "Toggle the locked status of your account. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 7a40354..30f4a25 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -78,6 +78,7 @@ (autoload 'mastodon-profile--update-preference "mastodon-profile") (autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile") (autoload 'mastodon-tl--render-text "mastodon-tl") +(autoload 'mastodon-profile-fetch-server-account-settings-maybe "mastodon-profile") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -1284,7 +1285,7 @@ a draft into the buffer." (insert initial-text)))) ;;;###autoload -(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings) +(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings-maybe) (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." -- cgit v1.2.3 From 699cc27b3a141544fbf48603eff4fbfea0911cd7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Nov 2022 20:44:41 +0100 Subject: FIX update profile note - params alist format --- lisp/mastodon-profile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index ba3a0d3..5b243d1 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -271,7 +271,7 @@ JSON is the data returned by the server." (let* ((note (buffer-substring-no-properties (point-min) (point-max))) (url (mastodon-http--api "accounts/update_credentials"))) (kill-buffer-and-window) - (let ((response (mastodon-http--patch url `((note ,note))))) + (let ((response (mastodon-http--patch url `(("note" . ,note))))) (mastodon-http--triage response (lambda () (message "Profile note updated!")))))) -- cgit v1.2.3 From 7dc13db0a929f8fe4b2c3b8e8a9b88b361914aa8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Nov 2022 20:48:11 +0100 Subject: GET verify_cred not PATCH update_creds for fetch profile note --- 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 5b243d1..553c21d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -247,8 +247,8 @@ JSON is the data returned by the server." (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." (interactive) - (let* ((url (mastodon-http--api "accounts/update_credentials")) - (json (mastodon-http--patch-json url)) + (let* ((url (mastodon-http--api "accounts/verify_credentials")) + (json (mastodon-http--get-json url)) (source (alist-get 'source json)) (note (alist-get 'note source)) (buffer (get-buffer-create "*mastodon-update-profile*")) -- cgit v1.2.3 From d5802f73a4878afea4d902fc973b19ab4c209bd5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Nov 2022 11:09:40 +0100 Subject: flycheck -profile / profile--toot-json todos --- lisp/mastodon-profile.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 553c21d..56e5fef 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -137,6 +137,11 @@ contains") (defun mastodon-profile--toot-json () "Get the next toot-json." (interactive) + ;; NB: we cannot add + ;; (or (mastodon-tl--property 'profile-json) + ;; here because it searches forward endlessly + ;; TODO: it would be nice to be able to do so tho + ;; or handle --property failing (mastodon-tl--property 'toot-json)) (defun mastodon-profile--make-author-buffer (account) @@ -298,14 +303,15 @@ This is done after changing the setting on the server." (plist-put mastodon-profile-account-settings pref val))) (defun mastodon-profile-fetch-server-account-settings-maybe () - "Fetch account settings from the server if `mastodon-profile-account-settings' is nil." + "Fetch account settings from the server. +Only do so if `mastodon-profile-account-settings' is nil." (mastodon-profile-fetch-server-account-settings :no-force)) (defun mastodon-profile-fetch-server-account-settings (&optional no-force) "Fetch basic account settings from the server. Store the values in `mastodon-profile-account-settings'. Run in `mastodon-mode-hook'. -If NO-FORCE is non-nil, only fetch if `mastodon-profile-account-settings' is nil." +If NO-FORCE, only fetch if `mastodon-profile-account-settings' is nil." (unless (and no-force mastodon-profile-account-settings) -- cgit v1.2.3 From 66b37a1ad65caa1c6cbe3e7b6ad7bc3ad7084da4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 13 Nov 2022 11:21:26 +0100 Subject: comment profile 's' and 'g' view followers/-ing bindings 's' conflicts with translate-toot-at-point. C-c C-c does the job anyway --- lisp/mastodon-profile.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 56e5fef..ea73b99 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -82,8 +82,11 @@ (defvar mastodon-profile-mode-map (let ((map (make-sparse-keymap))) - (define-key map (kbd "s") #'mastodon-profile--open-followers) - (define-key map (kbd "g") #'mastodon-profile--open-following) + ;; 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'.") -- cgit v1.2.3 From 447081217888977ecfcbe8a005566f44929a16e6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 13 Nov 2022 11:23:39 +0100 Subject: change foll-reqs view reject binding to 'j', like notifs view then 'r' is only ever used for reply, even tho not avail in fr view --- README.org | 2 +- lisp/mastodon-profile.el | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/README.org b/README.org index fc238a1..ffe65df 100644 --- a/README.org +++ b/README.org @@ -133,7 +133,7 @@ take place if your =mastodon-token-file= does not contain =:client_id= and | | *Other views* | | =S= | search (posts, users, tags) (NB: only posts you have interacted with) | | =I=, =c=, =d= | view, create, and delete filters | -| =R=, =a=, =r= | view/accept/reject follow requests | +| =R=, =a=, =j= | view/accept/reject follow requests | | =G= | view follow suggestions | | =V= | view your favourited toots | | =K= | view bookmarked toots | diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index ea73b99..63c062b 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -94,7 +94,10 @@ (defvar mastodon-profile--view-follow-requests-keymap (let ((map ;(make-sparse-keymap))) (copy-keymap mastodon-mode-map))) - (define-key map (kbd "r") #'mastodon-notifications--follow-request-reject) + ;; make reject binding match the binding in notifs view + ;; 'r' is then reserved for replying, even tho it is not avail + ;; in foll-reqs view + (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject) (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept) (define-key map (kbd "n") #'mastodon-tl--goto-next-item) (define-key map (kbd "p") #'mastodon-tl--goto-prev-item) -- cgit v1.2.3