diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-03-24 11:26:08 +0100 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-03-24 11:26:08 +0100 |
commit | 8765cdc693eaa7fdc28d0ce4b95efa051c10ebdb (patch) | |
tree | 95aac39497865af5e91b552fe8f9cf700cca7231 /lisp/mastodon-views.el | |
parent | 63814ce94f6d3f2fe3ace8aaf34b1a21a2183e99 (diff) |
factor out views--get-instance-url
Diffstat (limited to 'lisp/mastodon-views.el')
-rw-r--r-- | lisp/mastodon-views.el | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index affd899..74a3353 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -718,6 +718,25 @@ BRIEF means show fewer details." (interactive) (mastodon-views--view-instance-description nil :brief)) +(defun mastodon-views--get-instance-url (url username &optional instance) + "Return an instance base url from a user account URL. +USERNAME is the name to cull. +If INSTANCE is given, use that." + (cond (instance + (concat "https://" instance)) + ;; pleroma URL is https://instance.com/users/username + ((string-suffix-p "users/" (url-basepath url)) + (string-remove-suffix "/users/" + (url-basepath url))) + ;; friendica is https://instance.com/profile/user + ((string-suffix-p "profile/" (url-basepath url)) + (string-remove-suffix "/profile/" + (url-basepath url))) + ;; mastodon is https://instance.com/@user + (t + (string-remove-suffix (concat "/@" username) + url)))) + (defun mastodon-views--view-instance-description (&optional user brief instance) "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. @@ -754,20 +773,7 @@ INSTANCE is an instance domain name." (username (if (mastodon-tl--property 'profile-json) (alist-get 'username toot) ;; profile (alist-get 'username account))) - (instance (cond (instance - (concat "https://" instance)) - ;; pleroma URL is https://instance.com/users/username - ((string-suffix-p "users/" (url-basepath url)) - (string-remove-suffix "/users/" - (url-basepath url))) - ;; friendica is https://instance.com/profile/user - ((string-suffix-p "profile/" (url-basepath url)) - (string-remove-suffix "/profile/" - (url-basepath url))) - ;; mastodon: - (t - (string-remove-suffix (concat "/@" username) - url)))) + (instance (mastodon-views--get-instance-url url username instance)) (response (mastodon-http--get-json (if user (mastodon-http--api "instance") |