From db17df93f0bd3851941d948a8b6dbfed28d57481 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 29 Mar 2025 16:07:53 +0100 Subject: [PATCH] #1160 - Detects acct and intent in URL with scheme web+activitypub --- app/src/main/AndroidManifest.xml | 12 +++ .../android/activities/WebActivityPub.java | 75 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 app/src/main/java/app/fedilab/android/activities/WebActivityPub.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d149753..67606c31 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -449,6 +449,18 @@ android:label="@string/action_cache" android:theme="@style/AppThemeBar" /> + + + + + + + + + + + . */ +import static app.fedilab.android.mastodon.helper.Helper.TAG; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class WebActivityPub extends AppCompatActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent appIntent = getIntent(); + String acct = null; + String intent = null; + if(appIntent == null) { + finish(); + return; + } + Uri uri = appIntent.getData(); + if(uri == null) { + finish(); + return; + } + String host = uri.getHost(); + String path = uri.getPath(); + String query = uri.getQuery(); + + if(path == null || path.isEmpty()) { + finish(); + return; + } + if(query != null) { + String intentPatternString = "intent=(\\w+)"; + final Pattern intentPattern = Pattern.compile(intentPatternString, Pattern.CASE_INSENSITIVE); + Matcher matcherIntent = intentPattern.matcher(query); + while (matcherIntent.find()) { + intent = matcherIntent.group(1); + } + } + if(path.startsWith("/@")) { + String[] params = path.split("@"); + if(params.length == 2) { + acct = params[1] + "@" + host; + } + } else if(path.split("/").length > 2) { + String[] params = path.split("/"); + String root = params[1].toLowerCase(); + if (root.equals("users")) { + acct = params[2] + "@" + host; + } + } + } +}