From 0702703d78a0e619b976ba95d0f3f2cc475a8962 Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 1 Jun 2023 19:13:03 +0200 Subject: [PATCH] normalize instance uri --- .../joinmastodon/android/api/session/AccountSession.java | 2 +- .../fragments/onboarding/InstanceRulesFragment.java | 7 +------ .../main/java/org/joinmastodon/android/model/Instance.java | 7 +++++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java index f8b201bda..30acb30d6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java @@ -99,7 +99,7 @@ public class AccountSession{ public Uri getInstanceUri() { return new Uri.Builder() .scheme("https") - .authority(getInstance().map(i -> i.uri).orElse(domain)) + .authority(getInstance().map(i -> i.normalizedUri).orElse(domain)) .build(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java index 42583c5ef..c8efd7f80 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java @@ -50,7 +50,6 @@ public class InstanceRulesFragment extends ToolbarFragment implements ProvidesAs private ElevationOnScrollListener onScrollListener; private static final int RULES_REQUEST=376; - private String domain; @Override public void onCreate(Bundle savedInstanceState){ @@ -63,10 +62,6 @@ public class InstanceRulesFragment extends ToolbarFragment implements ProvidesAs super.onAttach(activity); setNavigationBarColor(UiUtils.getThemeColor(activity, R.attr.colorWindowBackground)); instance=Parcels.unwrap(getArguments().getParcelable("instance")); - // akkoma says uri is "https://example.social" while just "example.social" on mastodon - domain = instance.uri - .replaceFirst("^https://", "") - .replaceFirst("/$", ""); setTitle(R.string.instance_rules_title); } @@ -142,7 +137,7 @@ public class InstanceRulesFragment extends ToolbarFragment implements ProvidesAs public void onProvideAssistContent(AssistContent assistContent) { assistContent.setWebUri(new Uri.Builder() .scheme("https") - .authority(domain) + .authority(instance.normalizedUri) .path("/about") .build()); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java index cd8e94d99..5ceaeb72e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java @@ -88,6 +88,9 @@ public class Instance extends BaseModel{ public PleromaPollLimits pollLimits; + /** like uri, but always without scheme and trailing slash */ + public transient String normalizedUri; + @Override public void postprocess() throws ObjectValidationException{ super.postprocess(); @@ -97,6 +100,10 @@ public class Instance extends BaseModel{ rules=Collections.emptyList(); if(shortDescription==null) shortDescription=""; + // akkoma says uri is "https://example.social" while just "example.social" on mastodon + normalizedUri = uri + .replaceFirst("^https://", "") + .replaceFirst("/$", ""); } @Override