From 3c40f6dbb855fb4a3100f1822c4d2a29c29737a2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 27 Aug 2022 11:21:24 +0200 Subject: readme CI status --- README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.org b/README.org index 53bfc3c..f8e3af4 100644 --- a/README.org +++ b/README.org @@ -1,5 +1,7 @@ #+OPTIONS: toc:nil +[[https://ci.codeberg.org/api/badges/martianh/mastodon.el/status.svg]] + * README =mastodon.el= is an Emacs client for the Mastodon and Pleroma social networks. For info see https://joinmastodon.org/. -- cgit v1.2.3 From 43625baee1137335f8220348dfde4439aef048ae Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 30 Aug 2022 23:34:34 +0200 Subject: autoload --- lisp/mastodon-notifications.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 9986ede..32cc4ee 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -49,6 +49,7 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl.el") (autoload 'mastodon-http--get-params-async-json "mastodon-http.el") (autoload 'mastodon-profile--view-follow-requests "mastodon-profile.el") +(autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) (defvar mastodon-tl--buffer-spec) -- cgit v1.2.3 From 7672a0240b45675c1fde0ca960fea56c02ecc4ab Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 08:49:25 +0200 Subject: http--api in -profile.el --- lisp/mastodon-profile.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 516059e..9c28703 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -212,8 +212,7 @@ 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 (concat mastodon-instance-url - "/api/v1/accounts/update_credentials")) + (let* ((url (mastodon-http--api "accounts/update_credentials")) ;; (buffer (mastodon-http--patch url)) (json (mastodon-http--patch-json url)) (source (alist-get 'source json)) @@ -236,8 +235,7 @@ JSON is the data returned by the server." "Send PATCH request with the updated profile note." (interactive) (let* ((note (buffer-substring-no-properties (point-min) (point-max))) - (url (concat mastodon-instance-url - "/api/v1/accounts/update_credentials"))) + (url (mastodon-http--api "accounts/update_credentials"))) (kill-buffer-and-window) (let ((response (mastodon-http--patch url note))) (mastodon-http--triage response -- cgit v1.2.3 From e670268cc5dbaf1f4b0605a79ec63422bda03c3a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 08:49:41 +0200 Subject: view brief prefs fun --- lisp/mastodon-profile.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 9c28703..0496d53 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -241,6 +241,26 @@ JSON is the data returned by the server." (mastodon-http--triage response (lambda () (message "Profile note updated!")))))) +(defun mastodon-profile-view-preferences () + "View user preferences in another window." + (interactive) + (let* ((url (mastodon-http--api "preferences")) + (response (mastodon-http--get-json url)) + (buf (get-buffer-create "*mastodon-preferences*"))) + (with-current-buffer buf + (switch-to-buffer-other-window buf) + (erase-buffer) + (special-mode) + (let ((inhibit-read-only t)) + (while response + (let ((el (pop response))) + (insert + (format "%-30s %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + "\n\n")))) + (goto-char (point-min))))) + (defun mastodon-profile--relationships-get (id) "Fetch info about logged-in user's relationship to user with id ID." (let* ((their-id id) -- cgit v1.2.3 From de033f831b10fa84b0ba36f067788d2c7587dc7a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 11:07:47 +0200 Subject: buffer-spec for search buffers (so following works) --- lisp/mastodon-search.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 8d450e3..10e12c3 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -103,6 +103,11 @@ QUERY is the string to search." (mastodon-mode) (let ((inhibit-read-only t)) (erase-buffer) + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,(format "api/v2/search") + update-function + (lambda (toot) (message "Searched.")))) ;; user results: (insert (mastodon-tl--set-face (concat "\n ------------\n" -- cgit v1.2.3 From 59a1fbda1f6c3d8cc20714eb000e05bee7c5310e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 12:44:52 +0200 Subject: http--patch: make general function, not just for note - this way we can build funs to change basic account options. --- lisp/mastodon-http.el | 19 ++++++++----------- lisp/mastodon-profile.el | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 49b2375..9904232 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -168,7 +168,7 @@ Pass response buffer to CALLBACK function." (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 `url-build-query-string'." +PARAMS should be an alist as required by `url-build-query-string'." (let ((query-string (url-build-query-string params))) (concat url "?" query-string))) @@ -204,21 +204,18 @@ PARAM is a formatted request parameter, eg 'following=true'." ;; profile update functions -(defun mastodon-http--patch-json (url) - "Make synchronous PATCH request to URL. Return JSON response." - (with-current-buffer (mastodon-http--patch url) +(defun mastodon-http--patch-json (url &optional params) + "Make synchronous PATCH request to URL. Return JSON response. +Optionally specify the PARAMS to send." + (with-current-buffer (mastodon-http--patch url params) (mastodon-http--process-json))) -;; hard coded just for bio note for now: -(defun mastodon-http--patch (base-url &optional note) +(defun mastodon-http--patch (base-url &optional params) "Make synchronous PATCH request to BASE-URL. -Optionally specify the NOTE to edit. -Pass response buffer to CALLBACK function." +Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" - (let ((url (if note - (concat base-url "?note=" (url-hexify-string note)) - base-url))) + (let ((url (mastodon-http--append-query-string base-url params))) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0496d53..a27afd2 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -237,7 +237,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))) + (let ((response (mastodon-http--patch url `((note ,note))))) (mastodon-http--triage response (lambda () (message "Profile note updated!")))))) -- cgit v1.2.3 From 7b48b973bfccab713af5938cbf6124984d4a7b25 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 14:20:13 +0200 Subject: get and set account preference functions --- lisp/mastodon-profile.el | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index a27afd2..6fe3e14 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -207,13 +207,25 @@ JSON is the data returned by the server." 'byline t 'toot-id "0")) (mastodon-search--insert-users-propertized json :note))) - ;; (mastodon-profile--add-author-bylines json))) +;; (mastodon-profile--add-author-bylines json))) + +;;; account preferences + +(defun mastodon-profile--get-source-prefs () + "Return the \"source\" preferences from the server." + (let* ((url (mastodon-http--api "accounts/verify_credentials")) + (response (mastodon-http--get-json url))) + (alist-get 'source response))) + +(defun mastodon-profile--get-source-pref (pref) + "Return account PREF erence from the \"source\" section on the server." + (let ((source (mastodon-profile--get-source-prefs))) + (alist-get pref source))) (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")) - ;; (buffer (mastodon-http--patch url)) (json (mastodon-http--patch-json url)) (source (alist-get 'source json)) (note (alist-get 'note source)) @@ -241,6 +253,16 @@ JSON is the data returned by the server." (mastodon-http--triage response (lambda () (message "Profile note updated!")))))) +(defun mastodon-profile--update-preference (pref val &optional source) + "Update a single acount PREF erence to setting VAL. +SOURCE means that the preference is in the 'source' part of the account json." + (let* ((url (mastodon-http--api "accounts/update_credentials")) + (pref (if source (concat "source[" pref "]") pref)) + (response (mastodon-http--patch url `((,pref ,val))))) + (mastodon-http--triage response + (lambda () + (message "Account setting %s updated!" pref))))) + (defun mastodon-profile-view-preferences () "View user preferences in another window." (interactive) -- cgit v1.2.3 From fcdf2ca8451c21e373d1d484ee4883b9ec26c6e1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 14:20:34 +0200 Subject: respect toot visibility setting from the server --- lisp/mastodon-toot.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 23abb84..3ecca20 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -71,6 +71,7 @@ (autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") +(autoload 'mastodon-profile--get-source-pref "mastodon-profile") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -141,7 +142,9 @@ This is only used if company mode is installed." "A string indicating the visibility of the toot being composed. Valid values are \"direct\", \"private\" (followers-only), -\"unlisted\", and \"public\".") +\"unlisted\", and \"public\". + +This may be set by the account setting on the server.") (defvar-local mastodon-toot--media-attachments nil "A list of the media attachments of the toot being composed.") @@ -1030,11 +1033,15 @@ REPLY-JSON is the full JSON of the toot being replied to." (switch-to-buffer-other-window buffer) (text-mode) (mastodon-toot-mode t) + ;; use toot visibility setting from the server: + (setq mastodon-toot--visibility + (mastodon-profile--get-source-pref 'privacy)) (unless buffer-exists (mastodon-toot--display-docs-and-status-fields) (mastodon-toot--setup-as-reply reply-to-user reply-to-id reply-json)) (unless mastodon-toot--max-toot-chars (mastodon-toot--get-max-toot-chars)) + ;; set up company backends: (when (require 'company nil :noerror) (when mastodon-toot--enable-completion (set (make-local-variable 'company-backends) -- cgit v1.2.3 From 284b4d583f4c78c815739dc4ec9bbcf39595117b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 14:26:47 +0200 Subject: remove default-visibility defcustom --- lisp/mastodon-toot.el | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 3ecca20..253fb5d 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -83,18 +83,6 @@ :prefix "mastodon-toot-" :group 'mastodon) -(defcustom mastodon-toot--default-visibility "public" - "The default visibility for new toots. - -Must be one of \"public\", \"unlisted\", \"private\" (for -followers-only), or \"direct\"." - :group 'mastodon-toot - :type '(choice - (const :tag "public" "public") - (const :tag "unlisted" "unlisted") - (const :tag "followers only" "private") - (const :tag "direct" "direct"))) - (defcustom mastodon-toot--default-media-directory "~/" "The default directory when prompting for a media file to upload." :group 'mastodon-toot -- cgit v1.2.3 From 6f7c564d90b7d477ef600a9ffb742faaaf38d3fb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 14:31:14 +0200 Subject: readme clean up --- README.org | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.org b/README.org index 3b91224..baa7dfa 100644 --- a/README.org +++ b/README.org @@ -216,12 +216,7 @@ See =M-x customize-group RET mastodon= to view all customize options. - Enable image caching - Compose options: - - Default toot visibility, using =mastodon-toot--default-visibility= variable. Valid values are ="public"=, ="unlisted"=, ="private"=, or =direct=. -<<<<<<< HEAD - - Completions for user mentions -======= - Completion for mentions and tags ->>>>>>> develop - Enable custom emoji *** live-updating timelines: =mastodon-async-mode= -- cgit v1.2.3 From 81bc0978fd36a17d2e0fba4123754ccc2af9035d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 15:10:52 +0200 Subject: set default visibility fun --- lisp/mastodon-profile.el | 9 +++++++++ lisp/mastodon-toot.el | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 6fe3e14..0c91556 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -70,6 +70,7 @@ (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) (defvar mastodon-mode-map) +(defvar mastodon-toot-visibility-list) (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") @@ -263,6 +264,14 @@ SOURCE means that the preference is in the 'source' part of the account json." (lambda () (message "Account setting %s updated!" pref))))) +(defun mastodon-profile-set-default-toot-visibility () + "Set the default visibility for toots." + (interactive) + (let ((vis (completing-read "Set default visibility to:" + mastodon-toot-visibility-list + nil t))) + (mastodon-profile--update-preference "privacy" vis :source))) + (defun mastodon-profile-view-preferences () "View user preferences in another window." (interactive) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 253fb5d..8d8b9f3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -126,6 +126,10 @@ This is only used if company mode is installed." (defvar-local mastodon-toot--content-nsfw nil "A flag indicating whether the toot should be marked as NSFW.") +(defvar mastodon-toot-visibility-list + '(direct private unlisted public) + "A list of the available toot visibility settings.") + (defvar-local mastodon-toot--visibility "public" "A string indicating the visibility of the toot being composed. -- cgit v1.2.3 From 889e7079efe2ea266491dc383491a8a3dfb6ca94 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 15:32:27 +0200 Subject: readme contributors --- README.org | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index baa7dfa..b950681 100644 --- a/README.org +++ b/README.org @@ -219,7 +219,7 @@ See =M-x customize-group RET mastodon= to view all customize options. - Completion for mentions and tags - Enable custom emoji -*** live-updating timelines: =mastodon-async-mode= +*** Live-updating timelines: =mastodon-async-mode= (code taken from https://github.com/alexjgriffith/mastodon-future.el.) @@ -232,7 +232,7 @@ To enable, it, add =(require 'mastodon-async)= to your =init.el=. Then you can view a timeline with one of the commands that begin with =mastodon-async--stream-=. -*** translating toots +*** Translating toots You can translate toots with =mastodon-toot--translate-toot-text=. At the moment this requires [[https://codeberg.org/martianh/lingva.el][lingva.el]], a little interface I wrote to https://lingva.ml, to @@ -255,7 +255,7 @@ to your translator function as its text argument. Here's what (message "No toot to translate?")))) #+end_src -** dependencies +** Dependencies This version depends on the library =request= (for uploading attachments). You can install it from MELPA, or https://github.com/tkf/emacs-request. @@ -281,3 +281,15 @@ PRs, issues, and feature requests are very welcome! 1. In an [[https://github.com/jdenen/mastodon.el/issues][issue]], let me know that you're working to fix it. 2. Fork the repository and create a branch off of =develop=. 3. Create a pull request referencing the issue from step 1. + +** Contributors: + +=mastodon.el= is a the work of a number of people. + +Some significant contributors are: + +- https://github.com/jdenen [original author] +- http://atomized.org +- https://alexjgriffith.itch.io +- https://github.com/hdurer +- https://codeberg.org/Red_Starfish -- cgit v1.2.3 From 4d9073299485d3dc6095f824ae017b7d35bd0c1d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 16:32:26 +0200 Subject: profile: refactor get-source-prefs with get-json-value --- lisp/mastodon-profile.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0c91556..1fc4d09 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -212,11 +212,15 @@ JSON is the data returned by the server." ;;; account preferences -(defun mastodon-profile--get-source-prefs () - "Return the \"source\" preferences from the server." +(defun mastodon-profile--get-json-value (val) + "Fetch current VAL ue from account." (let* ((url (mastodon-http--api "accounts/verify_credentials")) (response (mastodon-http--get-json url))) - (alist-get 'source response))) + (alist-get val response))) + +(defun mastodon-profile--get-source-prefs () + "Return the \"source\" preferences from the server." + (mastodon-profile--get-json-value 'source)) (defun mastodon-profile--get-source-pref (pref) "Return account PREF erence from the \"source\" section on the server." -- cgit v1.2.3 From 6fe9d764d568c2ba001a932305f5d926c2f63c25 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 16:32:50 +0200 Subject: toggle account locked status --- lisp/mastodon-profile.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 1fc4d09..284bae6 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -260,6 +260,7 @@ JSON is the data returned by the server." (defun mastodon-profile--update-preference (pref val &optional source) "Update a single acount PREF erence to setting VAL. +Both args are strings. SOURCE means that the preference is in the 'source' part of the account json." (let* ((url (mastodon-http--api "accounts/update_credentials")) (pref (if source (concat "source[" pref "]") pref)) @@ -268,6 +269,17 @@ SOURCE means that the preference is in the 'source' part of the account json." (lambda () (message "Account setting %s updated!" pref))))) +(defun mastodon-profile-account-locked-toggle () + "Toggle the locked status of the user's account. +Locked accounts mean follow requests have to be manually approved." + (interactive) + (let ((locked-p (mastodon-profile--get-json-value 'locked))) + (if (not (equal locked-p :json-false)) + (when (y-or-n-p "Account is locked to new followers. Unlock?") + (mastodon-profile--update-preference "locked" "false")) + (when (y-or-n-p "Account is not locked to new followers. Lock it?") + (mastodon-profile--update-preference "locked" "true"))))) + (defun mastodon-profile-set-default-toot-visibility () "Set the default visibility for toots." (interactive) -- cgit v1.2.3 From a30b8353d122a753be6fcf38fe84f7da99ad2ebd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 16:46:12 +0200 Subject: refactor locked toggle, add discoverable toggle --- lisp/mastodon-profile.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 284bae6..5c4adaa 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -273,12 +273,23 @@ SOURCE means that the preference is in the 'source' part of the account json." "Toggle the locked status of the user's account. Locked accounts mean follow requests have to be manually approved." (interactive) - (let ((locked-p (mastodon-profile--get-json-value 'locked))) - (if (not (equal locked-p :json-false)) - (when (y-or-n-p "Account is locked to new followers. Unlock?") - (mastodon-profile--update-preference "locked" "false")) - (when (y-or-n-p "Account is not locked to new followers. Lock it?") - (mastodon-profile--update-preference "locked" "true"))))) + (mastodon-profile--toggle-account-key 'locked)) + +(defun mastodon-profile-account-discoverable-toggle () + "Toggle the discoverable status of the user's account. +Discoverable means the account is listed in the server directory." + (interactive) + (mastodon-profile--toggle-account-key 'discoverable)) + +(defun mastodon-profile--toggle-account-key (key) + "Toggle the boolean account setting KEY." + (let* ((val (mastodon-profile--get-json-value key)) + (prompt (format "Account setting %s is %s. Toggle?" key val))) + (if (not (equal val :json-false)) + (when (y-or-n-p prompt) + (mastodon-profile--update-preference (symbol-name key) "false")) + (when (y-or-n-p prompt) + (mastodon-profile--update-preference (symbol-name key) "true"))))) (defun mastodon-profile-set-default-toot-visibility () "Set the default visibility for toots." -- cgit v1.2.3 From 7e98dae4756b62b34a2526ef6c776258db4c5202 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 31 Aug 2022 21:44:26 +0200 Subject: improve set default-toot-visibility formatting --- lisp/mastodon-profile.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5c4adaa..c43906f 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -263,11 +263,11 @@ JSON is the data returned by the server." Both args are strings. SOURCE means that the preference is in the 'source' part of the account json." (let* ((url (mastodon-http--api "accounts/update_credentials")) - (pref (if source (concat "source[" pref "]") pref)) - (response (mastodon-http--patch url `((,pref ,val))))) + (pref-formatted (if source (concat "source[" pref "]") pref)) + (response (mastodon-http--patch url `((,pref-formatted ,val))))) (mastodon-http--triage response (lambda () - (message "Account setting %s updated!" pref))))) + (message "Account setting %s updated to %s!" pref val))))) (defun mastodon-profile-account-locked-toggle () "Toggle the locked status of the user's account. -- cgit v1.2.3 From 5142c83a75dd5728d11beba1711ae1f1d53cb423 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 09:27:50 +0200 Subject: edit display_name fun --- lisp/mastodon-profile.el | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c43906f..116af5d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -270,13 +270,13 @@ SOURCE means that the preference is in the 'source' part of the account json." (message "Account setting %s updated to %s!" pref val))))) (defun mastodon-profile-account-locked-toggle () - "Toggle the locked status of the user's account. + "Toggle the locked status of your account. Locked accounts mean follow requests have to be manually approved." (interactive) (mastodon-profile--toggle-account-key 'locked)) (defun mastodon-profile-account-discoverable-toggle () - "Toggle the discoverable status of the user's account. + "Toggle the discoverable status of your account. Discoverable means the account is listed in the server directory." (interactive) (mastodon-profile--toggle-account-key 'discoverable)) @@ -291,6 +291,19 @@ Discoverable means the account is listed in the server directory." (when (y-or-n-p prompt) (mastodon-profile--update-preference (symbol-name key) "true"))))) +(defun mastodon-profile--edit-account-string (key) + "Edit the string for account setting KEY." + (let* ((val (mastodon-profile--get-json-value key)) + (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 () + "Update display name for your account." + (interactive) + (mastodon-profile--edit-account-string 'display_name)) + (defun mastodon-profile-set-default-toot-visibility () "Set the default visibility for toots." (interactive) -- cgit v1.2.3 From ee35f8c94d6ee76d75bdf85f2b495df4ce6c5a94 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 11:04:25 +0200 Subject: readme account settings funcs --- README.org | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.org b/README.org index b950681..d9e0b39 100644 --- a/README.org +++ b/README.org @@ -219,6 +219,13 @@ See =M-x customize-group RET mastodon= to view all customize options. - Completion for mentions and tags - Enable custom emoji +*** Account settings: + +- =mastodon-profile-update-display-name=: Update the display name for your account. +- =mastodon-profile-set-default-toot-visibility=: Set the default visibility for your toots. +- =mastodon-profile-account-locked-toggle=: Toggle the locked status of your account. Locked accounts have to manually approve follow requests. +- =mastodon-profile-account-discoverable-toggle=: Toggle the discoverable status of your account. Non-discoverable accounts are not listed in the profile directory. + *** Live-updating timelines: =mastodon-async-mode= (code taken from https://github.com/alexjgriffith/mastodon-future.el.) -- cgit v1.2.3 From f6a2a14066cae107deab1805b8e5ff99d28c5125 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 14:13:34 +0200 Subject: move set-default-toot-visibility to -toot.el --- lisp/mastodon-profile.el | 9 --------- lisp/mastodon-toot.el | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 116af5d..25edfba 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -70,7 +70,6 @@ (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) (defvar mastodon-mode-map) -(defvar mastodon-toot-visibility-list) (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") @@ -304,14 +303,6 @@ Discoverable means the account is listed in the server directory." (interactive) (mastodon-profile--edit-account-string 'display_name)) -(defun mastodon-profile-set-default-toot-visibility () - "Set the default visibility for toots." - (interactive) - (let ((vis (completing-read "Set default visibility to:" - mastodon-toot-visibility-list - nil t))) - (mastodon-profile--update-preference "privacy" vis :source))) - (defun mastodon-profile-view-preferences () "View user preferences in another window." (interactive) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8d8b9f3..d7efd44 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -72,6 +72,7 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") (autoload 'mastodon-profile--get-source-pref "mastodon-profile") +(autoload 'mastodon-profile--update-preference "mastodon-profile") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -164,6 +165,14 @@ This may be set by the account setting on the server.") map) "Keymap for `mastodon-toot'.") +(defun mastodon-toot-set-default-visibility () + "Set the default visibility for toots on the server." + (interactive) + (let ((vis (completing-read "Set default visibility to:" + mastodon-toot-visibility-list + nil t))) + (mastodon-profile--update-preference "privacy" vis :source))) + (defun mastodon-toot--get-max-toot-chars () "Fetch max_toot_chars from `mastodon-instance-url' asynchronously." (mastodon-http--get-json-async -- cgit v1.2.3 From c6aa74e6942f5156e43a027c54862bfd68270911 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 14:19:03 +0200 Subject: melpa badge --- README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/README.org b/README.org index d9e0b39..815e99f 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,7 @@ #+OPTIONS: toc:nil [[https://ci.codeberg.org/api/badges/martianh/mastodon.el/status.svg]] +https://melpa.org/packages/mastodon-badge.svg * README -- cgit v1.2.3 From d50e1324f5476a7bf84cbf0b8307e6a283cdbb10 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 16:33:31 +0200 Subject: view instance details of post at point's author. --- lisp/mastodon-tl.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 079af22..36a79da 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1357,11 +1357,63 @@ RESPONSE is the JSON returned by the server." (defmacro mastodon-tl--do-if-toot (&rest body) "Execute BODY if we have a toot or user at point." + (declare (debug (symbolp &rest body))) `(if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view (not (mastodon-tl--property 'toot-json))) (message "Looks like there's no toot or user at point?") ,@body)) +(defun mastodon-tl-view-instance-description () + "View the details of the instance the current post's author is on." + (interactive) + (mastodon-tl--do-if-toot + (let* ((toot (mastodon-tl--property 'toot-json)) + (reblog (alist-get 'reblog toot)) + (account (or (alist-get 'account reblog) + (alist-get 'account toot))) + (acct (alist-get 'acct account)) + (username (alist-get 'username account)) + (instance + (concat "https://" + (string-remove-prefix (concat username "@") + acct))) + (response (mastodon-http--get-json + (concat instance + "/api/v1/instance")))) + (when response + (let ((buf (get-buffer-create "*mastodon-preferences*"))) + (with-current-buffer buf + ;; (setq masto-test-inst-json response) + (switch-to-buffer-other-window buf) + (let ((inhibit-read-only t)) + (erase-buffer) + (special-mode) + (mastodon-tl--print-json-keys response) + (goto-char (point-min))))))))) + +(defun mastodon-tl--print-json-keys (response) + "Print the JSON keys and values in RESPONSE." + (while response + (let ((el (pop response))) + (if (equal (type-of (cdr el)) 'cons) + (progn + (setq-local left-margin 4) + (insert + (mastodon-tl--render-text + (format "%-20s: " + (prin1-to-string (car el))) + nil) + "\n") + (indent-to-left-margin) + (mastodon-tl--print-json-keys (cdr el))) + (insert + (mastodon-tl--render-text + (format "%-20s: %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + nil) + "\n"))))) + (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. If NOTIFY is \"true\", enable notifications when that user posts. -- cgit v1.2.3 From 6d3e9cf18a74045e17f8e5c1fc6e20a8c40f497f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 17:03:47 +0200 Subject: cl-reduce for metadata fields format --- lisp/mastodon-profile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 25edfba..aa5ec2e 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -34,6 +34,7 @@ ;;; Code: (require 'seq) +(require 'cl-lib) (autoload 'mastodon-http--api "mastodon-http.el") (autoload 'mastodon-http--get-json "mastodon-http.el") @@ -344,7 +345,8 @@ Returns a list of lists." (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 (car (sort (mapcar 'length car-fields) '>)))) + (left-width (cl-reduce + #'max (mapcar 'length car-fields)))) (mapconcat (lambda (field) (mastodon-tl--render-text (concat -- cgit v1.2.3 From a93ef40dd8700659e84ca48571c24f98e56cfb91 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Sep 2022 18:48:35 +0200 Subject: silence flycheck about 'backend-name' --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index d7efd44..7f867fe 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -661,7 +661,7 @@ The query is matched against a tag search on the server." 'mastodon-toot--tags-company-make-candidate)) (defun mastodon-toot--make-company-backend - (command backend-name str-prefix candidates-fun annot-fun meta-fun + (command _backend-name str-prefix candidates-fun annot-fun meta-fun &optional arg &rest ignored) "Make a company backend for `mastodon-toot-mode'. -- cgit v1.2.3 From 2f0cd109fd98a8039fb52a7ad81a386efd6e208d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 08:32:43 +0200 Subject: make render-text arg TOOT optional --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 36a79da..00a89ba 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -615,7 +615,7 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." 'help-echo (format "You have %s this status." help-string))))) -(defun mastodon-tl--render-text (string toot) +(defun mastodon-tl--render-text (string &optional toot) "Return a propertized text rendering the given HTML string STRING. The contents comes from the given TOOT which is used in parsing -- cgit v1.2.3 From 82aac0a4b33eb54d510bcf19c162213682e1dea8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 09:42:36 +0200 Subject: use # for quoted functions --- lisp/mastodon-profile.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index aa5ec2e..00ffedd 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -344,9 +344,9 @@ Returns a list of lists." (defun mastodon-profile--fields-insert (fields) "Format and insert field pairs (a.k.a profile metadata) in FIELDS." - (let* ((car-fields (mapcar 'car fields)) + (let* ((car-fields (mapcar #'car fields)) (left-width (cl-reduce - #'max (mapcar 'length car-fields)))) + #'max (mapcar #'length car-fields)))) (mapconcat (lambda (field) (mastodon-tl--render-text (concat -- cgit v1.2.3 From dc2813aa84fc8b84a7e9c287eac097bb673e3a21 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 10:40:23 +0200 Subject: fix --do-if-toot debug declare --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 00a89ba..d74f003 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1357,7 +1357,7 @@ RESPONSE is the JSON returned by the server." (defmacro mastodon-tl--do-if-toot (&rest body) "Execute BODY if we have a toot or user at point." - (declare (debug (symbolp &rest body))) + (declare (debug t)) `(if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view (not (mastodon-tl--property 'toot-json))) (message "Looks like there's no toot or user at point?") -- cgit v1.2.3 From 3ec2f7814aa11f860658e4e995ea4f8accc9499a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 08:33:04 +0200 Subject: work on printing instance details more work on printing instance details readme - instance description more more work on printing instance details more more more work on printing instance details --- README.org | 18 ++++--- lisp/mastodon-tl.el | 141 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 122 insertions(+), 37 deletions(-) diff --git a/README.org b/README.org index 815e99f..a2b047a 100644 --- a/README.org +++ b/README.org @@ -99,7 +99,7 @@ restart Emacs and follow the steps again. =M-x mastodon= -Opens a =*mastodon-home*= buffer in the major mode and displays toots. You +Opens a =*mastodon-home*= buffer in the major mode and displays toots. If your credentials are not yet saved, you will be prompted for email and password. The app registration process will take place if your =mastodon-token-file= does not contain =:client_id= and =:client_secret=. @@ -204,6 +204,15 @@ You can download and use your instance's custom emoji | =C-c C-e= | add emoji (if =emojify= installed) | |---------+----------------------------------| +*** Other commands and account settings: + +- =mastodon-tl-view-instance-description=: View information about the instance that the author of the toot at point is on. + +- =mastodon-profile-update-display-name=: Update the display name for your account. +- =mastodon-profile-set-default-toot-visibility=: Set the default visibility for your toots. +- =mastodon-profile-account-locked-toggle=: Toggle the locked status of your account. Locked accounts have to manually approve follow requests. +- =mastodon-profile-account-discoverable-toggle=: Toggle the discoverable status of your account. Non-discoverable accounts are not listed in the profile directory. + *** Customization See =M-x customize-group RET mastodon= to view all customize options. @@ -220,13 +229,6 @@ See =M-x customize-group RET mastodon= to view all customize options. - Completion for mentions and tags - Enable custom emoji -*** Account settings: - -- =mastodon-profile-update-display-name=: Update the display name for your account. -- =mastodon-profile-set-default-toot-visibility=: Set the default visibility for your toots. -- =mastodon-profile-account-locked-toggle=: Toggle the locked status of your account. Locked accounts have to manually approve follow requests. -- =mastodon-profile-account-discoverable-toggle=: Toggle the discoverable status of your account. Non-discoverable accounts are not listed in the profile directory. - *** Live-updating timelines: =mastodon-async-mode= (code taken from https://github.com/alexjgriffith/mastodon-future.el.) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d74f003..7092352 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -34,7 +34,7 @@ (require 'shr) (require 'thingatpt) ; for word-at-point (require 'time-date) -(require 'cl-lib) ; for cl-mapcar +(require 'cl-lib) (require 'mpv nil :no-error) @@ -1363,8 +1363,26 @@ RESPONSE is the JSON returned by the server." (message "Looks like there's no toot or user at point?") ,@body)) -(defun mastodon-tl-view-instance-description () - "View the details of the instance the current post's author is on." +(defun mastodon-tl-view-own-instance (&optional brief) + "View details of your own instance. +BRIEF means show fewer details." + (interactive) + (mastodon-tl-view-instance-description :user brief)) + +(defun mastodon-tl-view-own-instance-brief () + "View brief details of your own instance." + (interactive) + (mastodon-tl-view-instance-description :user :brief)) + +(defun mastodon-tl-view-instance-description-brief () + "View brief details of the instance the current post's author is on." + (interactive) + (mastodon-tl-view-instance-description nil :brief)) + +(defun mastodon-tl-view-instance-description (&optional user brief) + "View the details of the instance the current post's author is on. +USER means to show the instance details for the logged in user. +BRIEF means to show fewer details." (interactive) (mastodon-tl--do-if-toot (let* ((toot (mastodon-tl--property 'toot-json)) @@ -1378,41 +1396,106 @@ RESPONSE is the JSON returned by the server." (string-remove-prefix (concat username "@") acct))) (response (mastodon-http--get-json - (concat instance - "/api/v1/instance")))) + (if user + (mastodon-http--api "instance") + (concat instance + "/api/v1/instance"))))) (when response - (let ((buf (get-buffer-create "*mastodon-preferences*"))) + (let ((buf (get-buffer-create "*mastodon-instance*"))) (with-current-buffer buf - ;; (setq masto-test-inst-json response) (switch-to-buffer-other-window buf) (let ((inhibit-read-only t)) (erase-buffer) (special-mode) + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) (mastodon-tl--print-json-keys response) (goto-char (point-min))))))))) -(defun mastodon-tl--print-json-keys (response) - "Print the JSON keys and values in RESPONSE." - (while response - (let ((el (pop response))) - (if (equal (type-of (cdr el)) 'cons) - (progn - (setq-local left-margin 4) - (insert - (mastodon-tl--render-text - (format "%-20s: " - (prin1-to-string (car el))) - nil) - "\n") - (indent-to-left-margin) - (mastodon-tl--print-json-keys (cdr el))) - (insert - (mastodon-tl--render-text - (format "%-20s: %s" - (prin1-to-string (car el)) - (prin1-to-string (cdr el))) - nil) - "\n"))))) +(defun mastodon-tl--format-key (el pad) + "Format a key of element EL, a cons, with PAD padding." + (format (concat "%-" + (number-to-string pad) + "s: ") + (prin1-to-string (car el)))) + +(defun mastodon-tl--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)) + (pad (1+ (cl-reduce #'max (mapcar #'length cars))))) + (while response + (let ((el (pop response))) + (cond + ;; vector of alists (fields, instance rules): + ((and (equal (type-of (cdr el)) 'vector) + (not (seq-empty-p (cdr el))) + (equal (type-of (seq-elt (cdr el) 0)) 'cons)) + (insert + (mastodon-tl--format-key el pad) + "\n\n") + (seq-do #'mastodon-tl--print-instance-rules-or-fields (cdr el)) + (insert "\n")) + ;; vector of strings (media types): + ((and (equal (type-of (cdr el)) 'vector) + (not (seq-empty-p (cdr el))) + (< 1 (seq-length (cdr el))) + (equal (type-of (seq-elt (cdr el) 0)) 'string)) + (when ind (indent-to ind)) + (insert + (mastodon-tl--format-key el pad) + "\n" + (seq-mapcat + (lambda (x) (concat x ", ")) + (cdr el) 'string) + "\n\n")) + ;; basic nesting: + ((equal (type-of (cdr el)) 'cons) + (when ind (indent-to ind)) + (insert + (mastodon-tl--format-key el pad) + "\n\n") + (mastodon-tl--print-json-keys + (cdr el) (if ind (+ ind 4) 4))) + (t + (when ind (indent-to ind)) + (insert (mastodon-tl--format-key el pad) + " " + (mastodon-tl--newline-if-long el) + (mastodon-tl--render-text + (prin1-to-string (cdr el))) + "\n"))))))) + +(defun mastodon-tl--print-instance-rules-or-fields (alist) + "Print ALIST of instance rules or contact account fields." + (let ((key (if (alist-get 'id alist) 'id 'name)) + (value (if (alist-get 'id alist) 'text 'value))) + (indent-to 4) + (insert (format "%-5s: " + (alist-get key alist)) + (mastodon-tl--newline-if-long (assoc value alist)) + (format "%s" (mastodon-tl--render-text + (alist-get value alist))) + "\n"))) + +(defun mastodon-tl--newline-if-long (el) + "Return a newline string if the cdr of EL is over 50 characters long." + (if (and (sequencep (cdr el)) + (< 50 (length (cdr el)))) + "\n" + "")) (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. -- cgit v1.2.3