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

275 lines
11 KiB
Java

package com.discord.stores;
import android.content.Context;
import c.d.b.a.a;
import com.discord.api.premium.ClaimedOutboundPromotion;
import com.discord.api.premium.OutboundPromotion;
import com.discord.api.user.User;
import com.discord.models.domain.ModelPayload;
import com.discord.models.user.MeUser;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.user.UserUtils;
import com.discord.widgets.settings.premium.OutboundPromosPreviewFeatureFlag;
import d0.t.n;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreOutboundPromotions.kt */
public final class StoreOutboundPromotions extends StoreV2 {
private static final String CONSUMED_ENTITLEMENT_PROMO_ID = "CONSUMED_ENTITLEMENT_CODE";
public static final Companion Companion = new Companion(null);
private static final String LATEST_SEEN_PROMO_DATE = "LATEST_SEEN_PROMO_DATE";
private static final long NO_PROMO_ID = -1;
private static final long NO_SEEN_PROMO_DATE = -1;
private final Dispatcher dispatcher;
private final ObservationDeck observationDeck;
private final OutboundPromosPreviewFeatureFlag previewFeatureFlag;
private final RestAPI restAPI;
private State state;
private State stateSnapshot;
/* compiled from: StoreOutboundPromotions.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: StoreOutboundPromotions.kt */
public static abstract class State {
/* compiled from: StoreOutboundPromotions.kt */
public static final class Failed extends State {
public static final Failed INSTANCE = new Failed();
private Failed() {
super(null);
}
}
/* compiled from: StoreOutboundPromotions.kt */
public static final class Loaded extends State {
private final int unseenCount;
private final List<OutboundPromotion> validActivePromotions;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded(List<OutboundPromotion> list, int i) {
super(null);
m.checkNotNullParameter(list, "validActivePromotions");
this.validActivePromotions = list;
this.unseenCount = i;
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreOutboundPromotions$State$Loaded */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Loaded copy$default(Loaded loaded, List list, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
list = loaded.validActivePromotions;
}
if ((i2 & 2) != 0) {
i = loaded.unseenCount;
}
return loaded.copy(list, i);
}
public final List<OutboundPromotion> component1() {
return this.validActivePromotions;
}
public final int component2() {
return this.unseenCount;
}
public final Loaded copy(List<OutboundPromotion> list, int i) {
m.checkNotNullParameter(list, "validActivePromotions");
return new Loaded(list, i);
}
@Override // com.discord.stores.StoreOutboundPromotions.State
public Loaded deepCopy() {
return copy$default(this, new ArrayList(this.validActivePromotions), 0, 2, null);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Loaded)) {
return false;
}
Loaded loaded = (Loaded) obj;
return m.areEqual(this.validActivePromotions, loaded.validActivePromotions) && this.unseenCount == loaded.unseenCount;
}
public final int getUnseenCount() {
return this.unseenCount;
}
public final List<OutboundPromotion> getValidActivePromotions() {
return this.validActivePromotions;
}
public int hashCode() {
List<OutboundPromotion> list = this.validActivePromotions;
return ((list != null ? list.hashCode() : 0) * 31) + this.unseenCount;
}
public String toString() {
StringBuilder K = a.K("Loaded(validActivePromotions=");
K.append(this.validActivePromotions);
K.append(", unseenCount=");
return a.w(K, this.unseenCount, ")");
}
}
/* compiled from: StoreOutboundPromotions.kt */
public static final class Loading extends State {
public static final Loading INSTANCE = new Loading();
private Loading() {
super(null);
}
}
private State() {
}
public /* synthetic */ State(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public State deepCopy() {
return this;
}
}
public StoreOutboundPromotions(OutboundPromosPreviewFeatureFlag outboundPromosPreviewFeatureFlag, Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI) {
m.checkNotNullParameter(outboundPromosPreviewFeatureFlag, "previewFeatureFlag");
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(observationDeck, "observationDeck");
m.checkNotNullParameter(restAPI, "restAPI");
this.previewFeatureFlag = outboundPromosPreviewFeatureFlag;
this.dispatcher = dispatcher;
this.observationDeck = observationDeck;
this.restAPI = restAPI;
State.Loading loading = State.Loading.INSTANCE;
this.state = loading;
this.stateSnapshot = loading;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreOutboundPromotions(OutboundPromosPreviewFeatureFlag outboundPromosPreviewFeatureFlag, Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(outboundPromosPreviewFeatureFlag, dispatcher, (i & 4) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 8) != 0 ? RestAPI.Companion.getApi() : restAPI);
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreOutboundPromotions storeOutboundPromotions) {
return storeOutboundPromotions.dispatcher;
}
public static final /* synthetic */ RestAPI access$getRestAPI$p(StoreOutboundPromotions storeOutboundPromotions) {
return storeOutboundPromotions.restAPI;
}
public static final /* synthetic */ State access$getState$p(StoreOutboundPromotions storeOutboundPromotions) {
return storeOutboundPromotions.state;
}
public static final /* synthetic */ int access$getUnseenCount(StoreOutboundPromotions storeOutboundPromotions, List list) {
return storeOutboundPromotions.getUnseenCount(list);
}
public static final /* synthetic */ void access$setState$p(StoreOutboundPromotions storeOutboundPromotions, State state) {
storeOutboundPromotions.state = state;
}
private final int getUnseenCount(List<OutboundPromotion> list) {
long j = getPrefs().getLong("LATEST_SEEN_PROMO_DATE", -1);
if ((list instanceof Collection) && list.isEmpty()) {
return 0;
}
int i = 0;
for (OutboundPromotion outboundPromotion : list) {
if ((outboundPromotion.h().f() > j) && (i = i + 1) < 0) {
n.throwCountOverflow();
}
}
return i;
}
public final Observable<ClaimedOutboundPromotion> claimOutboundPromotion(long j) {
return this.restAPI.claimOutboundPromotion(j);
}
public final Observable<List<ClaimedOutboundPromotion>> fetchClaimedOutboundPromotions() {
return this.restAPI.getClaimedOutboundPromotions();
}
public final State getState() {
return this.stateSnapshot;
}
public final int getUnseenCount() {
State state = getState();
if (!(state instanceof State.Loaded)) {
state = null;
}
State.Loaded loaded = (State.Loaded) state;
if (loaded != null) {
return loaded.getUnseenCount();
}
return 0;
}
@StoreThread
public final void handleConnectionOpen$app_productionBetaRelease(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "readyPayload");
UserUtils userUtils = UserUtils.INSTANCE;
User me2 = modelPayload.getMe();
m.checkNotNullExpressionValue(me2, "readyPayload.me");
if (userUtils.isPremium(new MeUser(me2))) {
this.state = State.Loading.INSTANCE;
markChanged();
RestAPI restAPI = this.restAPI;
Observable z2 = ObservableExtensionsKt.restSubscribeOn$default(this.previewFeatureFlag.isEnabled() ? restAPI.getAllPreviewPromotions() : restAPI.getAllActiveOutboundPromotions(), false, 1, null).z(new StoreOutboundPromotions$handleConnectionOpen$2(this));
m.checkNotNullExpressionValue(z2, "restAPI.run {\n if… }\n }");
ObservableExtensionsKt.appSubscribe$default(z2, StoreOutboundPromotions.class, (Context) null, (Function1) null, new StoreOutboundPromotions$handleConnectionOpen$3(this), (Function0) null, (Function0) null, new StoreOutboundPromotions$handleConnectionOpen$4(this), 54, (Object) null);
return;
}
this.state = new State.Loaded(n.emptyList(), 0);
markChanged();
}
public final void markSeen() {
this.dispatcher.schedule(new StoreOutboundPromotions$markSeen$1(this));
}
public final Observable<State> observeState() {
Observable<State> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreOutboundPromotions$observeState$1(this), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()");
return r;
}
public final Observable<Integer> observeUnseenCount() {
Observable<Integer> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreOutboundPromotions$observeUnseenCount$1(this), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()");
return r;
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
super.snapshotData();
this.stateSnapshot = this.state.deepCopy();
}
}