discord-jadx/app/src/main/java/com/discord/stores/StoreGuildIntegrations.java

122 lines
5.6 KiB
Java

package com.discord.stores;
import android.content.Context;
import c.d.b.a.a;
import com.discord.models.domain.ModelGuildIntegration;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import d0.z.d.m;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import rx.Observable;
import rx.Subscription;
import rx.subjects.BehaviorSubject;
/* compiled from: StoreGuildIntegrations.kt */
public final class StoreGuildIntegrations {
private final HashMap<Long, Map<Long, ModelGuildIntegration>> allIntegrations = new HashMap<>();
private Subscription closeIntegrationScreenSubscription;
private final Dispatcher dispatcher;
private final BehaviorSubject<Map<Long, Map<Long, ModelGuildIntegration>>> integrationsSubject = BehaviorSubject.l0(new HashMap());
private boolean isOnIntegrationsScreen;
public StoreGuildIntegrations(Dispatcher dispatcher) {
m.checkNotNullParameter(dispatcher, "dispatcher");
this.dispatcher = dispatcher;
}
public static final /* synthetic */ Subscription access$getCloseIntegrationScreenSubscription$p(StoreGuildIntegrations storeGuildIntegrations) {
return storeGuildIntegrations.closeIntegrationScreenSubscription;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreGuildIntegrations storeGuildIntegrations) {
return storeGuildIntegrations.dispatcher;
}
public static final /* synthetic */ void access$handleIntegrationScreenClosed(StoreGuildIntegrations storeGuildIntegrations) {
storeGuildIntegrations.handleIntegrationScreenClosed();
}
public static final /* synthetic */ void access$handleIntegrationScreenOpened(StoreGuildIntegrations storeGuildIntegrations, long j) {
storeGuildIntegrations.handleIntegrationScreenOpened(j);
}
public static final /* synthetic */ void access$handleIntegrationsLoaded(StoreGuildIntegrations storeGuildIntegrations, long j, List list) {
storeGuildIntegrations.handleIntegrationsLoaded(j, list);
}
public static final /* synthetic */ void access$setCloseIntegrationScreenSubscription$p(StoreGuildIntegrations storeGuildIntegrations, Subscription subscription) {
storeGuildIntegrations.closeIntegrationScreenSubscription = subscription;
}
@StoreThread
private final void handleIntegrationScreenClosed() {
this.isOnIntegrationsScreen = false;
}
@StoreThread
private final void handleIntegrationScreenOpened(long j) {
if (!this.isOnIntegrationsScreen) {
this.isOnIntegrationsScreen = true;
requestGuildIntegrations(j);
}
}
@StoreThread
private final void handleIntegrationsLoaded(long j, List<? extends ModelGuildIntegration> list) {
HashMap<Long, Map<Long, ModelGuildIntegration>> hashMap = this.allIntegrations;
Long valueOf = Long.valueOf(j);
LinkedHashMap linkedHashMap = new LinkedHashMap(a.I(list, 10, 16));
for (Object obj : list) {
linkedHashMap.put(Long.valueOf(((ModelGuildIntegration) obj).getId()), obj);
}
hashMap.put(valueOf, linkedHashMap);
this.integrationsSubject.onNext(new HashMap(this.allIntegrations));
}
private final void requestGuildIntegrations(long j) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().getGuildIntegrations(j), false, 1, null), StoreGuildIntegrations.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreGuildIntegrations$requestGuildIntegrations$1(this, j), 62, (Object) null);
}
public final Observable<Map<Long, ModelGuildIntegration>> get(long j) {
Observable<Map<Long, ModelGuildIntegration>> r = this.integrationsSubject.F(new StoreGuildIntegrations$get$1(j)).r();
m.checkNotNullExpressionValue(r, "integrationsSubject\n … .distinctUntilChanged()");
return r;
}
public final Observable<ModelGuildIntegration> get(long j, long j2) {
Observable<ModelGuildIntegration> r = get(j).F(new StoreGuildIntegrations$get$2(j2)).r();
m.checkNotNullExpressionValue(r, "get(guildId)\n .… .distinctUntilChanged()");
return r;
}
@StoreThread
public final void handleUpdate(ModelGuildIntegration.Update update) {
if (this.isOnIntegrationsScreen && update != null) {
requestGuildIntegrations(update.getGuildId());
}
}
public final synchronized void onIntegrationScreenClosed() {
Subscription subscription = this.closeIntegrationScreenSubscription;
if (subscription != null) {
subscription.unsubscribe();
}
Observable<Long> d02 = Observable.d0(1000, TimeUnit.MILLISECONDS);
m.checkNotNullExpressionValue(d02, "Observable\n .time…S, TimeUnit.MILLISECONDS)");
ObservableExtensionsKt.appSubscribe$default(d02, getClass(), (Context) null, new StoreGuildIntegrations$onIntegrationScreenClosed$2(this), (Function1) null, (Function0) null, (Function0) null, new StoreGuildIntegrations$onIntegrationScreenClosed$1(this), 58, (Object) null);
}
public final synchronized void onIntegrationScreenOpened(long j) {
Subscription subscription = this.closeIntegrationScreenSubscription;
if (subscription != null) {
subscription.unsubscribe();
}
this.dispatcher.schedule(new StoreGuildIntegrations$onIntegrationScreenOpened$1(this, j));
}
}