2021-06-27 20:44:35 +00:00
|
|
|
package com.discord.utilities.premium;
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
import com.discord.api.guild.GuildFeature;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.app.AppLog;
|
|
|
|
import com.discord.models.domain.ModelSubscription;
|
|
|
|
import com.discord.models.domain.premium.SubscriptionPlanType;
|
2022-03-02 20:59:20 +00:00
|
|
|
import com.discord.models.experiments.domain.Experiment;
|
|
|
|
import com.discord.models.guild.Guild;
|
|
|
|
import com.discord.stores.StoreExperiments;
|
2021-12-21 23:37:30 +00:00
|
|
|
import com.discord.stores.StoreGuildBoost;
|
2022-03-02 20:59:20 +00:00
|
|
|
import com.discord.stores.StoreGuilds;
|
|
|
|
import com.discord.stores.StoreStream;
|
2021-08-09 22:50:01 +00:00
|
|
|
import com.discord.utilities.analytics.Traits;
|
2022-03-08 21:11:21 +00:00
|
|
|
import com.discord.utilities.guilds.GuildConstantsKt;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.utilities.logging.Logger;
|
|
|
|
import com.discord.utilities.rest.RestAPI;
|
2021-11-08 18:25:28 +00:00
|
|
|
import d0.t.u;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import j0.p.a;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import rx.Observable;
|
2021-12-21 23:37:30 +00:00
|
|
|
/* compiled from: GuildBoostUtils.kt */
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes2.dex */
|
2021-12-21 23:37:30 +00:00
|
|
|
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();
|
2021-06-27 20:44:35 +00:00
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
/* compiled from: GuildBoostUtils.kt */
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes2.dex */
|
2021-12-21 23:37:30 +00:00
|
|
|
public enum ModifyGuildBoostSlotResult {
|
2021-06-27 20:44:35 +00:00
|
|
|
SUCCESS,
|
|
|
|
FAILURE_MODIFYING_SLOT,
|
|
|
|
FAILURE_UPDATING_SUBSCRIPTION
|
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
private GuildBoostUtils() {
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-08 21:11:21 +00:00
|
|
|
private final GuildBoostTierAmounts getBoostTierAmounts(long j, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
|
|
Experiment guildExperiment = storeExperiments.getGuildExperiment("2022-03_boosting_tiers_small_guilds", j, true);
|
|
|
|
Experiment guildExperiment2 = storeExperiments.getGuildExperiment("2022-03_boosting_tiers_medium_guilds", j, true);
|
|
|
|
Guild guild = storeGuilds.getGuild(j);
|
|
|
|
boolean z2 = false;
|
|
|
|
boolean z3 = guild != null && guild.hasFeature(GuildFeature.BOOSTING_TIERS_EXPERIMENT_SMALL_GUILD);
|
|
|
|
Guild guild2 = storeGuilds.getGuild(j);
|
|
|
|
if (guild2 != null && guild2.hasFeature(GuildFeature.BOOSTING_TIERS_EXPERIMENT_MEDIUM_GUILD)) {
|
|
|
|
z2 = true;
|
|
|
|
}
|
|
|
|
return (!z3 || guildExperiment == null || guildExperiment.getBucket() != 1) ? (!z2 || guildExperiment2 == null || guildExperiment2.getBucket() != 1) ? GuildConstantsKt.getGUILD_BOOST_TIER_AMOUNTS() : GuildConstantsKt.getGUILD_BOOST_TIER_AMOUNTS_EXP_MEDIUM_GUILDS() : GuildConstantsKt.getGUILD_BOOST_TIER_AMOUNTS_EXP_SMALL_GUILDS();
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
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();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
if ((i2 & 8) != 0) {
|
|
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
return guildBoostUtils.getBoostsRequiredForTier(j, i, storeExperiments, storeGuilds);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 21:11:21 +00:00
|
|
|
private final int getCurrentTierSubs(GuildBoostTierAmounts guildBoostTierAmounts, int i) {
|
2021-06-27 20:44:35 +00:00
|
|
|
if (i == 1) {
|
2022-03-08 21:11:21 +00:00
|
|
|
return guildBoostTierAmounts.getTier1Boosts();
|
2022-03-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
if (i == 2) {
|
2022-03-08 21:11:21 +00:00
|
|
|
return guildBoostTierAmounts.getTier2Boosts();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
if (i != 3) {
|
|
|
|
return 0;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-08 21:11:21 +00:00
|
|
|
return guildBoostTierAmounts.getTier3Boosts();
|
2022-03-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 21:11:21 +00:00
|
|
|
private final int getNextTierSubs(GuildBoostTierAmounts guildBoostTierAmounts, int i) {
|
|
|
|
if (i == 1) {
|
|
|
|
return guildBoostTierAmounts.getTier2Boosts();
|
|
|
|
}
|
|
|
|
if (i == 2) {
|
|
|
|
return guildBoostTierAmounts.getTier3Boosts();
|
|
|
|
}
|
|
|
|
if (i != 3) {
|
|
|
|
return guildBoostTierAmounts.getTier1Boosts();
|
|
|
|
}
|
|
|
|
return 0;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
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));
|
2021-10-26 23:51:06 +00:00
|
|
|
m.checkNotNullExpressionValue(z3, "apiObs\n .subscrib…N }\n }\n }");
|
|
|
|
return z3;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
public final List<ModelSubscription.SubscriptionAdditionalPlan> calculateAdditionalPlansWithGuildBoostAdjustment(ModelSubscription modelSubscription, int i) {
|
2022-03-02 20:59:20 +00:00
|
|
|
Object obj;
|
2021-06-27 20:44:35 +00:00
|
|
|
boolean z2;
|
2021-08-09 22:50:01 +00:00
|
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
2021-06-27 20:44:35 +00:00
|
|
|
ModelSubscription.SubscriptionRenewalMutations renewalMutations = modelSubscription.getRenewalMutations();
|
2022-03-02 20:59:20 +00:00
|
|
|
List<ModelSubscription.SubscriptionAdditionalPlan> premiumAdditionalPlans = renewalMutations == null ? modelSubscription.getPremiumAdditionalPlans() : renewalMutations.getPremiumAdditionalPlans();
|
|
|
|
Iterator<T> it = premiumAdditionalPlans.iterator();
|
|
|
|
while (true) {
|
|
|
|
if (!it.hasNext()) {
|
|
|
|
obj = null;
|
|
|
|
break;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
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;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
ModelSubscription.SubscriptionAdditionalPlan subscriptionAdditionalPlan2 = (ModelSubscription.SubscriptionAdditionalPlan) obj;
|
|
|
|
int quantity = (subscriptionAdditionalPlan2 != null ? subscriptionAdditionalPlan2.getQuantity() : 0) + i;
|
|
|
|
if (quantity < 0 || subscriptionAdditionalPlan2 == null) {
|
2021-06-27 20:44:35 +00:00
|
|
|
AppLog appLog = AppLog.g;
|
|
|
|
Logger.e$default(appLog, "Error calculating additional_plans adjustment, new sub count:" + quantity, null, null, 6, null);
|
2021-07-13 20:48:29 +00:00
|
|
|
return modelSubscription.getPremiumAdditionalPlans();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
ArrayList arrayList = new ArrayList();
|
2022-03-02 20:59:20 +00:00
|
|
|
for (Object obj2 : premiumAdditionalPlans) {
|
|
|
|
ModelSubscription.SubscriptionAdditionalPlan subscriptionAdditionalPlan3 = (ModelSubscription.SubscriptionAdditionalPlan) obj2;
|
2021-06-27 20:44:35 +00:00
|
|
|
if ((subscriptionAdditionalPlan3.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_MONTH.getPlanId() || subscriptionAdditionalPlan3.getPlanId() == SubscriptionPlanType.PREMIUM_GUILD_YEAR.getPlanId()) ? false : true) {
|
2022-03-02 20:59:20 +00:00
|
|
|
arrayList.add(obj2);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
return quantity == 0 ? arrayList : u.plus((Collection) arrayList, (Iterable) d0.t.m.listOf(new ModelSubscription.SubscriptionAdditionalPlan(subscriptionAdditionalPlan2.getPlanId(), quantity)));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
public final int calculatePercentToNextTier(long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
2021-06-27 20:44:35 +00:00
|
|
|
if (i >= 3) {
|
|
|
|
return 100;
|
|
|
|
}
|
2022-03-08 21:11:21 +00:00
|
|
|
GuildBoostTierAmounts boostTierAmounts = getBoostTierAmounts(j, storeExperiments, storeGuilds);
|
|
|
|
return d0.a0.a.roundToInt(((i2 - getCurrentTierSubs(boostTierAmounts, i)) / getNextTierSubs(boostTierAmounts, i)) * 100);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
public final int calculateTotalProgress(long j, int i, int i2, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
2021-06-27 20:44:35 +00:00
|
|
|
if (i >= 3) {
|
|
|
|
return 100;
|
|
|
|
}
|
2022-03-08 21:11:21 +00:00
|
|
|
GuildBoostTierAmounts boostTierAmounts = getBoostTierAmounts(j, storeExperiments, storeGuilds);
|
|
|
|
int nextTierSubs = getNextTierSubs(boostTierAmounts, i);
|
|
|
|
int currentTierSubs = getCurrentTierSubs(boostTierAmounts, i);
|
2022-03-02 20:59:20 +00:00
|
|
|
return d0.a0.a.roundToInt((((i2 - currentTierSubs) / (nextTierSubs - currentTierSubs)) * 33.3f) + (i * 33.3f));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
public final Observable<ModifyGuildBoostSlotResult> cancelGuildBoostSlot(RestAPI restAPI, long j, ModelSubscription modelSubscription, StoreGuildBoost storeGuildBoost) {
|
2021-06-27 20:44:35 +00:00
|
|
|
m.checkNotNullParameter(restAPI, "api");
|
2021-08-09 22:50:01 +00:00
|
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
2021-12-21 23:37:30 +00:00
|
|
|
m.checkNotNullParameter(storeGuildBoost, "storeGuildBoost");
|
|
|
|
return modifyGuildBoostSlot(restAPI, j, modelSubscription, true, storeGuildBoost);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
public final int getBoostTier(long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
2022-03-08 21:11:21 +00:00
|
|
|
GuildBoostTierAmounts boostTierAmounts = getBoostTierAmounts(j, storeExperiments, storeGuilds);
|
|
|
|
if (i >= boostTierAmounts.getTier3Boosts()) {
|
2021-06-27 20:44:35 +00:00
|
|
|
return 3;
|
|
|
|
}
|
2022-03-08 21:11:21 +00:00
|
|
|
if (i >= boostTierAmounts.getTier2Boosts()) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return i >= boostTierAmounts.getTier1Boosts() ? 1 : 0;
|
2022-03-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final int getBoostsRequiredForTier(long j, int i, StoreExperiments storeExperiments, StoreGuilds storeGuilds) {
|
|
|
|
m.checkNotNullParameter(storeExperiments, "storeExperiments");
|
|
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
2022-03-08 21:11:21 +00:00
|
|
|
GuildBoostTierAmounts boostTierAmounts = getBoostTierAmounts(j, storeExperiments, storeGuilds);
|
2022-03-02 20:59:20 +00:00
|
|
|
if (i == 1) {
|
2022-03-08 21:11:21 +00:00
|
|
|
return boostTierAmounts.getTier1Boosts();
|
2021-08-24 17:45:16 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
if (i == 2) {
|
2022-03-08 21:11:21 +00:00
|
|
|
return boostTierAmounts.getTier2Boosts();
|
2022-03-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
if (i != 3) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-03-08 21:11:21 +00:00
|
|
|
return boostTierAmounts.getTier3Boosts();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
public final Observable<ModifyGuildBoostSlotResult> uncancelGuildBoostSlot(RestAPI restAPI, long j, ModelSubscription modelSubscription, StoreGuildBoost storeGuildBoost) {
|
2021-06-27 20:44:35 +00:00
|
|
|
m.checkNotNullParameter(restAPI, "api");
|
2021-08-09 22:50:01 +00:00
|
|
|
m.checkNotNullParameter(modelSubscription, Traits.Payment.Type.SUBSCRIPTION);
|
2021-12-21 23:37:30 +00:00
|
|
|
m.checkNotNullParameter(storeGuildBoost, "storeGuildBoost");
|
|
|
|
return modifyGuildBoostSlot(restAPI, j, modelSubscription, false, storeGuildBoost);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|