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

102 lines
4.3 KiB
Java

package com.discord.stores;
import com.discord.api.channel.Channel;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.time.Clock;
import d0.z.d.m;
import j0.l.a.c0;
import j0.l.e.j;
import java.util.HashMap;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/* compiled from: StoreSlowMode.kt */
public final class StoreSlowMode extends Store {
@Deprecated
private static final long COOLDOWN_BUFFER_MS = 1000;
private static final Companion Companion = new Companion(null);
private final HashMap<Long, Observable<Integer>> channelCooldownObservables = new HashMap<>();
private final Clock clock;
private final HashMap<Long, Long> nextSendTimes;
private final BehaviorSubject<HashMap<Long, Long>> nextSendTimesSubject;
private final StoreStream stream;
/* compiled from: StoreSlowMode.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public StoreSlowMode(Clock clock, StoreStream storeStream) {
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(storeStream, "stream");
this.clock = clock;
this.stream = storeStream;
HashMap<Long, Long> hashMap = new HashMap<>();
this.nextSendTimes = hashMap;
this.nextSendTimesSubject = BehaviorSubject.l0(new HashMap(hashMap));
}
public static final /* synthetic */ Clock access$getClock$p(StoreSlowMode storeSlowMode) {
return storeSlowMode.clock;
}
public static final /* synthetic */ BehaviorSubject access$getNextSendTimesSubject$p(StoreSlowMode storeSlowMode) {
return storeSlowMode.nextSendTimesSubject;
}
public static final /* synthetic */ Observable access$removeChannelCooldownObservable(StoreSlowMode storeSlowMode, long j) {
return storeSlowMode.removeChannelCooldownObservable(j);
}
private final synchronized Observable<Integer> getChannelCooldownObservable(long j) {
Observable<Integer> observable = this.channelCooldownObservables.get(Long.valueOf(j));
if (observable != null) {
return observable;
}
Observable<Integer> h02 = Observable.h0(new c0(this.stream.getPermissions$app_productionBetaRelease().observePermissionsForChannel(j).F(new StoreSlowMode$sam$rx_functions_Func1$0(new StoreSlowMode$getChannelCooldownObservable$newObservable$1(PermissionUtils.INSTANCE))).r().Y(new StoreSlowMode$getChannelCooldownObservable$newObservable$2(this, j)).F(StoreSlowMode$getChannelCooldownObservable$newObservable$3.INSTANCE).v(new StoreSlowMode$getChannelCooldownObservable$newObservable$4(this, j)).M(1)));
HashMap<Long, Observable<Integer>> hashMap = this.channelCooldownObservables;
Long valueOf = Long.valueOf(j);
m.checkNotNullExpressionValue(h02, "newObservable");
hashMap.put(valueOf, h02);
return h02;
}
@StoreThread
private final void onCooldownInternal(long j, long j2) {
this.nextSendTimes.put(Long.valueOf(j), Long.valueOf(this.clock.currentTimeMillis() + j2));
this.nextSendTimesSubject.onNext(new HashMap<>(this.nextSendTimes));
}
private final synchronized Observable<Integer> removeChannelCooldownObservable(long j) {
return this.channelCooldownObservables.remove(Long.valueOf(j));
}
public final Observable<Integer> getCooldownSecs(Long l) {
if (l != null) {
return getChannelCooldownObservable(l.longValue());
}
j jVar = new j(0);
m.checkNotNullExpressionValue(jVar, "Observable.just(0)");
return jVar;
}
@StoreThread
public final void onCooldown(long j, long j2) {
onCooldownInternal(j, j2 + 1000);
}
@StoreThread
public final void onMessageSent(long j) {
Channel findChannelByIdInternal$app_productionBetaRelease = this.stream.getChannels$app_productionBetaRelease().findChannelByIdInternal$app_productionBetaRelease(j);
int u = findChannelByIdInternal$app_productionBetaRelease != null ? findChannelByIdInternal$app_productionBetaRelease.u() : 0;
if (u > 0) {
onCooldownInternal(j, ((long) u) * 1000);
}
}
}