180 lines
7.5 KiB
Java
180 lines
7.5 KiB
Java
|
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<Long, StageInstance> stageInstancesByChannel;
|
||
|
private Map<Long, StageInstance> stageInstancesByChannelSnapshot;
|
||
|
private final Map<Long, Map<Long, StageInstance>> stageInstancesByGuild;
|
||
|
private Map<Long, ? extends Map<Long, StageInstance>> 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<Long, StageInstance> 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<Long, Map<Long, StageInstance>> map = this.stageInstancesByGuild;
|
||
|
Long valueOf = Long.valueOf(stageInstance.b());
|
||
|
Map<Long, StageInstance> 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<Long, StageInstance> getStageInstances() {
|
||
|
return this.stageInstancesByChannelSnapshot;
|
||
|
}
|
||
|
|
||
|
/* 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.stageinstance.StageInstance>>, java.util.Map<java.lang.Long, java.util.Map<java.lang.Long, com.discord.api.stageinstance.StageInstance>> */
|
||
|
public final Map<Long, Map<Long, StageInstance>> getStageInstancesByGuild() {
|
||
|
return this.stageInstancesByGuildSnapshot;
|
||
|
}
|
||
|
|
||
|
public final Map<Long, StageInstance> getStageInstancesForGuild(long j) {
|
||
|
Map<Long, StageInstance> map = (Map) this.stageInstancesByGuildSnapshot.get(Long.valueOf(j));
|
||
|
return map != null ? map : h0.emptyMap();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final Map<Long, StageInstance> getStageInstancesForGuildInternal(long j) {
|
||
|
Map<Long, StageInstance> 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<Guild> 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<StageInstance> G = guild.G();
|
||
|
if (G != null) {
|
||
|
for (StageInstance stageInstance : G) {
|
||
|
handleStageInstanceCreateOrUpdate(stageInstance);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleGuildRemove(Guild guild) {
|
||
|
Set<Long> set;
|
||
|
m.checkNotNullParameter(guild, "guild");
|
||
|
Map<Long, StageInstance> 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<StageInstance> 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<Map<Long, StageInstance>> observeStageInstances() {
|
||
|
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStageInstances$observeStageInstances$1(this), 14, null);
|
||
|
}
|
||
|
|
||
|
public final Observable<Map<Long, StageInstance>> 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<Long, Map<Long, StageInstance>> entry : this.stageInstancesByGuild.entrySet()) {
|
||
|
hashMap.put(entry.getKey(), new HashMap(entry.getValue()));
|
||
|
}
|
||
|
this.stageInstancesByGuildSnapshot = hashMap;
|
||
|
}
|
||
|
}
|