122 lines
5.6 KiB
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.m0(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>> s2 = this.integrationsSubject.G(new StoreGuildIntegrations$get$1(j)).s();
|
||
|
m.checkNotNullExpressionValue(s2, "integrationsSubject\n … .distinctUntilChanged()");
|
||
|
return s2;
|
||
|
}
|
||
|
|
||
|
public final Observable<ModelGuildIntegration> get(long j, long j2) {
|
||
|
Observable<ModelGuildIntegration> s2 = get(j).G(new StoreGuildIntegrations$get$2(j2)).s();
|
||
|
m.checkNotNullExpressionValue(s2, "get(guildId)\n .… .distinctUntilChanged()");
|
||
|
return s2;
|
||
|
}
|
||
|
|
||
|
@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> e02 = Observable.e0(1000, TimeUnit.MILLISECONDS);
|
||
|
m.checkNotNullExpressionValue(e02, "Observable\n .time…S, TimeUnit.MILLISECONDS)");
|
||
|
ObservableExtensionsKt.appSubscribe$default(e02, 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));
|
||
|
}
|
||
|
}
|