235 lines
12 KiB
Java
235 lines
12 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.api.utcdatetime.UtcDateTime;
|
||
|
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.time.ClockFactory;
|
||
|
import com.discord.utilities.user.UserUtils;
|
||
|
import d0.c0.c;
|
||
|
import d0.d0.f;
|
||
|
import d0.t.n;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
import kotlin.jvm.functions.Function0;
|
||
|
import kotlin.jvm.functions.Function1;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
import kotlin.ranges.LongRange;
|
||
|
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 long NO_PROMO_ID = -1;
|
||
|
private final Dispatcher dispatcher;
|
||
|
private final boolean isEnabled;
|
||
|
private final ObservationDeck observationDeck;
|
||
|
private final RestAPI restAPI;
|
||
|
private State state;
|
||
|
private State stateSnapshot;
|
||
|
private final List<OutboundPromotion> stubActivePromos;
|
||
|
private final List<ClaimedOutboundPromotion> stubClaimedPromos;
|
||
|
private final long stubConsumedPromoId;
|
||
|
|
||
|
/* 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 List<OutboundPromotion> validActivePromotions;
|
||
|
|
||
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
||
|
public Loaded(List<OutboundPromotion> list) {
|
||
|
super(null);
|
||
|
m.checkNotNullParameter(list, "validActivePromotions");
|
||
|
this.validActivePromotions = list;
|
||
|
}
|
||
|
|
||
|
/* 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, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
list = loaded.validActivePromotions;
|
||
|
}
|
||
|
return loaded.copy(list);
|
||
|
}
|
||
|
|
||
|
public final List<OutboundPromotion> component1() {
|
||
|
return this.validActivePromotions;
|
||
|
}
|
||
|
|
||
|
public final Loaded copy(List<OutboundPromotion> list) {
|
||
|
m.checkNotNullParameter(list, "validActivePromotions");
|
||
|
return new Loaded(list);
|
||
|
}
|
||
|
|
||
|
@Override // com.discord.stores.StoreOutboundPromotions.State
|
||
|
public Loaded deepCopy() {
|
||
|
return new Loaded(new ArrayList(this.validActivePromotions));
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (this != obj) {
|
||
|
return (obj instanceof Loaded) && m.areEqual(this.validActivePromotions, ((Loaded) obj).validActivePromotions);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public final List<OutboundPromotion> getValidActivePromotions() {
|
||
|
return this.validActivePromotions;
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
List<OutboundPromotion> list = this.validActivePromotions;
|
||
|
if (list != null) {
|
||
|
return list.hashCode();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
return a.E(a.L("Loaded(validActivePromotions="), this.validActivePromotions, ")");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* 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(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, boolean z2) {
|
||
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
||
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
||
|
m.checkNotNullParameter(restAPI, "restAPI");
|
||
|
this.dispatcher = dispatcher;
|
||
|
this.observationDeck = observationDeck;
|
||
|
this.restAPI = restAPI;
|
||
|
this.isEnabled = z2;
|
||
|
State.Loading loading = State.Loading.INSTANCE;
|
||
|
this.state = loading;
|
||
|
this.stateSnapshot = loading;
|
||
|
long currentTimeMillis = ClockFactory.get().currentTimeMillis();
|
||
|
TimeUnit timeUnit = TimeUnit.DAYS;
|
||
|
List<OutboundPromotion> listOf = n.listOf((Object[]) new OutboundPromotion[]{new OutboundPromotion(100, new UtcDateTime(timeUnit.toMillis(5) + currentTimeMillis), "Unclaimed promo 1 title", "This is unclaimed 1", "https://www.google.com", "https://www.google.com/{code}", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in pharetra nibh."), new OutboundPromotion(101, new UtcDateTime(timeUnit.toMillis(5) + ClockFactory.get().currentTimeMillis()), "Unclaimed promo 2 title", "This is unclaimed 2", "https://www.google.com", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in pharetra nibh."), new OutboundPromotion(103, new UtcDateTime(timeUnit.toMillis(3) + ClockFactory.get().currentTimeMillis()), "Claimed promo 1 title", "Claimed promo 1 body", "https://www.google.com", "https://www.google.com/{code}", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in pharetra nibh."), new OutboundPromotion(104, new UtcDateTime(timeUnit.toMillis(3) + ClockFactory.get().currentTimeMillis()), "Claimed promo 2 title", "Claimed promo 2 body", "https://www.google.com", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in pharetra nibh."), new OutboundPromotion(105, new UtcDateTime(timeUnit.toMillis(5) + ClockFactory.get().currentTimeMillis()), "Consumed promo 1 title", "Consumed promo 1 body", "https://www.google.com", "https://www.google.com/{code}", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in pharetra nibh.")});
|
||
|
this.stubActivePromos = listOf;
|
||
|
this.stubClaimedPromos = n.listOf((Object[]) new ClaimedOutboundPromotion[]{new ClaimedOutboundPromotion("PROMO CODE HERE", 999, new UtcDateTime(ClockFactory.get().currentTimeMillis() - timeUnit.toMillis(2)), listOf.get(2)), new ClaimedOutboundPromotion("PROMO CODE HERE", 999, new UtcDateTime(ClockFactory.get().currentTimeMillis() - timeUnit.toMillis(1)), listOf.get(3))});
|
||
|
this.stubConsumedPromoId = 105;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
||
|
public /* synthetic */ StoreOutboundPromotions(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 4) != 0 ? RestAPI.Companion.getApi() : restAPI, (i & 8) != 0 ? false : z2);
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreOutboundPromotions storeOutboundPromotions) {
|
||
|
return storeOutboundPromotions.dispatcher;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ State access$getState$p(StoreOutboundPromotions storeOutboundPromotions) {
|
||
|
return storeOutboundPromotions.state;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ List access$getStubActivePromos$p(StoreOutboundPromotions storeOutboundPromotions) {
|
||
|
return storeOutboundPromotions.stubActivePromos;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ List access$getStubClaimedPromos$p(StoreOutboundPromotions storeOutboundPromotions) {
|
||
|
return storeOutboundPromotions.stubClaimedPromos;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ long access$getStubConsumedPromoId$p(StoreOutboundPromotions storeOutboundPromotions) {
|
||
|
return storeOutboundPromotions.stubConsumedPromoId;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$setState$p(StoreOutboundPromotions storeOutboundPromotions, State state) {
|
||
|
storeOutboundPromotions.state = state;
|
||
|
}
|
||
|
|
||
|
public final Observable<List<ClaimedOutboundPromotion>> fetchClaimedOutboundPromotions() {
|
||
|
Observable<List<ClaimedOutboundPromotion>> r = Observable.D(new StoreOutboundPromotions$fetchClaimedOutboundPromotions$1(this)).r(f.random(new LongRange(0, 2000), c.b), TimeUnit.MILLISECONDS, j0.p.a.a());
|
||
|
m.checkNotNullExpressionValue(r, "Observable.fromCallable …Schedulers.computation())");
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
public final State getState() {
|
||
|
return this.stateSnapshot;
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleConnectionOpen$app_productionBetaRelease(ModelPayload modelPayload) {
|
||
|
m.checkNotNullParameter(modelPayload, "readyPayload");
|
||
|
if (this.isEnabled) {
|
||
|
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();
|
||
|
Observable A = Observable.D(new StoreOutboundPromotions$handleConnectionOpen$1(this)).r(f.random(new LongRange(0, 2000), c.b), TimeUnit.MILLISECONDS, j0.p.a.a()).Y(j0.p.a.a()).A(new StoreOutboundPromotions$handleConnectionOpen$2(this));
|
||
|
m.checkNotNullExpressionValue(A, "Observable.fromCallable … }\n }");
|
||
|
ObservableExtensionsKt.appSubscribe$default(A, 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());
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
public final Observable<State> observeState() {
|
||
|
Observable<State> s2 = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreOutboundPromotions$observeState$1(this), 14, null).s();
|
||
|
m.checkNotNullExpressionValue(s2, "observationDeck.connectR… .distinctUntilChanged()");
|
||
|
return s2;
|
||
|
}
|
||
|
|
||
|
@Override // com.discord.stores.StoreV2
|
||
|
public void snapshotData() {
|
||
|
super.snapshotData();
|
||
|
this.stateSnapshot = this.state.deepCopy();
|
||
|
}
|
||
|
}
|