package com.discord.stores; import android.content.Context; import c.d.b.a.a; import com.discord.api.guild.Guild; import com.discord.models.domain.ModelInvite; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import com.discord.utilities.error.Error; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.t.h0; import d0.z.d.m; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreInstantInvites.kt */ public final class StoreInstantInvites extends StoreV2 { private final Dispatcher dispatcher; private final Map> invites; private Map> invitesSnapshot; private final Map knownInvites; private Map knownInvitesSnapshot; private final ObservationDeck observationDeck; private final RestAPI restAPI; /* compiled from: StoreInstantInvites.kt */ public static abstract class InviteState { /* compiled from: StoreInstantInvites.kt */ public static final class Invalid extends InviteState { public static final Invalid INSTANCE = new Invalid(); private Invalid() { super(null); } } /* compiled from: StoreInstantInvites.kt */ public static final class LoadFailed extends InviteState { public static final LoadFailed INSTANCE = new LoadFailed(); private LoadFailed() { super(null); } } /* compiled from: StoreInstantInvites.kt */ public static final class Loading extends InviteState { public static final Loading INSTANCE = new Loading(); private Loading() { super(null); } } /* compiled from: StoreInstantInvites.kt */ public static final class Resolved extends InviteState { private final ModelInvite invite; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Resolved(ModelInvite modelInvite) { super(null); m.checkNotNullParameter(modelInvite, "invite"); this.invite = modelInvite; } public static /* synthetic */ Resolved copy$default(Resolved resolved, ModelInvite modelInvite, int i, Object obj) { if ((i & 1) != 0) { modelInvite = resolved.invite; } return resolved.copy(modelInvite); } public final ModelInvite component1() { return this.invite; } public final Resolved copy(ModelInvite modelInvite) { m.checkNotNullParameter(modelInvite, "invite"); return new Resolved(modelInvite); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Resolved) && m.areEqual(this.invite, ((Resolved) obj).invite); } return true; } public final ModelInvite getInvite() { return this.invite; } public int hashCode() { ModelInvite modelInvite = this.invite; if (modelInvite != null) { return modelInvite.hashCode(); } return 0; } public String toString() { StringBuilder L = a.L("Resolved(invite="); L.append(this.invite); L.append(")"); return L.toString(); } } private InviteState() { } public /* synthetic */ InviteState(DefaultConstructorMarker defaultConstructorMarker) { this(); } } public final /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; static { Error.Type.values(); int[] iArr = new int[17]; $EnumSwitchMapping$0 = iArr; iArr[Error.Type.DISCORD_REQUEST_ERROR.ordinal()] = 1; iArr[Error.Type.NETWORK.ordinal()] = 2; } } public StoreInstantInvites(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI) { m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(observationDeck, "observationDeck"); m.checkNotNullParameter(restAPI, "restAPI"); this.dispatcher = dispatcher; this.observationDeck = observationDeck; this.restAPI = restAPI; this.invites = new LinkedHashMap(); this.invitesSnapshot = h0.emptyMap(); this.knownInvites = new LinkedHashMap(); this.knownInvitesSnapshot = h0.emptyMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreInstantInvites(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) { this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 4) != 0 ? RestAPI.Companion.getApi() : restAPI); } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreInstantInvites storeInstantInvites) { return storeInstantInvites.dispatcher; } public static final /* synthetic */ Map access$getInvites(StoreInstantInvites storeInstantInvites, long j) { return storeInstantInvites.getInvites(j); } public static final /* synthetic */ Map access$getInvites$p(StoreInstantInvites storeInstantInvites) { return storeInstantInvites.invites; } public static final /* synthetic */ Map access$getKnownInvites(StoreInstantInvites storeInstantInvites) { return storeInstantInvites.getKnownInvites(); } public static final /* synthetic */ Map access$getKnownInvites$p(StoreInstantInvites storeInstantInvites) { return storeInstantInvites.knownInvites; } public static final /* synthetic */ RestAPI access$getRestAPI$p(StoreInstantInvites storeInstantInvites) { return storeInstantInvites.restAPI; } public static final /* synthetic */ void access$onLoadedInvites(StoreInstantInvites storeInstantInvites, List list) { storeInstantInvites.onLoadedInvites(list); } public static final /* synthetic */ void access$setChatInvites(StoreInstantInvites storeInstantInvites, String str, InviteState inviteState) { storeInstantInvites.setChatInvites(str, inviteState); } public static /* synthetic */ void fetchInviteIfNotLoaded$default(StoreInstantInvites storeInstantInvites, String str, String str2, int i, Object obj) { if ((i & 2) != 0) { str2 = null; } storeInstantInvites.fetchInviteIfNotLoaded(str, str2); } /* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map>, java.util.Map> */ private final Map> getInvites() { return this.invitesSnapshot; } private final Map getInvites(long j) { Map map = getInvites().get(Long.valueOf(j)); return map != null ? map : h0.emptyMap(); } /* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map, java.util.Map */ private final Map getKnownInvites() { return this.knownInvitesSnapshot; } @StoreThread private final void onLoadedInvites(List list) { this.invites.clear(); for (ModelInvite modelInvite : list) { Guild guild = modelInvite.getGuild(); Long valueOf = guild != null ? Long.valueOf(guild.o()) : null; if (valueOf != null) { Map map = this.invites.get(valueOf); if (map == null) { map = new LinkedHashMap<>(); } String code = modelInvite.getCode(); m.checkNotNullExpressionValue(code, "invite.code"); map.put(code, modelInvite); this.invites.put(valueOf, map); } } markChanged(); } @StoreThread private final void setChatInvites(String str, InviteState inviteState) { this.knownInvites.put(str, inviteState); markChanged(); } public final void clearInvites(long j) { this.dispatcher.schedule(new StoreInstantInvites$clearInvites$1(this, j)); } public final void fetchGuildInvites(long j) { ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.getGuildInvites(j), false, 1, null), StoreInstantInvites.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreInstantInvites$fetchGuildInvites$1(this), 62, (Object) null); } public final void fetchInviteIfNotLoaded(String str, String str2) { m.checkNotNullParameter(str, "inviteCode"); this.dispatcher.schedule(new StoreInstantInvites$fetchInviteIfNotLoaded$1(this, str, str2)); } public final Observable observeInvite(String str) { m.checkNotNullParameter(str, "inviteCode"); Observable r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreInstantInvites$observeInvite$1(this), 14, null).F(new StoreInstantInvites$observeInvite$2(str)).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()"); return r; } public final Observable> observeInvites(long j) { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreInstantInvites$observeInvites$1(this, j), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()"); return r; } public final Observable> observeKnownInvites() { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreInstantInvites$observeKnownInvites$1(this), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()"); return r; } public final void onInviteRemoved(ModelInvite modelInvite) { m.checkNotNullParameter(modelInvite, "invite"); this.dispatcher.schedule(new StoreInstantInvites$onInviteRemoved$1(this, modelInvite)); } @Override // com.discord.stores.StoreV2 public void snapshotData() { super.snapshotData(); LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry> entry : this.invites.entrySet()) { linkedHashMap.put(Long.valueOf(entry.getKey().longValue()), new HashMap(entry.getValue())); } this.invitesSnapshot = linkedHashMap; this.knownInvitesSnapshot = new HashMap(this.knownInvites); } }