237 lines
12 KiB
Java
237 lines
12 KiB
Java
package com.discord.utilities.premium;
|
|
|
|
import com.discord.api.guild.GuildFeature;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.models.domain.ModelSubscription;
|
|
import com.discord.models.domain.premium.SubscriptionPlanType;
|
|
import com.discord.models.experiments.domain.Experiment;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.stores.StoreExperiments;
|
|
import com.discord.stores.StoreGuildBoost;
|
|
import com.discord.stores.StoreGuilds;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.analytics.Traits;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import j0.p.a;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import rx.Observable;
|
|
/* compiled from: GuildBoostUtils.kt */
|
|
public final class GuildBoostUtils {
|
|
public static final int DEFAULT_GUILD_BOOST_GUILD_COUNT = 1;
|
|
public static final int DEFAULT_GUILD_BOOST_SLOT_COUNT = 1;
|
|
public static final int GUILD_BOOST_COOLDOWN_DAYS = 7;
|
|
public static final GuildBoostUtils INSTANCE = new GuildBoostUtils();
|
|
|
|
/* compiled from: GuildBoostUtils.kt */
|
|
public enum ModifyGuildBoostSlotResult {
|
|
SUCCESS,
|
|
FAILURE_MODIFYING_SLOT,
|
|
FAILURE_UPDATING_SUBSCRIPTION
|
|
}
|
|
|
|
private GuildBoostUtils() {
|
|
}
|
|
|
|
public static /* synthetic */ int calculatePercentToNextTier$default(GuildBoostUtils guildBoostUtils, long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds, int i3, Object obj) {
|
|
if ((i3 & 8) != 0) {
|
|
storeExperiments = StoreStream.Companion.getExperiments();
|
|
}
|
|
if ((i3 & 16) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
return guildBoostUtils.calculatePercentToNextTier(j, i, i2, storeExperiments, storeGuilds);
|
|
}
|
|
|
|
public static /* synthetic */ int calculateTotalProgress$default(GuildBoostUtils guildBoostUtils, long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds, int i3, Object obj) {
|
|
if ((i3 & 8) != 0) {
|
|
storeExperiments = StoreStream.Companion.getExperiments();
|
|
}
|
|
if ((i3 & 16) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
return guildBoostUtils.calculateTotalProgress(j, i, i2, storeExperiments, storeGuilds);
|
|
}
|
|
|
|
public static /* synthetic */ int getBoostTier$default(GuildBoostUtils guildBoostUtils, long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
storeExperiments = StoreStream.Companion.getExperiments();
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
return guildBoostUtils.getBoostTier(j, i, storeExperiments, storeGuilds);
|
|
}
|
|
|
|
public static /* synthetic */ int getBoostsRequiredForTier$default(GuildBoostUtils guildBoostUtils, long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
storeExperiments = StoreStream.Companion.getExperiments();
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
return guildBoostUtils.getBoostsRequiredForTier(j, i, storeExperiments, storeGuilds);
|
|
}
|
|
|
|
private final int getCurrentTierSubs(boolean z2, int i) {
|
|
if (i == 1) {
|
|
return 2;
|
|
}
|
|
if (i == 2) {
|
|
return z2 ? 5 : 7;
|
|
}
|
|
if (i != 3) {
|
|
return 0;
|
|
}
|
|
return z2 ? 7 : 14;
|
|
}
|
|
|
|
private final int getNextTierSubs(boolean z2, int i) {
|
|
return i != 1 ? i != 2 ? i != 3 ? 2 : 0 : z2 ? 7 : 14 : z2 ? 5 : 7;
|
|
}
|
|
|
|
private final Observable<ModifyGuildBoostSlotResult> modifyGuildBoostSlot(RestAPI restAPI, long j, ModelSubscription modelSubscription, boolean z2, StoreGuildBoost storeGuildBoost) {
|
|
Observable<ModifyGuildBoostSlotResult> z3 = (z2 ? restAPI.cancelSubscriptionSlot(j) : restAPI.uncancelSubscriptionSlot(j)).X(a.c()).t(new GuildBoostUtils$modifyGuildBoostSlot$1(storeGuildBoost)).F(GuildBoostUtils$modifyGuildBoostSlot$2.INSTANCE).L(GuildBoostUtils$modifyGuildBoostSlot$3.INSTANCE).z(new GuildBoostUtils$modifyGuildBoostSlot$4(restAPI, modelSubscription, z2));
|
|
m.checkNotNullExpressionValue(z3, "apiObs\n .subscrib…N }\n }\n }");
|
|
return z3;
|
|
}
|
|
|
|
public final List<ModelSubscription.SubscriptionAdditionalPlan> calculateAdditionalPlansWithGuildBoostAdjustment(ModelSubscription modelSubscription, int i) {
|
|
Object obj;
|
|
boolean z2;
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
|
ModelSubscription.SubscriptionRenewalMutations renewalMutations = modelSubscription.getRenewalMutations();
|
|
List<ModelSubscription.SubscriptionAdditionalPlan> premiumAdditionalPlans = renewalMutations == null ? modelSubscription.getPremiumAdditionalPlans() : renewalMutations.getPremiumAdditionalPlans();
|
|
Iterator<T> it = premiumAdditionalPlans.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
ModelSubscription.SubscriptionAdditionalPlan subscriptionAdditionalPlan = (ModelSubscription.SubscriptionAdditionalPlan) obj;
|
|
if (subscriptionAdditionalPlan.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_MONTH.getPlanId() || subscriptionAdditionalPlan.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_YEAR.getPlanId()) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
break;
|
|
}
|
|
}
|
|
ModelSubscription.SubscriptionAdditionalPlan subscriptionAdditionalPlan2 = (ModelSubscription.SubscriptionAdditionalPlan) obj;
|
|
int quantity = (subscriptionAdditionalPlan2 != null ? subscriptionAdditionalPlan2.getQuantity() : 0) + i;
|
|
if (quantity < 0 || subscriptionAdditionalPlan2 == null) {
|
|
AppLog appLog = AppLog.g;
|
|
Logger.e$default(appLog, "Error calculating additional_plans adjustment, new sub count:" + quantity, null, null, 6, null);
|
|
return modelSubscription.getPremiumAdditionalPlans();
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Object obj2 : premiumAdditionalPlans) {
|
|
ModelSubscription.SubscriptionAdditionalPlan subscriptionAdditionalPlan3 = (ModelSubscription.SubscriptionAdditionalPlan) obj2;
|
|
if ((subscriptionAdditionalPlan3.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_MONTH.getPlanId() || subscriptionAdditionalPlan3.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_YEAR.getPlanId()) ? false : true) {
|
|
arrayList.add(obj2);
|
|
}
|
|
}
|
|
return quantity == 0 ? arrayList : u.plus((Collection) arrayList, (Iterable) d0.t.m.listOf(new ModelSubscription.SubscriptionAdditionalPlan(subscriptionAdditionalPlan2.getPlanId(), quantity)));
|
|
}
|
|
|
|
public final int calculatePercentToNextTier(long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
Guild guild;
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
|
if (i >= 3) {
|
|
return 100;
|
|
}
|
|
boolean z2 = true;
|
|
Experiment guildExperiment = storeExperiments.getGuildExperiment("2022-02_boosting_tiers", j, true);
|
|
if (guildExperiment == null || guildExperiment.getBucket() != 1 || (guild = storeGuilds.getGuild(j)) == null || !guild.hasFeature(GuildFeature.EXPOSED_TO_BOOSTING_TIERS_EXPERIMENT)) {
|
|
z2 = false;
|
|
}
|
|
return d0.a0.a.roundToInt((((float) (i2 - getCurrentTierSubs(z2, i))) / ((float) getNextTierSubs(z2, i))) * ((float) 100));
|
|
}
|
|
|
|
public final int calculateTotalProgress(long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
Guild guild;
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
|
if (i >= 3) {
|
|
return 100;
|
|
}
|
|
boolean z2 = true;
|
|
Experiment guildExperiment = storeExperiments.getGuildExperiment("2022-02_boosting_tiers", j, true);
|
|
if (guildExperiment == null || guildExperiment.getBucket() != 1 || (guild = storeGuilds.getGuild(j)) == null || !guild.hasFeature(GuildFeature.EXPOSED_TO_BOOSTING_TIERS_EXPERIMENT)) {
|
|
z2 = false;
|
|
}
|
|
int nextTierSubs = getNextTierSubs(z2, i);
|
|
int currentTierSubs = getCurrentTierSubs(z2, i);
|
|
return d0.a0.a.roundToInt(((((float) (i2 - currentTierSubs)) / ((float) (nextTierSubs - currentTierSubs))) * 33.3f) + (((float) i) * 33.3f));
|
|
}
|
|
|
|
public final Observable<ModifyGuildBoostSlotResult> cancelGuildBoostSlot(RestAPI restAPI, long j, ModelSubscription modelSubscription, StoreGuildBoost storeGuildBoost) {
|
|
m.checkNotNullParameter(restAPI, "api");
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
|
m.checkNotNullParameter(storeGuildBoost, "storeGuildBoost");
|
|
return modifyGuildBoostSlot(restAPI, j, modelSubscription, true, storeGuildBoost);
|
|
}
|
|
|
|
public final int getBoostTier(long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
Guild guild;
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
|
Experiment guildExperiment = storeExperiments.getGuildExperiment("2022-02_boosting_tiers", j, true);
|
|
if (guildExperiment != null && guildExperiment.getBucket() == 1 && (guild = storeGuilds.getGuild(j)) != null && guild.hasFeature(GuildFeature.EXPOSED_TO_BOOSTING_TIERS_EXPERIMENT)) {
|
|
if (i >= 7) {
|
|
return 3;
|
|
}
|
|
if (i >= 5) {
|
|
return 2;
|
|
}
|
|
return i >= 2 ? 1 : 0;
|
|
} else if (i >= 14) {
|
|
return 3;
|
|
} else {
|
|
if (i >= 7) {
|
|
return 2;
|
|
}
|
|
return i >= 2 ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
public final int getBoostsRequiredForTier(long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
Guild guild;
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
|
Experiment guildExperiment = storeExperiments.getGuildExperiment("2022-02_boosting_tiers", j, true);
|
|
boolean z2 = guildExperiment != null && guildExperiment.getBucket() == 1 && (guild = storeGuilds.getGuild(j)) != null && guild.hasFeature(GuildFeature.EXPOSED_TO_BOOSTING_TIERS_EXPERIMENT);
|
|
if (i == 1) {
|
|
return 2;
|
|
}
|
|
if (i != 2) {
|
|
if (i != 3) {
|
|
return 0;
|
|
}
|
|
if (!z2) {
|
|
return 14;
|
|
}
|
|
} else if (z2) {
|
|
return 5;
|
|
}
|
|
return 7;
|
|
}
|
|
|
|
public final Observable<ModifyGuildBoostSlotResult> uncancelGuildBoostSlot(RestAPI restAPI, long j, ModelSubscription modelSubscription, StoreGuildBoost storeGuildBoost) {
|
|
m.checkNotNullParameter(restAPI, "api");
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
|
m.checkNotNullParameter(storeGuildBoost, "storeGuildBoost");
|
|
return modifyGuildBoostSlot(restAPI, j, modelSubscription, false, storeGuildBoost);
|
|
}
|
|
}
|