124 lines
4.2 KiB
TypeScript
124 lines
4.2 KiB
TypeScript
// Metro module 5971 (f5972).
|
|
import ChannelStore from "./ChannelStore";
|
|
import PermissionStore from "./PermissionStore";
|
|
import { canBypassSlowmode } from "../modules/chat/SlowmodeUtils";
|
|
import { Timeout } from "../_bundle/Timeout";
|
|
import Dispatcher from "../Dispatcher";
|
|
import Durations from "../utils/Durations";
|
|
import Module589 from "../_bundle/Module589";
|
|
let c3767_5, c3767_6;
|
|
const setCooldown = function setCooldown(channel, slowmodeType2, a2) {
|
|
let c15336_2;
|
|
const slowmodeType = slowmodeType2;
|
|
if (c3767_6[slowmodeType2][channel.id] != null) {
|
|
c3767_6[slowmodeType2][channel.id].timer.stop();
|
|
delete c3767_6[slowmodeType2][channel.id];
|
|
}
|
|
if (!canBypassSlowmode(channel) && !(a2 <= 0)) {
|
|
const cooldownEndTimestamp = a2 + Date.now();
|
|
c15336_2 = cooldownEndTimestamp;
|
|
c3767_6[slowmodeType2][channel.id] = {
|
|
rateLimitPerUser: channel.rateLimitPerUser,
|
|
cooldownMs: a2,
|
|
cooldownEndTimestamp,
|
|
timer: new Timeout()
|
|
};
|
|
c3767_6[slowmodeType2][channel.id].timer.start(1000, () => {
|
|
Dispatcher.dispatch({
|
|
type: "SLOWMODE_SET_COOLDOWN",
|
|
channelId: channel.id,
|
|
slowmodeType,
|
|
cooldownMs: Math.max(c15336_2 - Date.now(), 0)
|
|
});
|
|
}, true);
|
|
}
|
|
};
|
|
const handleUploadCancel = function handleUploadCancel(a0) {
|
|
const channel = ChannelStore.getChannel(a0.channelId);
|
|
let r9 = channel != null;
|
|
if (r9) {
|
|
setCooldown(channel, c3767_5.SendMessage, 0);
|
|
r9 = void 0;
|
|
}
|
|
return r9;
|
|
};
|
|
c3767_5 = {
|
|
SendMessage: 0,
|
|
0: "SendMessage",
|
|
CreateThread: 1,
|
|
1: "CreateThread"
|
|
};
|
|
const r28 = {};
|
|
r28[c3767_5.SendMessage] = {};
|
|
r28[c3767_5.CreateThread] = {};
|
|
c3767_6 = r28;
|
|
class SlowmodeStore extends Module589.Store {
|
|
static displayName = "SlowmodeStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, PermissionStore);
|
|
}
|
|
getSlowmodeCooldownGuess(a0, a1) {
|
|
const r7 = c3767_6[a1 == null ? c3767_5.SendMessage : a1][a0];
|
|
return r7 != null ? r7.cooldownMs : 0;
|
|
}
|
|
isChannelOnCooldown(a0, a1) {
|
|
return this.getSlowmodeCooldownGuess(a0.id, a1) > 0 && a0.rateLimitPerUser > 0;
|
|
}
|
|
}
|
|
const slowmodeStore = new SlowmodeStore(Dispatcher, {
|
|
SLOWMODE_RESET_COOLDOWN: function handleSlowmodeResetCooldown({ channelId, slowmodeType: slowmodeType2 }) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const r4 = channel == null;
|
|
let r13 = false;
|
|
if (!r4) {
|
|
setCooldown(channel, slowmodeType2, channel.rateLimitPerUser !== 0 ? channel.rateLimitPerUser * Durations.Millis.SECOND + 100 : 0);
|
|
r13 = void 0;
|
|
}
|
|
return r13;
|
|
},
|
|
SLOWMODE_SET_COOLDOWN: function handleSlowmodeSetCooldown({ channelId, slowmodeType: slowmodeType2, cooldownMs }) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
if (channel == null) {
|
|
return false;
|
|
}
|
|
setCooldown(channel, slowmodeType2, cooldownMs !== 0 ? cooldownMs + 100 : 0);
|
|
},
|
|
UPLOAD_START: function handleUploadStart({ channelId }) {
|
|
const SendMessage = c3767_5.SendMessage;
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const r4 = channel == null;
|
|
let r14 = false;
|
|
if (!r4) {
|
|
setCooldown(channel, SendMessage, channel.rateLimitPerUser !== 0 ? channel.rateLimitPerUser * Durations.Millis.SECOND + 100 : 0);
|
|
r14 = void 0;
|
|
}
|
|
return r14;
|
|
},
|
|
UPLOAD_FAIL: handleUploadCancel,
|
|
UPLOAD_CANCEL_REQUEST: handleUploadCancel,
|
|
CHANNEL_UPDATES: function handleUpdateCooldown({ channels }) {
|
|
[c3767_5.SendMessage, c3767_5.CreateThread].forEach((item) => {
|
|
for (const channel of channels) {
|
|
const r39 = c3767_6[item][channel.id];
|
|
const rateLimitPerUser = channel.rateLimitPerUser;
|
|
if (r39 != null && r39.rateLimitPerUser !== rateLimitPerUser) {
|
|
const r16 = Math;
|
|
let r14 = r39?.cooldownMs;
|
|
if (r14 == null) {
|
|
r14 = 0;
|
|
}
|
|
setCooldown(channel, item, r16.min(r14, rateLimitPerUser * Durations.Millis.SECOND));
|
|
}
|
|
}
|
|
});
|
|
},
|
|
LOGOUT: function clear() {
|
|
[c3767_5.SendMessage, c3767_5.CreateThread].forEach((a0) => {
|
|
Object.keys(c3767_6[a0]).forEach((item) => c3767_6[a0][item].timer.stop());
|
|
c3767_6[a0] = {};
|
|
});
|
|
}
|
|
});
|
|
export default slowmodeStore;
|
|
export { c3767_5 as SlowmodeType };
|