145 lines
5.9 KiB
Java
145 lines
5.9 KiB
Java
package com.discord.stores;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.net.Uri;
|
|
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;
|
|
/* compiled from: StoreMaskedLinks.kt */
|
|
public final class StoreMaskedLinks extends StoreV2 {
|
|
private static final Companion Companion;
|
|
@Deprecated
|
|
private static final String HOST_SPOTIFY = "https://spotify.com";
|
|
@Deprecated
|
|
private static final String HOST_SPOTIFY_OPEN = "https://open.spotify.com";
|
|
@Deprecated
|
|
private static final List<String> TRUSTED_DOMAINS;
|
|
@Deprecated
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
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 */ Companion access$Companion() {
|
|
return Companion;
|
|
}
|
|
|
|
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) {
|
|
String access$getDomainName = Companion.access$getDomainName(Companion, str);
|
|
return u.contains(TRUSTED_DOMAINS, access$getDomainName) || u.contains(this.userTrustedDomainsSnapshot, 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));
|
|
}
|
|
}
|