174 lines
5.9 KiB
Java
174 lines
5.9 KiB
Java
package com.discord.stores;
|
|
|
|
import com.discord.api.guild.Guild;
|
|
import com.discord.api.guildmember.GuildMember;
|
|
import com.discord.api.sticker.GuildStickerUpdate;
|
|
import com.discord.api.sticker.Sticker;
|
|
import com.discord.api.sticker.StickerType;
|
|
import com.discord.models.domain.ModelPayload;
|
|
import d0.d0.f;
|
|
import d0.t.g0;
|
|
import d0.t.h0;
|
|
import d0.t.n;
|
|
import d0.t.o;
|
|
import d0.z.d.m;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import kotlin.Unit;
|
|
/* compiled from: StoreGuildStickers.kt */
|
|
public final class StoreGuildStickers extends StoreV2 {
|
|
private final Map<Long, Map<Long, Sticker>> allGuildStickers = new LinkedHashMap();
|
|
private Map<Long, ? extends Map<Long, Sticker>> allGuildStickersSnapshot = h0.emptyMap();
|
|
private final Dispatcher dispatcher;
|
|
|
|
/* renamed from: me reason: collision with root package name */
|
|
private long f2097me;
|
|
|
|
public StoreGuildStickers(Dispatcher dispatcher) {
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
this.dispatcher = dispatcher;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getAllGuildStickers$p(StoreGuildStickers storeGuildStickers) {
|
|
return storeGuildStickers.allGuildStickers;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
@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.f2097me = modelPayload.getMe().i();
|
|
for (Guild guild : modelPayload.getGuilds()) {
|
|
m.checkNotNullExpressionValue(guild, "guild");
|
|
handleGuildCreateOrUpdate(guild);
|
|
}
|
|
}
|
|
|
|
public final void handleFetchedSticker(Sticker sticker) {
|
|
Long f;
|
|
if (sticker != null && sticker.j() == StickerType.GUILD && (f = sticker.f()) != null) {
|
|
this.dispatcher.schedule(new StoreGuildStickers$handleFetchedSticker$1(this, f.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.f2097me) {
|
|
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(GuildStickerUpdate guildStickerUpdate) {
|
|
m.checkNotNullParameter(guildStickerUpdate, "stickersUpdate");
|
|
updateStickers(guildStickerUpdate.b(), guildStickerUpdate.c());
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<Long, Map<Long, Sticker>> entry : this.allGuildStickers.entrySet()) {
|
|
linkedHashMap.put(Long.valueOf(entry.getKey().longValue()), h0.toMap(entry.getValue()));
|
|
}
|
|
this.allGuildStickersSnapshot = linkedHashMap;
|
|
}
|
|
}
|