From 8765cdc693eaa7fdc28d0ce4b95efa051c10ebdb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 24 Mar 2023 11:26:08 +0100 Subject: factor out views--get-instance-url --- lisp/mastodon-views.el | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'lisp/mastodon-views.el') 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") -- cgit v1.2.3