diff options
author | Thomas <tschneider.ac@gmail.com> | 2022-12-24 10:32:12 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2022-12-24 10:32:12 +0100 |
commit | 209387820a29c74a480243ed6b496931e25f6c9d (patch) | |
tree | 95b8148593608f7d241863ac9c7d7d010e80fd05 | |
parent | eb9b5d41a3922d73be6c497ec2ba70324ecb291a (diff) |
Fix issue #674 - Fix fail when displaying thread from remote instances
-rw-r--r-- | app/src/main/java/app/fedilab/android/activities/ContextActivity.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/app/src/main/java/app/fedilab/android/activities/ContextActivity.java b/app/src/main/java/app/fedilab/android/activities/ContextActivity.java index 5a87a62de..4f9da9a61 100644 --- a/app/src/main/java/app/fedilab/android/activities/ContextActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ContextActivity.java @@ -34,6 +34,8 @@ import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.preference.PreferenceManager; +import java.net.MalformedURLException; +import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -184,11 +186,18 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon return true; } if (firstMessage.account.acct != null) { - String[] splitAcct = firstMessage.account.acct.split("@"); - String instance; - if (splitAcct.length > 1) { - instance = splitAcct[1]; - } else { + String instance = null; + try { + URL url = new URL(firstMessage.uri); + instance = url.getHost(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + if (instance == null) { + Toasty.info(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show(); + return true; + } + if (instance.equalsIgnoreCase(MainActivity.currentInstance)) { Toasty.info(ContextActivity.this, getString(R.string.toast_on_your_instance), Toasty.LENGTH_SHORT).show(); return true; } @@ -200,11 +209,12 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon } if (remoteId != null) { StatusesVM statusesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class); + String finalInstance = instance; statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> { if (status != null) { Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class); intentContext.putExtra(Helper.ARG_STATUS, status); - intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, instance); + intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, finalInstance); intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intentContext); } else { |