package com.discord.utilities.intent; import android.content.Context; import android.content.Intent; import android.net.Uri; import c.a.d.r0.b; import c.i.c.c; import c.i.c.k.c.a; import com.airbnb.lottie.parser.AnimatableValueParser; import com.discord.app.AppLog; import com.discord.stores.StoreStream; import com.discord.utilities.intent.RouteHandlers; import com.discord.utilities.logging.Logger; import com.google.firebase.appindexing.internal.zza; import com.google.firebase.appindexing.internal.zzc; import d0.g0.i; import d0.g0.s; import d0.g0.t; import d0.o; import d0.t.h0; import d0.z.d.m; import java.lang.ref.WeakReference; import java.util.Locale; import java.util.Map; import java.util.Objects; import kotlin.Unit; import kotlin.jvm.functions.Function2; import kotlin.jvm.functions.Function3; import kotlin.text.MatchResult; import kotlin.text.Regex; /* compiled from: IntentUtils.kt */ public final class IntentUtils { public static final IntentUtils INSTANCE = new IntentUtils(); private static final Map> pathRouterMap; /* compiled from: IntentUtils.kt */ public static final class RouteBuilders { public static final RouteBuilders INSTANCE = new RouteBuilders(); /* compiled from: IntentUtils.kt */ public static final class SDK { public static final SDK INSTANCE = new SDK(); private SDK() { } public static final Intent join(String str, long j, String str2) { m.checkNotNullParameter(str, "deeplink"); return new Intent("com.discord.intent.action.SDK", Uri.parse(str).buildUpon().appendPath("join").appendQueryParameter("application_id", String.valueOf(j)).appendQueryParameter("secret", str2).build()); } } /* compiled from: IntentUtils.kt */ public static final class Uris { public static final Uris INSTANCE = new Uris(); private Uris() { } public final Uri getApp() { Uri parse = Uri.parse("discord://app"); m.checkNotNullExpressionValue(parse, "Uri.parse(\"discord://app\")"); return parse; } public final Uri getOauth2Authorize() { Uri parse = Uri.parse("discord://action/oauth2/authorize"); m.checkNotNullExpressionValue(parse, "Uri.parse(\"discord://action/oauth2/authorize\")"); return parse; } public final Uri getSelectSettingsVoice() { Uri parse = Uri.parse("discord://app/settings/voice"); m.checkNotNullExpressionValue(parse, "Uri.parse(\"discord://app/settings/voice\")"); return parse; } } private RouteBuilders() { } /* JADX DEBUG: Failed to insert an additional move for type inference into block B:6:0x0014 */ /* JADX WARN: Multi-variable type inference failed */ public static final Intent selectChannel(long j, long j2, Long l) { String valueOf = (j2 == 0 || j2 == -1) ? "@me" : Long.valueOf(j2); if (l == 0) { l = ""; } return new Intent("android.intent.action.VIEW", Uri.parse("discord://app/channels/" + valueOf + '/' + j + '/' + l)); } public static /* synthetic */ Intent selectChannel$default(long j, long j2, Long l, int i, Object obj) { if ((i & 2) != 0) { j2 = 0; } if ((i & 4) != 0) { l = null; } return selectChannel(j, j2, l); } public static final Intent selectUserProfile(long j) { return new Intent("android.intent.action.VIEW", Uri.parse("discord://app/users/" + j)); } public final Intent connectVoice(long j) { return new Intent("com.discord.intent.action.CONNECT", Uri.parse("discord://app/connect/" + j)); } public final Intent selectDirectMessage(long j) { return new Intent("android.intent.action.VIEW", Uri.parse("discord://app/channels/@me/user/" + j)); } public final Intent selectGuildTemplate(String str, String str2) { Uri parse = Uri.parse(str); m.checkNotNullExpressionValue(parse, "uri"); if (parse.getScheme() == null) { if (str != null) { b bVar = b.F; if (t.startsWith$default(str, b.e, false, 2, null)) { parse = Uri.parse("https://" + str); } } parse = Uri.parse("discord://app/template/" + str + "?source=" + str2); } Intent data = new Intent().setData(parse); m.checkNotNullExpressionValue(data, "Intent().setData(uriMerged)"); return data; } public final Intent selectInvite(String str, String str2) { Uri parse = Uri.parse(str); m.checkNotNullExpressionValue(parse, "uri"); if (parse.getScheme() == null) { if (str != null) { b bVar = b.F; if (t.startsWith$default(str, b.d, false, 2, null)) { parse = Uri.parse("https://" + str); } } parse = Uri.parse("discord://app/invite/" + str + "?source=" + str2); } Intent data = new Intent().setData(parse); m.checkNotNullExpressionValue(data, "Intent().setData(uriMerged)"); return data; } } static { b bVar = b.F; Regex regex = b.u; RouteHandlers routeHandlers = RouteHandlers.INSTANCE; pathRouterMap = h0.mapOf(o.to(b.t, IntentUtils$pathRouterMap$1.INSTANCE), o.to(regex, new IntentUtils$pathRouterMap$2(routeHandlers)), o.to(b.w, new IntentUtils$pathRouterMap$3(routeHandlers)), o.to(b.f48x, new IntentUtils$pathRouterMap$4(routeHandlers)), o.to(b.f50z, new IntentUtils$pathRouterMap$5(routeHandlers)), o.to(b.f49y, new IntentUtils$pathRouterMap$6(routeHandlers)), o.to(b.A, new IntentUtils$pathRouterMap$7(routeHandlers)), o.to(b.f47s, new IntentUtils$pathRouterMap$8(routeHandlers)), o.to(b.v, new IntentUtils$pathRouterMap$9(routeHandlers)), o.to(b.C, new IntentUtils$pathRouterMap$10(routeHandlers)), o.to(b.D, new IntentUtils$pathRouterMap$11(routeHandlers)), o.to(b.E, new IntentUtils$pathRouterMap$12(routeHandlers)), o.to(b.B, new IntentUtils$pathRouterMap$13(routeHandlers)), o.to(b.m, new IntentUtils$pathRouterMap$14(routeHandlers))); } private IntentUtils() { } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.utilities.intent.IntentUtils */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ boolean consumeRoutingIntent$default(IntentUtils intentUtils, Intent intent, Context context, Function2 function2, int i, Object obj) { if ((i & 4) != 0) { function2 = IntentUtils$consumeRoutingIntent$1.INSTANCE; } return intentUtils.consumeRoutingIntent(intent, context, function2); } private final Uri externalize(Uri uri) { Uri.Builder scheme = uri.buildUpon().scheme("https"); b bVar = b.F; return scheme.authority(b.a).build(); } private final boolean isHttpDomainUrl(Uri uri) { Regex regex = new Regex("https?", i.IGNORE_CASE); String scheme = uri.getScheme(); if (scheme == null) { scheme = ""; } m.checkNotNullExpressionValue(scheme, "uri.scheme ?: \"\""); if (regex.matches(scheme)) { return b.F.a(uri.getHost()); } return false; } private final void notifyFirebaseUserActionStatus(Intent intent, boolean z2) { String stringExtra = intent.getStringExtra("actions.fulfillment.extra.ACTION_TOKEN"); if (stringExtra != null) { m.checkNotNullExpressionValue(stringExtra, "intent.getStringExtra(In…A_VOICE_ACTION) ?: return"); String str = z2 ? "http://schema.org/CompletedActionStatus" : "http://schema.org/FailedActionStatus"; a aVar = new a(); aVar.f = stringExtra; aVar.e = str; AnimatableValueParser.z(stringExtra, "setActionToken is required before calling build()."); AnimatableValueParser.z(new String(aVar.e), "setActionStatus is required before calling build()."); aVar.a("actionToken", aVar.f); c.i.c.k.b bVar = null; if ((aVar.f1279c == null ? null : new String(aVar.f1279c)) == null) { aVar.f1279c = "AssistAction"; aVar.a("name", "AssistAction"); } if ((aVar.d == null ? null : new String(aVar.d)) == null) { String valueOf = String.valueOf(aVar.f); String concat = valueOf.length() != 0 ? "https://developers.google.com/actions?invocation=".concat(valueOf) : new String("https://developers.google.com/actions?invocation="); Objects.requireNonNull(concat, "null reference"); aVar.d = concat; aVar.a("url", concat); } AnimatableValueParser.z(aVar.f1279c, "setObject is required before calling build()."); AnimatableValueParser.z(aVar.d, "setObject is required before calling build()."); zza zza = new zza(aVar.b, aVar.f1279c, aVar.d, null, new zzc(true), aVar.e, aVar.a); synchronized (c.i.c.k.b.class) { WeakReference weakReference = c.i.c.k.b.a; if (weakReference != null) { bVar = weakReference.get(); } if (bVar == null) { c b = c.b(); b.a(); bVar = new c.i.c.k.d.b(b.d); c.i.c.k.b.a = new WeakReference<>(bVar); } } bVar.a(zza); } } public static final void performChooserSendIntent(Context context, String str) { performChooserSendIntent$default(context, str, null, 4, null); } public static final void performChooserSendIntent(Context context, String str, CharSequence charSequence) { m.checkNotNullParameter(context, "context"); m.checkNotNullParameter(str, "text"); m.checkNotNullParameter(charSequence, "chooserText"); context.startActivity(Intent.createChooser(INSTANCE.sendText(new Intent("android.intent.action.SEND"), str), charSequence)); } public static /* synthetic */ void performChooserSendIntent$default(Context context, String str, CharSequence charSequence, int i, Object obj) { if ((i & 4) != 0) { charSequence = context.getString(2131893317); m.checkNotNullExpressionValue(charSequence, "context.getString(R.string.share)"); } performChooserSendIntent(context, str, charSequence); } private final Intent sendText(Intent intent, String str) { intent.setAction("android.intent.action.SEND"); intent.setType("text/plain"); if (str == null) { str = ""; } intent.putExtra("android.intent.extra.TEXT", str); return intent; } public final boolean consumeExternalRoutingIntent(Intent intent, Context context) { m.checkNotNullParameter(intent, "intent"); m.checkNotNullParameter(context, "context"); StoreStream.Companion.getDynamicLinkCache().storeLinkIfExists(intent, context); return consumeRoutingIntent(intent, context, new IntentUtils$consumeExternalRoutingIntent$1(intent)); } public final boolean consumeRoutingIntent(Intent intent, Context context, Function2 function2) { MatchResult matchResult; RouteHandlers.AnalyticsMetadata analyticsMetadata; m.checkNotNullParameter(intent, "intent"); m.checkNotNullParameter(context, "context"); m.checkNotNullParameter(function2, "callback"); Uri data = intent.getData(); if (data == null) { data = Uri.EMPTY; } m.checkNotNullExpressionValue(data, "uri"); boolean z2 = isDiscordAppUri(data) || isHttpDomainUrl(data); function2.invoke(data, Boolean.valueOf(z2)); if (z2) { AppLog appLog = AppLog.g; String simpleName = IntentUtils.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName, "javaClass.simpleName"); String uri = data.toString(); if (uri == null) { uri = ""; } m.checkNotNullExpressionValue(uri, "uri?.toString() ?: \"\""); appLog.f(simpleName, uri); for (Map.Entry> entry : pathRouterMap.entrySet()) { Regex key = entry.getKey(); Function3 value = entry.getValue(); String path = data.getPath(); if (path != null) { m.checkNotNullExpressionValue(path, "it"); matchResult = key.matchEntire(path); continue; } else { matchResult = null; continue; } if (matchResult != null) { try { analyticsMetadata = value.invoke(data, matchResult, context); } catch (Exception unused) { analyticsMetadata = RouteHandlers.AnalyticsMetadata.Companion.getUNKNOWN(); } intent.setData(Uri.EMPTY); boolean z3 = !m.areEqual(analyticsMetadata, RouteHandlers.AnalyticsMetadata.Companion.getUNKNOWN()); Logger.d$default(AppLog.g, "Intent handler activated for " + data + ", consumed: " + z3, null, 2, null); notifyFirebaseUserActionStatus(intent, z3); StoreStream.Companion.getAnalytics().deepLinkReceived(intent, analyticsMetadata); return z3; } } } notifyFirebaseUserActionStatus(intent, false); return false; } public final Long getDirectShareId(Intent intent) { m.checkNotNullParameter(intent, "$this$getDirectShareId"); String stringExtra = intent.getStringExtra("android.intent.extra.shortcut.ID"); if (stringExtra != null) { return s.toLongOrNull(stringExtra); } return null; } public final boolean isDiscordAppUri(Uri uri) { String str; int hashCode; m.checkNotNullParameter(uri, "uri"); if (t.equals(uri.getScheme(), "discord", true)) { String host = uri.getHost(); if (host != null) { Locale locale = Locale.ENGLISH; m.checkNotNullExpressionValue(locale, "Locale.ENGLISH"); str = host.toLowerCase(locale); m.checkNotNullExpressionValue(str, "(this as java.lang.String).toLowerCase(locale)"); } else { str = null; } if (str != null && ((hashCode = str.hashCode()) == -1422950858 ? str.equals("action") : !(hashCode != 96801 || !str.equals("app")))) { return true; } } return false; } public final Intent toExternalizedSend(Intent intent) { Uri uri; m.checkNotNullParameter(intent, "$this$toExternalizedSend"); Uri data = intent.getData(); if (data == null || (uri = INSTANCE.externalize(data)) == null) { uri = Uri.EMPTY; } intent.setData(uri); IntentUtils intentUtils = INSTANCE; Uri data2 = intent.getData(); intentUtils.sendText(intent, data2 != null ? data2.toString() : null); return intent; } }