245 lines
9.5 KiB
Java
245 lines
9.5 KiB
Java
package com.discord.stores;
|
|
|
|
import com.discord.api.guild.Guild;
|
|
import com.discord.api.guildmember.GuildMember;
|
|
import com.discord.api.sticker.GuildStickersUpdate;
|
|
import com.discord.api.sticker.Sticker;
|
|
import com.discord.api.sticker.StickerType;
|
|
import com.discord.models.domain.ModelPayload;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import d0.d0.f;
|
|
import d0.t.g0;
|
|
import d0.t.h0;
|
|
import d0.t.n;
|
|
import d0.t.o;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: StoreGuildStickers.kt */
|
|
public final class StoreGuildStickers extends StoreV2 {
|
|
private final Map<Long, Map<Long, Sticker>> allGuildStickers;
|
|
private List<Sticker> allGuildStickersFlattenedSnapshot;
|
|
private Map<Long, ? extends Map<Long, Sticker>> allGuildStickersSnapshot;
|
|
private final Dispatcher dispatcher;
|
|
|
|
/* renamed from: me reason: collision with root package name */
|
|
private long f2122me;
|
|
private final ObservationDeck observationDeck;
|
|
private final Function1<List<Long>, Unit> onStickersDeleted;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: kotlin.jvm.functions.Function1<? super java.util.List<java.lang.Long>, kotlin.Unit> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public StoreGuildStickers(Dispatcher dispatcher, ObservationDeck observationDeck, Function1<? super List<Long>, Unit> function1) {
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
m.checkNotNullParameter(function1, "onStickersDeleted");
|
|
this.dispatcher = dispatcher;
|
|
this.observationDeck = observationDeck;
|
|
this.onStickersDeleted = function1;
|
|
this.allGuildStickers = new LinkedHashMap();
|
|
this.allGuildStickersSnapshot = h0.emptyMap();
|
|
this.allGuildStickersFlattenedSnapshot = n.emptyList();
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ StoreGuildStickers(Dispatcher dispatcher, ObservationDeck observationDeck, Function1 function1, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck, function1);
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getAllGuildStickers$p(StoreGuildStickers storeGuildStickers) {
|
|
return storeGuildStickers.allGuildStickers;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getAllGuildStickersSnapshot$p(StoreGuildStickers storeGuildStickers) {
|
|
return storeGuildStickers.allGuildStickersSnapshot;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setAllGuildStickersSnapshot$p(StoreGuildStickers storeGuildStickers, Map map) {
|
|
storeGuildStickers.allGuildStickersSnapshot = map;
|
|
}
|
|
|
|
private final void updateStickers(long j, Collection<Sticker> collection) {
|
|
if (collection.isEmpty()) {
|
|
this.allGuildStickers.remove(Long.valueOf(j));
|
|
} else {
|
|
Map<Long, Map<Long, Sticker>> map = this.allGuildStickers;
|
|
Long valueOf = Long.valueOf(j);
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap(f.coerceAtLeast(g0.mapCapacity(o.collectionSizeOrDefault(collection, 10)), 16));
|
|
for (Object obj : collection) {
|
|
linkedHashMap.put(Long.valueOf(((Sticker) obj).getId()), obj);
|
|
}
|
|
map.put(valueOf, linkedHashMap);
|
|
}
|
|
markChanged();
|
|
}
|
|
|
|
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends java.util.Map<java.lang.Long, com.discord.api.sticker.Sticker>>, java.util.Map<java.lang.Long, java.util.Map<java.lang.Long, com.discord.api.sticker.Sticker>> */
|
|
public final Map<Long, Map<Long, Sticker>> getAllGuildStickers() {
|
|
return this.allGuildStickersSnapshot;
|
|
}
|
|
|
|
public final List<Sticker> getAllGuildStickersFlattened() {
|
|
return this.allGuildStickersFlattenedSnapshot;
|
|
}
|
|
|
|
@StoreThread
|
|
public final Map<Long, Map<Long, Sticker>> getAllGuildStickersInternal() {
|
|
return this.allGuildStickers;
|
|
}
|
|
|
|
public final Sticker getGuildSticker(long j) {
|
|
Object obj;
|
|
Iterator<T> it = getAllGuildStickers().values().iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
if (((Map) obj).containsKey(Long.valueOf(j))) {
|
|
break;
|
|
}
|
|
}
|
|
Map map = (Map) obj;
|
|
if (map != null) {
|
|
return (Sticker) map.get(Long.valueOf(j));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final Map<Long, Sticker> getStickersForGuild(long j) {
|
|
Map<Long, Sticker> map = getAllGuildStickers().get(Long.valueOf(j));
|
|
return map != null ? map : h0.emptyMap();
|
|
}
|
|
|
|
@StoreThread
|
|
public final Map<Long, Sticker> getStickersForGuildInternal(long j) {
|
|
return this.allGuildStickers.get(Long.valueOf(j));
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionOpen(ModelPayload modelPayload) {
|
|
m.checkNotNullParameter(modelPayload, "payload");
|
|
this.f2122me = modelPayload.getMe().i();
|
|
for (Guild guild : modelPayload.getGuilds()) {
|
|
m.checkNotNullExpressionValue(guild, "guild");
|
|
handleGuildCreateOrUpdate(guild);
|
|
}
|
|
}
|
|
|
|
public final void handleFetchedSticker(Sticker sticker) {
|
|
Long g;
|
|
if (sticker != null && sticker.k() == StickerType.GUILD && (g = sticker.g()) != null) {
|
|
this.dispatcher.schedule(new StoreGuildStickers$handleFetchedSticker$1(this, g.longValue(), sticker));
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final Unit handleGuildCreateOrUpdate(Guild guild) {
|
|
Object obj;
|
|
boolean z2;
|
|
m.checkNotNullParameter(guild, "guild");
|
|
List<GuildMember> s2 = guild.s();
|
|
if (s2 == null) {
|
|
return null;
|
|
}
|
|
Iterator<T> it = s2.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
if (((GuildMember) obj).j().i() == this.f2122me) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
break;
|
|
}
|
|
}
|
|
if (((GuildMember) obj) == null) {
|
|
return null;
|
|
}
|
|
long o = guild.o();
|
|
List<Sticker> H = guild.H();
|
|
if (H == null) {
|
|
H = n.emptyList();
|
|
}
|
|
updateStickers(o, H);
|
|
return Unit.a;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildRemove(long j) {
|
|
if (this.allGuildStickers.containsKey(Long.valueOf(j))) {
|
|
this.allGuildStickers.remove(Long.valueOf(j));
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleStickerUpdate(GuildStickersUpdate guildStickersUpdate) {
|
|
Collection collection;
|
|
m.checkNotNullParameter(guildStickersUpdate, "stickersUpdate");
|
|
long b = guildStickersUpdate.b();
|
|
List<Sticker> c2 = guildStickersUpdate.c();
|
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(c2, 10));
|
|
for (Sticker sticker : c2) {
|
|
arrayList.add(Long.valueOf(sticker.getId()));
|
|
}
|
|
Set set = u.toSet(arrayList);
|
|
Map map = (Map) this.allGuildStickersSnapshot.get(Long.valueOf(b));
|
|
if (map != null) {
|
|
collection = new ArrayList(map.size());
|
|
for (Map.Entry entry : map.entrySet()) {
|
|
collection.add(Long.valueOf(((Number) entry.getKey()).longValue()));
|
|
}
|
|
} else {
|
|
collection = n.emptyList();
|
|
}
|
|
ArrayList arrayList2 = new ArrayList();
|
|
for (Object obj : collection) {
|
|
if (!set.contains(Long.valueOf(((Number) obj).longValue()))) {
|
|
arrayList2.add(obj);
|
|
}
|
|
}
|
|
updateStickers(b, c2);
|
|
this.onStickersDeleted.invoke(arrayList2);
|
|
}
|
|
|
|
public final Observable<Map<Long, Map<Long, Sticker>>> observeGuildStickers() {
|
|
Observable<Map<Long, Map<Long, Sticker>>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreGuildStickers$observeGuildStickers$1(this), 14, null).r();
|
|
m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
ArrayList arrayList = new ArrayList();
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<Long, Map<Long, Sticker>> entry : this.allGuildStickers.entrySet()) {
|
|
long longValue = entry.getKey().longValue();
|
|
Map<Long, Sticker> value = entry.getValue();
|
|
linkedHashMap.put(Long.valueOf(longValue), h0.toMap(value));
|
|
arrayList.addAll(value.values());
|
|
}
|
|
this.allGuildStickersSnapshot = linkedHashMap;
|
|
this.allGuildStickersFlattenedSnapshot = u.toList(arrayList);
|
|
}
|
|
}
|