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> channelMessageSendCooldownObservables = new HashMap<>(); private final HashMap> channelThreadCreateCooldownObservables = new HashMap<>(); private final Clock clock; private final HashMap messageSendNextSendTimes; private final BehaviorSubject> messageSendNextSendTimesSubject; private final StoreStream stream; private final HashMap threadCreateNextSendTimes; private final BehaviorSubject> 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 hashMap = new HashMap<>(); this.messageSendNextSendTimes = hashMap; this.messageSendNextSendTimesSubject = BehaviorSubject.l0(new HashMap(hashMap)); HashMap hashMap2 = new HashMap<>(); this.threadCreateNextSendTimes = hashMap2; this.threadCreateNextSendTimesSubject = BehaviorSubject.l0(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 getChannelCooldownObservable(long j, Type type) { Type.MessageSend messageSend = Type.MessageSend.INSTANCE; Observable observable = m.areEqual(type, messageSend) ? this.channelMessageSendCooldownObservables.get(Long.valueOf(j)) : this.channelThreadCreateCooldownObservables.get(Long.valueOf(j)); if (observable != null) { return observable; } Observable h02 = Observable.h0(new c0(this.stream.getPermissions$app_productionBetaRelease().observePermissionsForChannel(j).F(new StoreSlowMode$getChannelCooldownObservable$newObservable$1(type)).r().Y(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> hashMap = this.channelMessageSendCooldownObservables; Long valueOf = Long.valueOf(j); m.checkNotNullExpressionValue(h02, "newObservable"); hashMap.put(valueOf, h02); } else { HashMap> hashMap2 = this.channelThreadCreateCooldownObservables; Long valueOf2 = Long.valueOf(j); m.checkNotNullExpressionValue(h02, "newObservable"); hashMap2.put(valueOf2, h02); } return h02; } @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 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 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); } } }