package com.discord.stores; import com.discord.api.channel.Channel; import com.discord.api.guild.Guild; import com.discord.api.stageinstance.StageInstance; import com.discord.models.domain.ModelPayload; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import d0.t.h0; import d0.t.n0; import d0.z.d.m; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreStageInstances.kt */ public final class StoreStageInstances extends StoreV2 { private final ObservationDeck observationDeck; private final Map stageInstancesByChannel; private Map stageInstancesByChannelSnapshot; private final Map> stageInstancesByGuild; private Map> stageInstancesByGuildSnapshot; public StoreStageInstances() { this(null, 1, null); } public StoreStageInstances(ObservationDeck observationDeck) { m.checkNotNullParameter(observationDeck, "observationDeck"); this.observationDeck = observationDeck; this.stageInstancesByChannel = new LinkedHashMap(); this.stageInstancesByChannelSnapshot = new HashMap(); this.stageInstancesByGuild = new LinkedHashMap(); this.stageInstancesByGuildSnapshot = new HashMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreStageInstances(ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) { this((i & 1) != 0 ? ObservationDeckProvider.get() : observationDeck); } private final void handleDelete(Long l, long j) { this.stageInstancesByChannel.remove(Long.valueOf(j)); Map map = this.stageInstancesByGuild.get(l); if (map != null) { map.remove(Long.valueOf(j)); } markChanged(); } private final void handleStageInstanceCreateOrUpdate(StageInstance stageInstance) { this.stageInstancesByChannel.put(Long.valueOf(stageInstance.a()), stageInstance); Map> map = this.stageInstancesByGuild; Long valueOf = Long.valueOf(stageInstance.b()); Map map2 = map.get(valueOf); if (map2 == null) { map2 = new LinkedHashMap<>(); map.put(valueOf, map2); } map2.put(Long.valueOf(stageInstance.a()), stageInstance); markChanged(); } public final StageInstance getStageInstanceForChannel(long j) { return this.stageInstancesByChannelSnapshot.get(Long.valueOf(j)); } public final StageInstance getStageInstanceForChannelInternal(long j) { return this.stageInstancesByChannel.get(Long.valueOf(j)); } public final Map getStageInstances() { return this.stageInstancesByChannelSnapshot; } /* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map>, java.util.Map> */ public final Map> getStageInstancesByGuild() { return this.stageInstancesByGuildSnapshot; } public final Map getStageInstancesForGuild(long j) { Map map = (Map) this.stageInstancesByGuildSnapshot.get(Long.valueOf(j)); return map != null ? map : h0.emptyMap(); } @StoreThread public final Map getStageInstancesForGuildInternal(long j) { Map map = this.stageInstancesByGuild.get(Long.valueOf(j)); return map != null ? map : h0.emptyMap(); } @StoreThread public final void handleChannelDelete(Channel channel) { m.checkNotNullParameter(channel, "channel"); handleDelete(Long.valueOf(channel.f()), channel.h()); } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "payload"); this.stageInstancesByGuild.clear(); this.stageInstancesByChannel.clear(); List guilds = modelPayload.getGuilds(); m.checkNotNullExpressionValue(guilds, "payload.guilds"); for (Guild guild : guilds) { m.checkNotNullExpressionValue(guild, "it"); handleGuildAdd(guild); } } @StoreThread public final void handleGuildAdd(Guild guild) { m.checkNotNullParameter(guild, "guild"); List G = guild.G(); if (G != null) { for (StageInstance stageInstance : G) { handleStageInstanceCreateOrUpdate(stageInstance); } } } @StoreThread public final void handleGuildRemove(Guild guild) { Set set; m.checkNotNullParameter(guild, "guild"); Map remove = this.stageInstancesByGuild.remove(Long.valueOf(guild.o())); if (remove == null || (set = remove.keySet()) == null) { set = n0.emptySet(); } if (!set.isEmpty()) { this.stageInstancesByChannel.keySet().removeAll(set); markChanged(); } } @StoreThread public final void handleStageInstanceCreate(StageInstance stageInstance) { m.checkNotNullParameter(stageInstance, "stageInstance"); handleStageInstanceCreateOrUpdate(stageInstance); } @StoreThread public final void handleStageInstanceDelete(StageInstance stageInstance) { m.checkNotNullParameter(stageInstance, "stageInstance"); handleDelete(Long.valueOf(stageInstance.b()), stageInstance.a()); } @StoreThread public final void handleStageInstanceUpdate(StageInstance stageInstance) { m.checkNotNullParameter(stageInstance, "stageInstance"); handleStageInstanceCreateOrUpdate(stageInstance); } public final Observable observeStageInstanceForChannel(long j) { return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStageInstances$observeStageInstanceForChannel$1(this, j), 14, null); } public final Observable> observeStageInstances() { return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStageInstances$observeStageInstances$1(this), 14, null); } public final Observable> observeStageInstancesForGuild(long j) { return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStageInstances$observeStageInstancesForGuild$1(this, j), 14, null); } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { this.stageInstancesByChannelSnapshot = new HashMap(this.stageInstancesByChannel); HashMap hashMap = new HashMap(); for (Map.Entry> entry : this.stageInstancesByGuild.entrySet()) { hashMap.put(entry.getKey(), new HashMap(entry.getValue())); } this.stageInstancesByGuildSnapshot = hashMap; } }