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

153 lines
5.5 KiB
Java

package com.discord.stores;
import androidx.annotation.VisibleForTesting;
import com.discord.utilities.lazy.subscriptions.GuildSubscriptionsManager;
import d0.d0.f;
import d0.t.n;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.List;
import kotlin.ranges.IntProgression;
import kotlin.ranges.IntRange;
/* compiled from: StoreGuildSubscriptions.kt */
public final class StoreGuildSubscriptions extends StoreV2 {
private final Dispatcher dispatcher;
private final StoreStream storeStream;
private final GuildSubscriptionsManager subscriptionsManager = new GuildSubscriptionsManager(new StoreGuildSubscriptions$subscriptionsManager$1(this));
/* compiled from: StoreGuildSubscriptions.kt */
@VisibleForTesting
public static final class RangeComputer {
private static final int DEFAULT_CHUNK_SIZE = 100;
public static final RangeComputer INSTANCE = new RangeComputer();
private RangeComputer() {
}
public static /* synthetic */ List computeRanges$default(RangeComputer rangeComputer, IntRange intRange, int i, int i2, Object obj) {
if ((i2 & 2) != 0) {
i = 100;
}
return rangeComputer.computeRanges(intRange, i);
}
public final List<IntRange> computeRanges(IntRange intRange, int i) {
m.checkNotNullParameter(intRange, "range");
ArrayList arrayList = new ArrayList(3);
int invoke = StoreGuildSubscriptions$RangeComputer$computeRanges$1.INSTANCE.invoke(intRange.getFirst(), i);
if (invoke > 0) {
arrayList.add(f.until(0, i));
}
IntProgression step = f.step(f.until(invoke, intRange.getLast()), i);
int first = step.getFirst();
int last = step.getLast();
int step2 = step.getStep();
if (step2 < 0 ? first >= last : first <= last) {
while (true) {
arrayList.add(f.until(first, first + i));
if (first == last) {
break;
}
first += step2;
}
}
return arrayList;
}
}
public StoreGuildSubscriptions(StoreStream storeStream, Dispatcher dispatcher) {
m.checkNotNullParameter(storeStream, "storeStream");
m.checkNotNullParameter(dispatcher, "dispatcher");
this.storeStream = storeStream;
this.dispatcher = dispatcher;
}
public static final /* synthetic */ StoreStream access$getStoreStream$p(StoreGuildSubscriptions storeGuildSubscriptions) {
return storeGuildSubscriptions.storeStream;
}
public static final /* synthetic */ GuildSubscriptionsManager access$getSubscriptionsManager$p(StoreGuildSubscriptions storeGuildSubscriptions) {
return storeGuildSubscriptions.subscriptionsManager;
}
@StoreThread
public final void handleConnectionReady(boolean z2) {
if (z2) {
long selectedGuildId = this.storeStream.getGuildSelected$app_productionBetaRelease().getSelectedGuildId();
if (selectedGuildId > 0) {
handleGuildSelect(selectedGuildId);
}
this.subscriptionsManager.queueExistingSubscriptions();
markChanged();
return;
}
this.subscriptionsManager.retainAll(n.listOf((Object[]) new Long[]{Long.valueOf(this.storeStream.getGuildSelected$app_productionBetaRelease().getSelectedGuildId()), Long.valueOf(this.storeStream.getRtcConnection$app_productionBetaRelease().getConnectedGuildId())}));
markChanged();
}
@StoreThread
public final void handleGuildRemove(long j) {
this.subscriptionsManager.remove(j);
markChanged();
}
@StoreThread
public final void handleGuildSelect(long j) {
if (j > 0) {
this.subscriptionsManager.subscribeTyping(j);
this.subscriptionsManager.subscribeActivities(j);
this.subscriptionsManager.subscribeThreads(j);
markChanged();
}
}
@StoreThread
public final void handlePreLogout() {
this.subscriptionsManager.reset();
markChanged();
}
@StoreThread
public final void handleSubscribeMember(long j, long j2) {
if (j > 0) {
this.subscriptionsManager.subscribeMember(j, j2);
markChanged();
}
}
@StoreThread
public final void handleUnsubscribeMember(long j, long j2) {
if (j > 0) {
this.subscriptionsManager.unsubscribeMember(j, j2);
markChanged();
}
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
super.snapshotData();
this.subscriptionsManager.flush();
}
public final void subscribeChannelRange(long j, long j2, IntRange intRange) {
m.checkNotNullParameter(intRange, "range");
if (j > 0 && j2 > 0) {
this.dispatcher.schedule(new StoreGuildSubscriptions$subscribeChannelRange$1(this, intRange, j, j2));
}
}
public final void subscribeThread(long j, long j2) {
if (j > 0 && j2 > 0) {
this.dispatcher.schedule(new StoreGuildSubscriptions$subscribeThread$1(this, j, j2));
}
}
public final void subscribeUser(long j, long j2) {
this.dispatcher.schedule(new StoreGuildSubscriptions$subscribeUser$1(this, j, j2));
}
public final void unsubscribeUser(long j, long j2) {
this.dispatcher.schedule(new StoreGuildSubscriptions$unsubscribeUser$1(this, j, j2));
}
}