package com.discord.stores; import android.content.Context; import androidx.fragment.app.FragmentManager; import c.a.d.q; import com.discord.app.AppComponent; import com.discord.models.domain.ModelCall; import com.discord.stores.StoreStream; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.z.d.m; import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import rx.Observable; import rx.subjects.BehaviorSubject; import rx.subjects.SerializedSubject; /* compiled from: StoreCalls.kt */ public final class StoreCalls { private final HashMap calls = new HashMap<>(); private final SerializedSubject, HashMap> callsSubject = new SerializedSubject<>(BehaviorSubject.k0()); private boolean connectionReady; private long selectedChannelId; private long selectedGuildId; private final StoreStream stream; public StoreCalls(StoreStream storeStream) { m.checkNotNullParameter(storeStream, "stream"); this.stream = storeStream; } public static final /* synthetic */ StoreStream access$getStream$p(StoreCalls storeCalls) { return storeCalls.stream; } /* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: com.discord.stores.StoreCalls */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ void call$default(StoreCalls storeCalls, AppComponent appComponent, Context context, FragmentManager fragmentManager, long j, Function0 function0, int i, Object obj) { if ((i & 16) != 0) { function0 = null; } storeCalls.call(appComponent, context, fragmentManager, j, function0); } private final void callConnect() { if (this.connectionReady && this.selectedGuildId == 0) { long j = this.selectedChannelId; if (j > 0 && !this.calls.containsKey(Long.valueOf(j))) { this.calls.put(Long.valueOf(this.selectedChannelId), null); this.stream.getGatewaySocket$app_productionBetaRelease().callConnect(this.selectedChannelId); } } } private final void callSubjectUpdate(boolean z2) { if (z2) { SerializedSubject, HashMap> serializedSubject = this.callsSubject; serializedSubject.j.onNext(new HashMap<>(this.calls)); } } public static /* synthetic */ void callSubjectUpdate$default(StoreCalls storeCalls, boolean z2, int i, Object obj) { if ((i & 1) != 0) { z2 = true; } storeCalls.callSubjectUpdate(z2); } private final void findCall(long j, Function1 function1) { Observable k = get(j).k(q.c(StoreCalls$findCall$1.INSTANCE, null, 3, TimeUnit.SECONDS)); m.checkNotNullExpressionValue(k, "get(channelId)\n .…l?, 3, TimeUnit.SECONDS))"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.takeSingleUntilTimeout$default(k, 0, false, 3, null), StoreCalls.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, function1, 62, (Object) null); } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreCalls */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ void ring$default(StoreCalls storeCalls, long j, List list, int i, Object obj) { if ((i & 2) != 0) { list = null; } storeCalls.ring(j, list); } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreCalls */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ void stopRinging$default(StoreCalls storeCalls, long j, List list, int i, Object obj) { if ((i & 2) != 0) { list = null; } storeCalls.stopRinging(j, list); } public final void call(AppComponent appComponent, Context context, FragmentManager fragmentManager, long j, Function0 function0) { m.checkNotNullParameter(appComponent, "appComponent"); m.checkNotNullParameter(context, "context"); m.checkNotNullParameter(fragmentManager, "fragmentManager"); StoreCalls$call$1 storeCalls$call$1 = new StoreCalls$call$1(this, j); StoreCalls$call$2 storeCalls$call$2 = new StoreCalls$call$2(this, j, appComponent, context, storeCalls$call$1, function0, fragmentManager); StoreStream.Companion companion = StoreStream.Companion; Observable Z = Observable.j0(companion.getChannels().observeChannel(j).k(q.c(StoreCalls$call$3.INSTANCE, null, 5000, TimeUnit.MILLISECONDS)), companion.getVoiceStates().observeForPrivateChannels(j), StoreCalls$call$4.INSTANCE).Z(1); m.checkNotNullExpressionValue(Z, "Observable\n .zip(…tates) }\n .take(1)"); ObservableExtensionsKt.appSubscribe$default(Z, StoreCalls.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreCalls$call$5(storeCalls$call$2, storeCalls$call$1), 62, (Object) null); } public final Observable get(long j) { Observable> F = this.callsSubject.F(new StoreCalls$get$1(j)); m.checkNotNullExpressionValue(F, "callsSubject\n .…lls -> calls[channelId] }"); Observable r = ObservableExtensionsKt.computationLatest(F).r(); m.checkNotNullExpressionValue(r, "callsSubject\n .… .distinctUntilChanged()"); return r; } public final void handleCallCreateOrUpdate(ModelCall modelCall) { m.checkNotNullParameter(modelCall, "call"); long channelId = modelCall.getChannelId(); boolean z2 = true; if (!m.areEqual(modelCall, this.calls.get(Long.valueOf(channelId)))) { this.calls.put(Long.valueOf(channelId), modelCall); } else { z2 = false; } callSubjectUpdate(z2); } public final void handleCallDelete(ModelCall modelCall) { m.checkNotNullParameter(modelCall, "callDelete"); long channelId = modelCall.getChannelId(); if (this.calls.containsKey(Long.valueOf(channelId))) { this.calls.put(Long.valueOf(channelId), null); callSubjectUpdate$default(this, false, 1, null); } } public final void handleChannelSelect(long j) { this.selectedChannelId = j; callConnect(); } public final void handleConnectionOpen() { this.calls.clear(); callSubjectUpdate$default(this, false, 1, null); callConnect(); } public final void handleConnectionReady(boolean z2) { this.connectionReady = z2; callConnect(); } public final void handleGuildSelect(long j) { this.selectedGuildId = j; callConnect(); } public final void ring(long j, List list) { findCall(j, new StoreCalls$ring$1(this, list)); } public final void stopRinging(long j, List list) { findCall(j, new StoreCalls$stopRinging$1(this, j, list)); } }