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

149 lines
6.8 KiB
Java

package com.discord.stores;
import c0.g0.w;
import c0.t.h0;
import c0.t.n;
import c0.t.o;
import c0.z.d.m;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.applicationcommands.ApplicationCommandFrecencyTracker;
import com.discord.utilities.frecency.FrecencyTracker;
import com.discord.utilities.persister.Persister;
import com.discord.widgets.chat.input.MentionUtilsKt;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreApplicationCommandFrecency.kt */
public final class StoreApplicationCommandFrecency extends StoreV2 {
private final Dispatcher dispatcher;
private final ApplicationCommandFrecencyTracker frecency;
private final Persister<ApplicationCommandFrecencyTracker> frecencyCache;
private final ObservationDeck observationDeck;
private Map<Long, List<String>> topCommandIds;
private Map<Long, ? extends List<String>> topCommandIdsSnapshot;
public StoreApplicationCommandFrecency(Dispatcher dispatcher, ObservationDeck observationDeck) {
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(observationDeck, "observationDeck");
this.dispatcher = dispatcher;
this.observationDeck = observationDeck;
Persister<ApplicationCommandFrecencyTracker> persister = new Persister<>("CACHE_KEY_APPLICATION_COMMANDS", new ApplicationCommandFrecencyTracker(0, 0, 3, null));
this.frecencyCache = persister;
this.frecency = persister.get();
this.topCommandIds = new LinkedHashMap();
this.topCommandIdsSnapshot = h0.emptyMap();
populateStore();
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreApplicationCommandFrecency(Dispatcher dispatcher, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck);
}
public static final /* synthetic */ List access$getAllTopCommandIds(StoreApplicationCommandFrecency storeApplicationCommandFrecency, Long l) {
return storeApplicationCommandFrecency.getAllTopCommandIds(l);
}
public static final /* synthetic */ ApplicationCommandFrecencyTracker access$getFrecency$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency) {
return storeApplicationCommandFrecency.frecency;
}
public static final /* synthetic */ Persister access$getFrecencyCache$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency) {
return storeApplicationCommandFrecency.frecencyCache;
}
public static final /* synthetic */ String access$getKey(StoreApplicationCommandFrecency storeApplicationCommandFrecency, Long l, String str) {
return storeApplicationCommandFrecency.getKey(l, str);
}
public static final /* synthetic */ Map access$getTopCommandIds$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency) {
return storeApplicationCommandFrecency.topCommandIds;
}
public static final /* synthetic */ Map access$getTopCommandIdsSnapshot$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency) {
return storeApplicationCommandFrecency.topCommandIdsSnapshot;
}
public static final /* synthetic */ void access$setTopCommandIds$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency, Map map) {
storeApplicationCommandFrecency.topCommandIds = map;
}
public static final /* synthetic */ void access$setTopCommandIdsSnapshot$p(StoreApplicationCommandFrecency storeApplicationCommandFrecency, Map map) {
storeApplicationCommandFrecency.topCommandIdsSnapshot = map;
}
private final List<String> getAllTopCommandIds(Long l) {
Collection sortedKeys$default = FrecencyTracker.getSortedKeys$default(this.frecency, 0, 1, null);
ArrayList<String> arrayList = new ArrayList();
Iterator it = sortedKeys$default.iterator();
while (true) {
boolean z2 = false;
if (!it.hasNext()) {
break;
}
Object next = it.next();
String str = (String) next;
if (l == null) {
z2 = !w.contains$default((CharSequence) str, (CharSequence) ":", false, 2, (Object) null);
} else if (w.contains$default((CharSequence) str, (CharSequence) ":", false, 2, (Object) null)) {
z2 = m.areEqual((String) w.split$default((CharSequence) str, new String[]{":"}, false, 0, 6, (Object) null).get(1), String.valueOf(l.longValue()));
}
if (z2) {
arrayList.add(next);
}
}
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(arrayList, 10));
for (String str2 : arrayList) {
if (w.contains$default((CharSequence) str2, (CharSequence) ":", false, 2, (Object) null)) {
str2 = (String) w.split$default((CharSequence) str2, new String[]{":"}, false, 0, 6, (Object) null).get(0);
}
arrayList2.add(str2);
}
return arrayList2;
}
private final String getKey(Long l, String str) {
if (l == null) {
return str;
}
return str + MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR + l;
}
public final List<String> getTopCommandIds(Long l) {
List<String> list = (List) this.topCommandIdsSnapshot.get(Long.valueOf(l != null ? l.longValue() : 0));
return list != null ? list : n.emptyList();
}
@StoreThread
public final void handlePreLogout() {
Persister.clear$default(this.frecencyCache, false, 1, null);
}
public final Observable<List<String>> observeTopCommandIds(Long l) {
Observable<List<String>> T = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreApplicationCommandFrecency$observeTopCommandIds$1(this, l), 14, null).T(getTopCommandIds(l));
m.checkNotNullExpressionValue(T, "observationDeck.connectR…etTopCommandIds(guildId))");
return T;
}
public final void onCommandUsed(Long l, String str) {
m.checkNotNullParameter(str, "commandId");
this.dispatcher.schedule(new StoreApplicationCommandFrecency$onCommandUsed$1(this, l, str));
}
public final void populateStore() {
this.dispatcher.schedule(new StoreApplicationCommandFrecency$populateStore$1(this));
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
this.topCommandIdsSnapshot = new HashMap(this.topCommandIds);
}
}