261 lines
11 KiB
Java
261 lines
11 KiB
Java
package com.discord.stores;
|
|
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.api.stageinstance.RecommendedStageInstance;
|
|
import com.discord.api.stageinstance.StageInstance;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import d0.t.h0;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlinx.coroutines.CoroutineDispatcher;
|
|
import kotlinx.coroutines.Job;
|
|
import rx.Observable;
|
|
import s.a.a.n;
|
|
import s.a.j0;
|
|
import s.a.w0;
|
|
/* compiled from: StoreRequestedStageChannels.kt */
|
|
public final class StoreRequestedStageChannels extends StoreV2 {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final long ENQUEUE_DEBOUNCE_DELAY_MS = 22;
|
|
private final Dispatcher dispatcher;
|
|
private Job enqueuedChannelFetchJob;
|
|
private Set<Long> enqueuedChannelFetches;
|
|
private final ObservationDeck observationDeck;
|
|
private final Map<Long, StageInstanceState> requestedStageChannels;
|
|
private Map<Long, StageInstanceState> requestedStageChannelsSnapshot;
|
|
private final RestAPI restAPI;
|
|
|
|
/* compiled from: StoreRequestedStageChannels.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreRequestedStageChannels.kt */
|
|
public enum FetchStatus {
|
|
ERROR,
|
|
LOADING,
|
|
LOADED
|
|
}
|
|
|
|
/* compiled from: StoreRequestedStageChannels.kt */
|
|
public static final class StageInstanceState {
|
|
private final RecommendedStageInstance stageInstance;
|
|
private final FetchStatus status;
|
|
|
|
public StageInstanceState(RecommendedStageInstance recommendedStageInstance, FetchStatus fetchStatus) {
|
|
m.checkNotNullParameter(fetchStatus, "status");
|
|
this.stageInstance = recommendedStageInstance;
|
|
this.status = fetchStatus;
|
|
}
|
|
|
|
public static /* synthetic */ StageInstanceState copy$default(StageInstanceState stageInstanceState, RecommendedStageInstance recommendedStageInstance, FetchStatus fetchStatus, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
recommendedStageInstance = stageInstanceState.stageInstance;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
fetchStatus = stageInstanceState.status;
|
|
}
|
|
return stageInstanceState.copy(recommendedStageInstance, fetchStatus);
|
|
}
|
|
|
|
public final RecommendedStageInstance component1() {
|
|
return this.stageInstance;
|
|
}
|
|
|
|
public final FetchStatus component2() {
|
|
return this.status;
|
|
}
|
|
|
|
public final StageInstanceState copy(RecommendedStageInstance recommendedStageInstance, FetchStatus fetchStatus) {
|
|
m.checkNotNullParameter(fetchStatus, "status");
|
|
return new StageInstanceState(recommendedStageInstance, fetchStatus);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof StageInstanceState)) {
|
|
return false;
|
|
}
|
|
StageInstanceState stageInstanceState = (StageInstanceState) obj;
|
|
return m.areEqual(this.stageInstance, stageInstanceState.stageInstance) && m.areEqual(this.status, stageInstanceState.status);
|
|
}
|
|
|
|
public final RecommendedStageInstance getStageInstance() {
|
|
return this.stageInstance;
|
|
}
|
|
|
|
public final FetchStatus getStatus() {
|
|
return this.status;
|
|
}
|
|
|
|
public int hashCode() {
|
|
RecommendedStageInstance recommendedStageInstance = this.stageInstance;
|
|
int i = 0;
|
|
int hashCode = (recommendedStageInstance != null ? recommendedStageInstance.hashCode() : 0) * 31;
|
|
FetchStatus fetchStatus = this.status;
|
|
if (fetchStatus != null) {
|
|
i = fetchStatus.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public final boolean isError() {
|
|
return this.status == FetchStatus.ERROR;
|
|
}
|
|
|
|
public final boolean isLoaded() {
|
|
return this.status == FetchStatus.LOADED;
|
|
}
|
|
|
|
public final boolean isLoading() {
|
|
return this.status == FetchStatus.LOADING;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("StageInstanceState(stageInstance=");
|
|
K.append(this.stageInstance);
|
|
K.append(", status=");
|
|
K.append(this.status);
|
|
K.append(")");
|
|
return K.toString();
|
|
}
|
|
}
|
|
|
|
public StoreRequestedStageChannels(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.requestedStageChannels = new LinkedHashMap();
|
|
this.requestedStageChannelsSnapshot = h0.emptyMap();
|
|
this.enqueuedChannelFetches = new LinkedHashSet();
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ StoreRequestedStageChannels(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(StoreRequestedStageChannels storeRequestedStageChannels) {
|
|
return storeRequestedStageChannels.dispatcher;
|
|
}
|
|
|
|
public static final /* synthetic */ Set access$getEnqueuedChannelFetches$p(StoreRequestedStageChannels storeRequestedStageChannels) {
|
|
return storeRequestedStageChannels.enqueuedChannelFetches;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getRequestedStageChannelsSnapshot$p(StoreRequestedStageChannels storeRequestedStageChannels) {
|
|
return storeRequestedStageChannels.requestedStageChannelsSnapshot;
|
|
}
|
|
|
|
public static final /* synthetic */ RestAPI access$getRestAPI$p(StoreRequestedStageChannels storeRequestedStageChannels) {
|
|
return storeRequestedStageChannels.restAPI;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onLoaded(StoreRequestedStageChannels storeRequestedStageChannels, Set set, List list) {
|
|
storeRequestedStageChannels.onLoaded(set, list);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setEnqueuedChannelFetches$p(StoreRequestedStageChannels storeRequestedStageChannels, Set set) {
|
|
storeRequestedStageChannels.enqueuedChannelFetches = set;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setRequestedStageChannelsSnapshot$p(StoreRequestedStageChannels storeRequestedStageChannels, Map map) {
|
|
storeRequestedStageChannels.requestedStageChannelsSnapshot = map;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$updateStatus(StoreRequestedStageChannels storeRequestedStageChannels, Set set, FetchStatus fetchStatus) {
|
|
storeRequestedStageChannels.updateStatus(set, fetchStatus);
|
|
}
|
|
|
|
@StoreThread
|
|
private final void onLoaded(Set<Long> set, List<RecommendedStageInstance> list) {
|
|
Set<Number> mutableSet = u.toMutableSet(set);
|
|
for (RecommendedStageInstance recommendedStageInstance : list) {
|
|
this.requestedStageChannels.put(Long.valueOf(recommendedStageInstance.b().a()), new StageInstanceState(recommendedStageInstance, FetchStatus.LOADED));
|
|
mutableSet.remove(Long.valueOf(recommendedStageInstance.b().a()));
|
|
}
|
|
for (Number number : mutableSet) {
|
|
this.requestedStageChannels.put(Long.valueOf(number.longValue()), new StageInstanceState(null, FetchStatus.LOADED));
|
|
}
|
|
markChanged();
|
|
}
|
|
|
|
@StoreThread
|
|
private final void updateStatus(Set<Long> set, FetchStatus fetchStatus) {
|
|
for (Number number : set) {
|
|
long longValue = number.longValue();
|
|
StageInstanceState stageInstanceState = this.requestedStageChannels.get(Long.valueOf(longValue));
|
|
this.requestedStageChannels.put(Long.valueOf(longValue), new StageInstanceState(stageInstanceState != null ? stageInstanceState.getStageInstance() : null, fetchStatus));
|
|
}
|
|
markChanged();
|
|
}
|
|
|
|
@MainThread
|
|
public final void enqueueStageChannelFetch(long j) {
|
|
StageInstanceState stageInstanceState = this.requestedStageChannelsSnapshot.get(Long.valueOf(j));
|
|
if (stageInstanceState == null || stageInstanceState.isError()) {
|
|
this.enqueuedChannelFetches.add(Long.valueOf(j));
|
|
Job job = this.enqueuedChannelFetchJob;
|
|
if (job == null || !job.a()) {
|
|
w0 w0Var = w0.i;
|
|
CoroutineDispatcher coroutineDispatcher = j0.a;
|
|
this.enqueuedChannelFetchJob = c.q.a.k.a.G(w0Var, n.b, null, new StoreRequestedStageChannels$enqueueStageChannelFetch$1(this, null), 2, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void fetchStageChannels(Set<Long> set) {
|
|
m.checkNotNullParameter(set, "channelIds");
|
|
this.dispatcher.schedule(new StoreRequestedStageChannels$fetchStageChannels$1(this, set));
|
|
}
|
|
|
|
public final Map<Long, StageInstanceState> getRequestedInstanceStatesByChannel() {
|
|
return this.requestedStageChannelsSnapshot;
|
|
}
|
|
|
|
public final StageInstance getStageInstanceForChannel(long j) {
|
|
RecommendedStageInstance stageInstance;
|
|
StageInstanceState stageInstanceState = getRequestedInstanceStatesByChannel().get(Long.valueOf(j));
|
|
if (stageInstanceState == null || (stageInstance = stageInstanceState.getStageInstance()) == null) {
|
|
return null;
|
|
}
|
|
return stageInstance.b();
|
|
}
|
|
|
|
public final Observable<StageInstanceState> observeRequestedStageChannel(long j) {
|
|
Observable<R> F = observeRequestedStageChannels().F(new StoreRequestedStageChannels$observeRequestedStageChannel$1(j));
|
|
m.checkNotNullExpressionValue(F, "observeRequestedStageCha…s().map { it[channelId] }");
|
|
return F;
|
|
}
|
|
|
|
public final Observable<Map<Long, StageInstanceState>> observeRequestedStageChannels() {
|
|
Observable<Map<Long, StageInstanceState>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreRequestedStageChannels$observeRequestedStageChannels$1(this), 14, null).r();
|
|
m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
this.requestedStageChannelsSnapshot = h0.toMap(this.requestedStageChannels);
|
|
}
|
|
}
|