151 lines
6.6 KiB
Java
151 lines
6.6 KiB
Java
package com.discord.stores;
|
|
|
|
import c0.g0.s;
|
|
import c0.g0.w;
|
|
import c0.t.g0;
|
|
import c0.t.h0;
|
|
import c0.t.n;
|
|
import c0.t.o;
|
|
import c0.t.u;
|
|
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 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() {
|
|
this(null, 1, null);
|
|
}
|
|
|
|
public StoreApplicationCommandFrecency(ObservationDeck observationDeck) {
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
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(ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this((i & 1) != 0 ? ObservationDeckProvider.get() : observationDeck);
|
|
}
|
|
|
|
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");
|
|
FrecencyTracker.track$default(this.frecency, getKey(l, str), 0, 2, null);
|
|
this.frecencyCache.set(this.frecency, true);
|
|
this.topCommandIds.put(Long.valueOf(l != null ? l.longValue() : 0), getAllTopCommandIds(l));
|
|
markChanged(this);
|
|
}
|
|
|
|
public final void populateStore() {
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (String str : FrecencyTracker.getSortedKeys$default(this.frecency, 0, 1, null)) {
|
|
if (w.contains$default((CharSequence) str, (CharSequence) ":", false, 2, (Object) null)) {
|
|
List split$default = w.split$default((CharSequence) str, new String[]{":"}, false, 0, 6, (Object) null);
|
|
Long longOrNull = s.toLongOrNull((String) split$default.get(1));
|
|
long longValue = longOrNull != null ? longOrNull.longValue() : 0;
|
|
String str2 = (String) split$default.get(0);
|
|
List list = (List) linkedHashMap.get(Long.valueOf(longValue));
|
|
if (list == null) {
|
|
list = new ArrayList();
|
|
linkedHashMap.put(Long.valueOf(longValue), list);
|
|
}
|
|
list.add(str2);
|
|
} else {
|
|
List list2 = (List) linkedHashMap.get(0L);
|
|
if (list2 == null) {
|
|
list2 = new ArrayList();
|
|
linkedHashMap.put(0L, list2);
|
|
}
|
|
list2.add(str);
|
|
}
|
|
}
|
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap(g0.mapCapacity(linkedHashMap.size()));
|
|
for (Map.Entry entry : linkedHashMap.entrySet()) {
|
|
linkedHashMap2.put(entry.getKey(), u.toList((Iterable) entry.getValue()));
|
|
}
|
|
this.topCommandIds = h0.toMutableMap(linkedHashMap2);
|
|
this.topCommandIdsSnapshot = linkedHashMap;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
this.topCommandIdsSnapshot = new HashMap(this.topCommandIds);
|
|
}
|
|
}
|