discord-jadx/app/src/main/java/com/discord/stores/StoreMaskedLinks.java

155 lines
6.6 KiB
Java

package com.discord.stores;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import androidx.annotation.VisibleForTesting;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.models.domain.ModelUserRelationship;
import com.discord.models.user.User;
import d0.t.n;
import d0.t.n0;
import d0.t.u;
import d0.z.d.m;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.text.Regex;
/* compiled from: StoreMaskedLinks.kt */
public final class StoreMaskedLinks extends StoreV2 {
public static final Companion Companion;
private static final Regex DISCORD_DOMAINS_REGEX = new Regex("(?:^|\\.)(?:discordapp|discord)\\.com$");
private static final String HOST_SPOTIFY = "https://spotify.com";
private static final String HOST_SPOTIFY_OPEN = "https://open.spotify.com";
private static final List<String> TRUSTED_DOMAINS;
private static final String USER_TRUSTED_DOMAINS_CACHE_KEY = "USER_TRUSTED_DOMAINS_CACHE_KEY";
private final Dispatcher dispatcher;
private final StoreChannelsSelected storeChannelsSelected;
private final StoreUserRelationships storeUserRelationships;
private Set<String> userTrustedDomains = new LinkedHashSet();
private Set<String> userTrustedDomainsSnapshot = n0.emptySet();
/* compiled from: StoreMaskedLinks.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ String access$getDomainName(Companion companion, String str) {
return companion.getDomainName(str);
}
private final String getDomainName(String str) {
try {
Uri parse = Uri.parse(str);
m.checkNotNullExpressionValue(parse, "Uri.parse(url)");
return parse.getHost();
} catch (Exception unused) {
return null;
}
}
@VisibleForTesting
public final boolean isImplicitlyTrustedDomain$app_productionBetaRelease(String str) {
m.checkNotNullParameter(str, "name");
return StoreMaskedLinks.access$getTRUSTED_DOMAINS$cp().contains(str) || StoreMaskedLinks.access$getDISCORD_DOMAINS_REGEX$cp().containsMatchIn(str);
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
TRUSTED_DOMAINS = n.listOfNotNull((Object[]) new String[]{Companion.access$getDomainName(companion, "https://discord.com"), Companion.access$getDomainName(companion, "https://discordapp.com"), Companion.access$getDomainName(companion, "https://cdn.discordapp.com"), Companion.access$getDomainName(companion, "https://discord.gift"), Companion.access$getDomainName(companion, "https://discord.gg"), Companion.access$getDomainName(companion, "https://discord.new"), Companion.access$getDomainName(companion, "https://spotify.com"), Companion.access$getDomainName(companion, "https://open.spotify.com")});
}
public StoreMaskedLinks(Dispatcher dispatcher, StoreChannelsSelected storeChannelsSelected, StoreUserRelationships storeUserRelationships) {
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(storeChannelsSelected, "storeChannelsSelected");
m.checkNotNullParameter(storeUserRelationships, "storeUserRelationships");
this.dispatcher = dispatcher;
this.storeChannelsSelected = storeChannelsSelected;
this.storeUserRelationships = storeUserRelationships;
}
public static final /* synthetic */ Regex access$getDISCORD_DOMAINS_REGEX$cp() {
return DISCORD_DOMAINS_REGEX;
}
public static final /* synthetic */ List access$getTRUSTED_DOMAINS$cp() {
return TRUSTED_DOMAINS;
}
public static final /* synthetic */ Set access$getUserTrustedDomains$p(StoreMaskedLinks storeMaskedLinks) {
return storeMaskedLinks.userTrustedDomains;
}
public static final /* synthetic */ void access$setUserTrustedDomains$p(StoreMaskedLinks storeMaskedLinks, Set set) {
storeMaskedLinks.userTrustedDomains = set;
}
private final boolean isTrustedDomain(String str) {
Companion companion = Companion;
String access$getDomainName = Companion.access$getDomainName(companion, str);
return u.contains(this.userTrustedDomainsSnapshot, access$getDomainName) || (access$getDomainName != null && companion.isImplicitlyTrustedDomain$app_productionBetaRelease(access$getDomainName));
}
public final Set<String> getUserTrustedDomains() {
return this.userTrustedDomainsSnapshot;
}
@Override // com.discord.stores.Store
@StoreThread
public void init(Context context) {
m.checkNotNullParameter(context, "context");
super.init(context);
Set<String> stringSet = getPrefs().getStringSet("USER_TRUSTED_DOMAINS_CACHE_KEY", n0.emptySet());
if (stringSet == null) {
stringSet = new LinkedHashSet<>();
}
this.userTrustedDomains = new HashSet(stringSet);
markChanged();
}
public final boolean isTrustedDomain(String str, String str2) {
m.checkNotNullParameter(str, "url");
if (isTrustedDomain(str)) {
return true;
}
boolean z2 = str2 == null || m.areEqual(str2, str);
Channel selectedChannel = this.storeChannelsSelected.getSelectedChannel();
Long l = null;
User v0 = selectedChannel != null ? AnimatableValueParser.v0(selectedChannel) : null;
Map<Long, Integer> relationships = this.storeUserRelationships.getRelationships();
if (v0 != null) {
l = Long.valueOf(v0.getId());
}
if (!ModelUserRelationship.isType(relationships.get(l), 1)) {
return false;
}
return z2;
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData() {
super.snapshotData();
this.userTrustedDomainsSnapshot = new HashSet(this.userTrustedDomains);
SharedPreferences.Editor edit = getPrefs().edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putStringSet("USER_TRUSTED_DOMAINS_CACHE_KEY", this.userTrustedDomainsSnapshot);
edit.apply();
}
public final void trustDomain(String str) {
m.checkNotNullParameter(str, "url");
this.dispatcher.schedule(new StoreMaskedLinks$trustDomain$1(this, str));
}
}