From a440c4c13460df0188b1863d86bcaeeca8d5f0b2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 2 Oct 2023 15:04:43 +0200 Subject: add misskey notes regex to masto-url-p --- lisp/mastodon.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 0dc6853..2a817ff 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -394,7 +394,8 @@ not, just browse the URL in the normal fashion." (string-match "^/u/[[:alpha:]]+$" query) (string-match "^/c/[[:alnum:]]+$" query) (string-match "^/post/[[:digit:]]+$" query) - (string-match "^/comment/[[:digit:]]+$" query))))) ; lemmy + (string-match "^/comment/[[:digit:]]+$" query) ; lemmy + (string-match "^/notes/[[:alnum:]]+$" query))))) ; misskey post (defun mastodon-live-buffers () "Return a list of open mastodon buffers. -- cgit v1.2.3 From cada9d84d13e0df5eeafa97f00e34c56a46473b8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 2 Oct 2023 15:47:41 +0200 Subject: port fedi-http handling of POST JSON data or not --- lisp/mastodon-http.el | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index ab621a2..cb4c323 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -127,17 +127,20 @@ Used for API form data parameters that take an array." (cl-loop for x in array collect (cons param-str x))) -(defun mastodon-http--post (url &optional params headers unauthenticated-p) +(defun mastodon-http--post (url &optional params headers unauthenticated-p json) "POST synchronously to URL, optionally with PARAMS and HEADERS. Authorization header is included by default unless UNAUTHENTICATED-P is non-nil." (mastodon-http--authorized-request "POST" - (let ((url-request-data (when params - (mastodon-http--build-params-string params))) - (url-request-extra-headers - (append url-request-extra-headers ; auth set in macro - (unless (assoc "Content-Type" headers) ; pleroma compat: - '(("Content-Type" . "application/x-www-form-urlencoded"))) - headers))) + (let* ((url-request-data + (when params + (if json + (json-encode params) + (fedi-http--build-params-string params)))) + (url-request-extra-headers + (append url-request-extra-headers ; auth set in macro + (unless (assoc "Content-Type" headers) ; pleroma compat: + '(("Content-Type" . "application/x-www-form-urlencoded"))) + headers))) (with-temp-buffer (mastodon-http--url-retrieve-synchronously url))) unauthenticated-p)) -- cgit v1.2.3 From db053972021aa75b4bc330843445877149d15b61 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 2 Oct 2023 15:48:03 +0200 Subject: add mastodon-views--instance-desc-misskey. TODO merge with other inst funs partial fix for #468. --- lisp/mastodon-views.el | 74 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index ad36664..5000017 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -755,7 +755,44 @@ INSTANCE is an instance domain name." (concat instance "/api/v1/instance") nil nil :vector))) (mastodon-views--instance-response-fun response brief instance))))) -(defun mastodon-views--instance-response-fun (response brief instance) +(defun mastodon-views--instance-desc-misskey (&optional brief instance) + "" + ;; TODO: work out how to try either misskey endpoint or mastodon-compat one. + (interactive) + (mastodon-tl--do-if-toot + (let* ((toot (if (mastodon-tl--profile-buffer-p) + ;; we may be on profile description itself: + (or (mastodon-tl--property 'profile-json) + ;; or on profile account listings, or just toots: + (mastodon-tl--property 'toot-json)) + ;; normal timeline/account listing: + (mastodon-tl--property 'toot-json))) + (reblog (alist-get 'reblog toot)) + (account (or (alist-get 'account reblog) + (alist-get 'account toot) + toot)) ; else `toot' is already an account listing. + ;; we may be at toots/boosts/users in a profile buffer. + ;; profile-json is a defacto test for if point is on the profile + ;; details at the top of a profile buffer. + (profile-note-p (and (mastodon-tl--profile-buffer-p) + ;; only call this in profile buffers: + (mastodon-tl--property 'profile-json))) + (url (if profile-note-p + (alist-get 'url toot) ; profile description + (alist-get 'url account))) + (username (if profile-note-p + (alist-get 'username toot) ;; profile + (alist-get 'username account))) + (instance (mastodon-views--get-instance-url url username instance)) + (params `(("detail" . ,(or brief t)))) + (headers '(("Content-Type" . "application/json"))) + (url (concat instance "/api/meta")) + (response + (with-current-buffer (mastodon-http--post url params headers t :json) + (mastodon-http--process-response)))) + (mastodon-views--instance-response-fun response brief instance :misskey)))) + +(defun mastodon-views--instance-response-fun (response brief instance misskey) "Display instance description RESPONSE in a new buffer. BRIEF means to show fewer details. INSTANCE is the instance were are working with." @@ -764,21 +801,26 @@ INSTANCE is the instance were are working with." (buf (get-buffer-create (format "*mastodon-instance-%s*" domain)))) (with-mastodon-buffer buf #'special-mode :other-window - (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-views--print-json-keys response) - (mastodon-tl--set-buffer-spec (buffer-name buf) "instance" nil) - (goto-char (point-min)))))) + (if misskey + (let ((inihibit-read-only t)) + (insert (prin1-to-string response)) + (pp-buffer) + (goto-char (point-min))) + (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-views--print-json-keys response) + (mastodon-tl--set-buffer-spec (buffer-name buf) "instance" nil) + (goto-char (point-min))))))) (defun mastodon-views--format-key (el pad) "Format a key of element EL, a cons, with PAD padding." -- cgit v1.2.3 From ce6739f74704590467ab07f84286512eaef5c0bd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 3 Oct 2023 17:14:13 +0200 Subject: instance-response-fun: misskey arg optional --- lisp/mastodon-views.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 5000017..cdddc57 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -792,7 +792,8 @@ INSTANCE is an instance domain name." (mastodon-http--process-response)))) (mastodon-views--instance-response-fun response brief instance :misskey)))) -(defun mastodon-views--instance-response-fun (response brief instance misskey) +(defun mastodon-views--instance-response-fun (response brief instance + &optional misskey) "Display instance description RESPONSE in a new buffer. BRIEF means to show fewer details. INSTANCE is the instance were are working with." -- cgit v1.2.3 From 2d3b3f00a3a8b5555e1ff61b9ababc44a90a4b70 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 3 Oct 2023 18:30:47 +0200 Subject: refactor misskey instance desc. if masto inst err, try misskey --- lisp/mastodon-views.el | 64 ++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index cdddc57..f942729 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -716,7 +716,7 @@ If INSTANCE is given, use that." (string-remove-suffix (concat "/@" username) url)))) -(defun mastodon-views--view-instance-description (&optional user brief instance) +(defun mastodon-views--view-instance-description (&optional user brief instance misskey) "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. @@ -750,47 +750,29 @@ INSTANCE is an instance domain name." (username (if profile-note-p (alist-get 'username toot) ;; profile (alist-get 'username account))) - (instance (mastodon-views--get-instance-url url username instance)) - (response (mastodon-http--get-json - (concat instance "/api/v1/instance") nil nil :vector))) - (mastodon-views--instance-response-fun response brief instance))))) - -(defun mastodon-views--instance-desc-misskey (&optional brief instance) - "" - ;; TODO: work out how to try either misskey endpoint or mastodon-compat one. + (instance (mastodon-views--get-instance-url url username instance))) + (if misskey + (let* ((params `(("detail" . ,(or brief t)))) + (headers '(("Content-Type" . "application/json"))) + (url (concat instance "/api/meta")) + (response + (with-current-buffer (mastodon-http--post url params headers t :json) + (mastodon-http--process-response)))) + (mastodon-views--instance-response-fun response brief instance :misskey)) + (let ((response (mastodon-http--get-json + (concat instance "/api/v1/instance") nil nil :vector))) + ;; if non-misskey attempt errors, try misskey instance: + ;; akkoma i guess should not error here. + (if (eq 'error (caar response)) + (mastodon-views--instance-desc-misskey) + (mastodon-views--instance-response-fun response brief instance)))))))) + +(defun mastodon-views--instance-desc-misskey (&optional user brief instance) + "Show instance description for a misskey/firefish server. +USER, BRIEF, and INSTANCE are all for +`mastodon-views--view-instance-description', which see." (interactive) - (mastodon-tl--do-if-toot - (let* ((toot (if (mastodon-tl--profile-buffer-p) - ;; we may be on profile description itself: - (or (mastodon-tl--property 'profile-json) - ;; or on profile account listings, or just toots: - (mastodon-tl--property 'toot-json)) - ;; normal timeline/account listing: - (mastodon-tl--property 'toot-json))) - (reblog (alist-get 'reblog toot)) - (account (or (alist-get 'account reblog) - (alist-get 'account toot) - toot)) ; else `toot' is already an account listing. - ;; we may be at toots/boosts/users in a profile buffer. - ;; profile-json is a defacto test for if point is on the profile - ;; details at the top of a profile buffer. - (profile-note-p (and (mastodon-tl--profile-buffer-p) - ;; only call this in profile buffers: - (mastodon-tl--property 'profile-json))) - (url (if profile-note-p - (alist-get 'url toot) ; profile description - (alist-get 'url account))) - (username (if profile-note-p - (alist-get 'username toot) ;; profile - (alist-get 'username account))) - (instance (mastodon-views--get-instance-url url username instance)) - (params `(("detail" . ,(or brief t)))) - (headers '(("Content-Type" . "application/json"))) - (url (concat instance "/api/meta")) - (response - (with-current-buffer (mastodon-http--post url params headers t :json) - (mastodon-http--process-response)))) - (mastodon-views--instance-response-fun response brief instance :misskey)))) + (mastodon-views--view-instance-description user brief instance :miskey)) (defun mastodon-views--instance-response-fun (response brief instance &optional misskey) -- cgit v1.2.3 From ccd3015d0846203ec624705356a2e6b9af54a19e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 10:33:23 +0200 Subject: readme --- README.org | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 290caea..e114d26 100644 --- a/README.org +++ b/README.org @@ -452,9 +452,9 @@ PRs, issues, feature requests, and general feedback are very welcome! ** Supporting =mastodon.el= If you'd like to support continued development of =mastodon.el=, I accept -donations via paypal: [[https://paypal.me/martianh][paypal.me/martianh]]. If you would -prefer a different payment method, write to me at that address and I can -provide IBAN or other details. +donations via paypal: [[https://paypal.me/martianh][paypal.me/martianh]]. If you would prefer a different +payment method, please write to me at and I can +provide IBAN or other bank account details. I don't have a tech worker's income, so even a small tip would help out. -- cgit v1.2.3 From f4cd336db111e58f07ad3a0b8a78ad82bcb2a047 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 12:26:04 +0200 Subject: readme re server compat --- README.org | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index e114d26..3d6c087 100644 --- a/README.org +++ b/README.org @@ -415,9 +415,15 @@ Optional dependencies (install yourself, =mastodon.el= can use them): =mastodon.el= should work with ActivityPub servers that implement the Mastodon API. -Apart from Mastodon itself, it is currently known to work with Pleroma and -Gotosocial. If you attempt to use =mastodon.el= with another server that -implements the Mastodon API and run into problems, feel free to open an issue. +Apart from Mastodon itself, it is currently known to work with: +- Pleroma ([[https://pleroma.social/][pleroma.social]]) +- Akkoma ([[https://akkoma.social/][akkoma.social]]) +- Gotosocial ([[https://gotosocial.org/][gotosocial.org]]) + +It does not support the non-Mastodon API servers Misskey ([[https://misskey.io/][misskey.io]]) and Firefish ([[https://joinfirefish.org/][joinfirefish.org]], formerly Calkey), but it should fully support displaying and interacting with posts and users on those platforms. + +If you attempt to use =mastodon.el= with a server and run into problems, feel +free to open an issue. ** Contributing -- cgit v1.2.3 From 10ca848cdd44e2bb04af039f23d17529cc9bda9f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 14:19:05 +0200 Subject: add ELPA badge --- README.org | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 3d6c087..aeefc0e 100644 --- a/README.org +++ b/README.org @@ -2,7 +2,9 @@ #+TEXINFO_DIR_TITLE: Mastodon: (mastodon). #+TEXINFO_DIR_DESC: Client for Mastodon on ActivityPub networks. -@@html: MELPA@@ +@@html: ELPA@@ + +@@html: MELPA@@ @@html: Build Status@@ -- cgit v1.2.3 From 3cd233610acf4cfebc5c25aa62d243dac3605ff5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 14:20:06 +0200 Subject: comment CI badge (defunct) --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index aeefc0e..1ea0aec 100644 --- a/README.org +++ b/README.org @@ -6,7 +6,7 @@ @@html: MELPA@@ -@@html: Build Status@@ +# @@html: Build Status@@ * README -- cgit v1.2.3 From 63f55bb016865b88f7df295e9d50a9e64403a474 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 16:11:51 +0200 Subject: refactor mode function, to avoid multiple addition of lambda. --- lisp/mastodon.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2a817ff..94189cd 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -420,14 +420,17 @@ Calls `mastodon-tl--get-buffer-type', which see." buf-names))) (switch-to-buffer choice))) +(defun mastodon-mode-hook-fun () + "Function to add to `mastodon-mode-hook'." + (when (require 'emojify nil :noerror) + (emojify-mode t) + (when mastodon-toot--enable-custom-instance-emoji + (mastodon-toot--enable-custom-emoji)) + (when mastodon-tl--highlight-current-toot + (cursor-face-highlight-mode)))) ; 29.1 + ;;;###autoload -(add-hook 'mastodon-mode-hook (lambda () - (when (require 'emojify nil :noerror) - (emojify-mode t) - (when mastodon-toot--enable-custom-instance-emoji - (mastodon-toot--enable-custom-emoji)) - (when mastodon-tl--highlight-current-toot - (cursor-face-highlight-mode))))) ; 29.1 +(add-hook 'mastodon-mode-hook #'mastodon-mode-hook-fun) ;;;###autoload (add-hook 'mastodon-mode-hook #'mastodon-profile--fetch-server-account-settings) -- cgit v1.2.3 From 0aa39f5f1451b7eb58954516a9b2a8b9be6dc16a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 4 Oct 2023 16:23:54 +0200 Subject: mastodon-toot--enable-custom-emoji: performance improvement. --- lisp/mastodon-toot.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a8c85d8..f7d4f18 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -758,12 +758,17 @@ to `emojify-user-emojis', and the emoji data is updated." (when (y-or-n-p "Looks like you haven't downloaded your instance's custom emoji yet. Download now? ") (mastodon-toot--download-custom-emoji))) - (setq emojify-user-emojis - (append (mastodon-toot--collect-custom-emoji) - emojify-user-emojis)) - ;; if already loaded, reload - (when (featurep 'emojify) - (emojify-set-emoji-data))) + ;; FIXME this test is awful, only works if we were last to mod the list: + (unless (equal (car (mastodon-toot--collect-custom-emoji)) + (car emojify-user-emojis)) + (setq emojify-user-emojis + (append (mastodon-toot--collect-custom-emoji) + emojify-user-emojis)) + ;; if already loaded, reload + (when (featurep 'emojify) + ;; we now only do this within the unless test above, as it is extremely + ;; slow and runs in `mastodon-mode-hook'. + (emojify-set-emoji-data)))) (defun mastodon-toot--remove-docs () "Get the body of a toot from the current compose buffer." -- cgit v1.2.3 From 98333a0f21f394acd4cb774b7d5e92430faf06f3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 5 Oct 2023 10:22:48 +0200 Subject: remove lambda from masto-toot hook --- lisp/mastodon-toot.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f7d4f18..4c55412 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1779,19 +1779,20 @@ Only text that is not one of these faces will be spell-checked." (let ((f (get-text-property (1- (point)) 'face))) (not (memq f faces)))))) -(add-hook 'mastodon-toot-mode-hook - (lambda () - (setq flyspell-generic-check-word-predicate - #'mastodon-toot-mode-flyspell-verify))) +(defun mastodon-toot-mode-hook-fun () + "Function for code to run in `mastodon-toot-mode-hook'." + ;; disable auto-fill-mode: + (auto-fill-mode -1) + ;; add flyspell predicate function: + (setq flyspell-generic-check-word-predicate + #'mastodon-toot-mode-flyspell-verify)) + +(add-hook 'mastodon-toot-mode-hook #'mastodon-toot-mode-hook-fun) ;;;###autoload (add-hook 'mastodon-toot-mode-hook #'mastodon-profile--fetch-server-account-settings-maybe) -;; disable auto-fill-mode: -(add-hook 'mastodon-toot-mode-hook - (lambda () - (auto-fill-mode -1))) (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." -- cgit v1.2.3 From 1964ee8ad6a0cd91a149a11925e1bcd94c83c072 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 5 Oct 2023 10:54:23 +0200 Subject: bump version --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 94189cd..1ad1b5d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -6,7 +6,7 @@ ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -;; Version: 1.0.2 +;; Version: 1.0.3 ;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) ;; Homepage: https://codeberg.org/martianh/mastodon.el -- cgit v1.2.3