diff options
-rw-r--r-- | lisp/mastodon.el | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 93b24b3..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 () |