From e08863e6fbd07c53937ec4106ddb4d4716ca7976 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 3 Sep 2022 14:51:22 +0200 Subject: url-lookup: fix loading profile fun: just use the search JSON --- lisp/mastodon.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 13a410b..2dc075a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -295,9 +295,8 @@ not, just browse the URL in the normal fashion." ((not (seq-empty-p (alist-get 'accounts response))) (let* ((accounts (assoc 'accounts response)) - (account (seq-first (cdr accounts))) - (account-acct (alist-get 'acct account))) - (mastodon-profile--show-user account-acct))) + (account (seq-first (cdr accounts)))) + (mastodon-profile--make-author-buffer account))) (t (browse-url query)))))))) -- cgit v1.2.3 From 809a9bd27c9a7c320a3daffa9ea8679442850597 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 3 Sep 2022 16:02:11 +0200 Subject: docstring --- lisp/mastodon.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2dc075a..e7ca3b8 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -269,7 +269,8 @@ If REPLY-JSON is the json of the toot being replied to." ;;;###autoload (defun mastodon-url-lookup (&optional query-url) - "Do a WebFinger lookup for a URL. + "If QUERY-URL resembles a mastodon link, try to load in `mastodon.el'. +Does a WebFinger lookup. URL can be arg QUERY-URL, or URL at point, or provided by the user. If a status or account is found, load it in `mastodon.el', if not, just browse the URL in the normal fashion." -- cgit v1.2.3 From c410a97146c0bf577e68bf21349edd43862b2a0d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 3 Sep 2022 16:45:45 +0200 Subject: fix http-get-retrieves test --- test/mastodon-http-tests.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mastodon-http-tests.el b/test/mastodon-http-tests.el index dc4aa76..57b52a4 100644 --- a/test/mastodon-http-tests.el +++ b/test/mastodon-http-tests.el @@ -53,9 +53,9 @@ Strict-Transport-Security: max-age=31536000 (ert-deftest mastodon-http--get-retrieves-endpoint () "Should make a `url-retrieve' of the given URL." (with-mock - (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz")) + (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz" nil)) (mock (mastodon-auth--access-token) => "test-token") - (mastodon-http--get "https://foo.bar/baz"))) + (mastodon-http--get "https://foo.bar/baz" nil))) (ert-deftest mastodon-http--triage-success () "Should run success function for 200 HTML response." -- cgit v1.2.3 From 4f3884f651618b4f693b5d8334888fcbcc084334 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 3 Sep 2022 18:32:37 +0200 Subject: improve masto-url-p regexes --- lisp/mastodon.el | 62 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e7ca3b8..0c6104f 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -279,43 +279,43 @@ not, just browse the URL in the normal fashion." (url-get-url-at-point) (get-text-property (point) 'shr-url) (read-string "Lookup URL: ")))) - ;; TODO: test for a likely masto link and just browse-url if not - (save-match-data - (if (not (mastodon--masto-url-p query)) - (browse-url query) - (message "Performing lookup...") - (let* ((url (format "%s/api/v2/search" mastodon-instance-url)) - (param (concat "resolve=t")) ; webfinger - (response (mastodon-http--get-search-json url query param :silent))) - (cond ((not (seq-empty-p - (alist-get 'statuses response))) - (let* ((statuses (assoc 'statuses response)) - (status (seq-first (cdr statuses))) - (status-id (alist-get 'id status))) - (mastodon-tl--thread status-id))) - ((not (seq-empty-p - (alist-get 'accounts response))) - (let* ((accounts (assoc 'accounts response)) - (account (seq-first (cdr accounts)))) - (mastodon-profile--make-author-buffer account))) - (t - (browse-url query)))))))) + (if (not (mastodon--masto-url-p query)) + (browse-url query) + (message "Performing lookup...") + (let* ((url (format "%s/api/v2/search" mastodon-instance-url)) + (param (concat "resolve=t")) ; webfinger + (response (mastodon-http--get-search-json url query param :silent))) + (cond ((not (seq-empty-p + (alist-get 'statuses response))) + (let* ((statuses (assoc 'statuses response)) + (status (seq-first (cdr statuses))) + (status-id (alist-get 'id status))) + (mastodon-tl--thread status-id))) + ((not (seq-empty-p + (alist-get 'accounts response))) + (let* ((accounts (assoc 'accounts response)) + (account (seq-first (cdr accounts)))) + (mastodon-profile--make-author-buffer account))) + (t + (browse-url query))))))) (defun mastodon--masto-url-p (query) "Check if QUERY resembles a fediverse URL." - ;; regex test the url: ;; calqued off https://github.com/tuskyapp/Tusky/blob/c8fc2418b8f5458a817bba221d025b822225e130/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt ;; TODO: remove domain and add ^ to regex: ;; (let ((query-path (url-file-nondirectory query))) - (or (string-match "/@" query) - (string-match "/users/[[:alnum:]]+$" query) - (string-match "/notice/[[:alnum:]]+$" query) - (string-match "/objects/[-a-f0-9]+$" query) - (string-match "/notes/[a-z0-9]+$" query) - (string-match "/display/[-a-f0-9]+$" query) - (string-match "/profile/[[:alpha:]]+$" query) - (string-match "/p/[[:alpha:]]+/[[:digit:]]+$" query) - (string-match "/[[:alpha:]]+$" query))) + (let* ((uri-parsed (url-generic-parse-url query)) + (query (url-filename uri-parsed))) + (save-match-data + (or (string-match "^/@[[:alnum:]]+/[[:digit:]]+$" query) + (string-match "^/users/[[:alnum:]]+$" query) + (string-match "^/notice/[[:alnum:]]+$" query) + (string-match "^/objects/[-a-f0-9]+$" query) + (string-match "^/notes/[a-z0-9]+$" query) + (string-match "^/display/[-a-f0-9]+$" query) + (string-match "^/profile/[[:alpha:]]+$" query) + (string-match "^/p/[[:alpha:]]+/[[:digit:]]+$" query) + (string-match "^/[[:alpha:]]+$" query))))) ;;;###autoload (add-hook 'mastodon-mode-hook (lambda () -- cgit v1.2.3 From 3ea9d6882464debcb48048c1a1affcd64bc8b220 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 5 Sep 2022 10:58:23 +0200 Subject: readme badge --- README.org | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 2bd6103..343a761 100644 --- a/README.org +++ b/README.org @@ -1,7 +1,8 @@ #+OPTIONS: toc:nil -[[https://ci.codeberg.org/api/badges/martianh/mastodon.el/status.svg]] -https://melpa.org/packages/mastodon-badge.svg +@@html: MELPA@@ + +@@html: Build Status@@ * README -- cgit v1.2.3