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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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(-) (limited to 'lisp') 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