164 lines
7.3 KiB
Java
164 lines
7.3 KiB
Java
package com.discord.stores;
|
|
|
|
import com.discord.api.channel.Channel;
|
|
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>> channelMessageSendCooldownObservables = new HashMap<>();
|
|
private final HashMap<Long, Observable<Integer>> channelThreadCreateCooldownObservables = new HashMap<>();
|
|
private final Clock clock;
|
|
private final HashMap<Long, Long> messageSendNextSendTimes;
|
|
private final BehaviorSubject<HashMap<Long, Long>> messageSendNextSendTimesSubject;
|
|
private final StoreStream stream;
|
|
private final HashMap<Long, Long> threadCreateNextSendTimes;
|
|
private final BehaviorSubject<HashMap<Long, Long>> threadCreateNextSendTimesSubject;
|
|
|
|
/* compiled from: StoreSlowMode.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreSlowMode.kt */
|
|
public static abstract class Type {
|
|
|
|
/* compiled from: StoreSlowMode.kt */
|
|
public static final class MessageSend extends Type {
|
|
public static final MessageSend INSTANCE = new MessageSend();
|
|
|
|
private MessageSend() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreSlowMode.kt */
|
|
public static final class ThreadCreate extends Type {
|
|
public static final ThreadCreate INSTANCE = new ThreadCreate();
|
|
|
|
private ThreadCreate() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private Type() {
|
|
}
|
|
|
|
public /* synthetic */ Type(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.messageSendNextSendTimes = hashMap;
|
|
this.messageSendNextSendTimesSubject = BehaviorSubject.k0(new HashMap(hashMap));
|
|
HashMap<Long, Long> hashMap2 = new HashMap<>();
|
|
this.threadCreateNextSendTimes = hashMap2;
|
|
this.threadCreateNextSendTimesSubject = BehaviorSubject.k0(new HashMap(hashMap2));
|
|
}
|
|
|
|
public static final /* synthetic */ Clock access$getClock$p(StoreSlowMode storeSlowMode) {
|
|
return storeSlowMode.clock;
|
|
}
|
|
|
|
public static final /* synthetic */ BehaviorSubject access$getMessageSendNextSendTimesSubject$p(StoreSlowMode storeSlowMode) {
|
|
return storeSlowMode.messageSendNextSendTimesSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ BehaviorSubject access$getThreadCreateNextSendTimesSubject$p(StoreSlowMode storeSlowMode) {
|
|
return storeSlowMode.threadCreateNextSendTimesSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ Observable access$removeChannelCooldownObservable(StoreSlowMode storeSlowMode, long j, Type type) {
|
|
return storeSlowMode.removeChannelCooldownObservable(j, type);
|
|
}
|
|
|
|
private final synchronized Observable<Integer> getChannelCooldownObservable(long j, Type type) {
|
|
Type.MessageSend messageSend = Type.MessageSend.INSTANCE;
|
|
Observable<Integer> observable = m.areEqual(type, messageSend) ? this.channelMessageSendCooldownObservables.get(Long.valueOf(j)) : this.channelThreadCreateCooldownObservables.get(Long.valueOf(j));
|
|
if (observable != null) {
|
|
return observable;
|
|
}
|
|
Observable<Integer> g02 = Observable.g0(new c0(this.stream.getPermissions$app_productionBetaRelease().observePermissionsForChannel(j).F(new StoreSlowMode$getChannelCooldownObservable$newObservable$1(type)).r().X(new StoreSlowMode$getChannelCooldownObservable$newObservable$2(this, type, j)).F(StoreSlowMode$getChannelCooldownObservable$newObservable$3.INSTANCE).v(new StoreSlowMode$getChannelCooldownObservable$newObservable$4(this, j, type)).M(1)));
|
|
if (m.areEqual(type, messageSend)) {
|
|
HashMap<Long, Observable<Integer>> hashMap = this.channelMessageSendCooldownObservables;
|
|
Long valueOf = Long.valueOf(j);
|
|
m.checkNotNullExpressionValue(g02, "newObservable");
|
|
hashMap.put(valueOf, g02);
|
|
} else {
|
|
HashMap<Long, Observable<Integer>> hashMap2 = this.channelThreadCreateCooldownObservables;
|
|
Long valueOf2 = Long.valueOf(j);
|
|
m.checkNotNullExpressionValue(g02, "newObservable");
|
|
hashMap2.put(valueOf2, g02);
|
|
}
|
|
return g02;
|
|
}
|
|
|
|
@StoreThread
|
|
private final void onCooldownInternal(long j, long j2, Type type) {
|
|
if (m.areEqual(type, Type.MessageSend.INSTANCE)) {
|
|
this.messageSendNextSendTimes.put(Long.valueOf(j), Long.valueOf(this.clock.currentTimeMillis() + j2));
|
|
this.messageSendNextSendTimesSubject.onNext(new HashMap<>(this.messageSendNextSendTimes));
|
|
return;
|
|
}
|
|
this.threadCreateNextSendTimes.put(Long.valueOf(j), Long.valueOf(this.clock.currentTimeMillis() + j2));
|
|
this.threadCreateNextSendTimesSubject.onNext(new HashMap<>(this.threadCreateNextSendTimes));
|
|
}
|
|
|
|
private final synchronized Observable<Integer> removeChannelCooldownObservable(long j, Type type) {
|
|
return m.areEqual(type, Type.MessageSend.INSTANCE) ? this.channelMessageSendCooldownObservables.remove(Long.valueOf(j)) : this.channelThreadCreateCooldownObservables.remove(Long.valueOf(j));
|
|
}
|
|
|
|
public final Observable<Integer> observeCooldownSecs(Long l, Type type) {
|
|
m.checkNotNullParameter(type, "type");
|
|
if (l != null) {
|
|
return getChannelCooldownObservable(l.longValue(), type);
|
|
}
|
|
j jVar = new j(0);
|
|
m.checkNotNullExpressionValue(jVar, "Observable.just(0)");
|
|
return jVar;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void onCooldown(long j, long j2, Type type) {
|
|
m.checkNotNullParameter(type, "type");
|
|
onCooldownInternal(j, j2 + 1000, type);
|
|
}
|
|
|
|
@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, Type.MessageSend.INSTANCE);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void onThreadCreated(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, Type.ThreadCreate.INSTANCE);
|
|
}
|
|
}
|
|
}
|