// Metro module 11158 (f11159). import AuthenticationStore from "./AuthenticationStore"; import ChannelStore from "./ChannelStore"; import { SlowmodeType } from "./SlowmodeStore"; import { Endpoints } from "../Constants"; import Durations from "../utils/Durations"; import { FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID } from "../modules/channel/FakePlaceholderPrivateChannel"; import { HTTP } from "../_bundle/sendRequest"; import Dispatcher from "../Dispatcher"; import Module589 from "../_bundle/Module589"; let c7542_3, c7542_8, c7542_9, c7542_10, c7542_11, c7542_12, c7542_13, handleTypingStop; const handleTypingStart = function handleTypingStart({ channelId: channelId3, userId: userId2, guildId: guildId2 }) { let r15 = c7542_10[channelId3]; if (r15 == null) { r15 = c7542_12; } const r6 = { ...r15 }; clearTimeout(r6[userId2]); const channelId = channelId3; const userId = userId2; const guildId = guildId2; const r22 = setTimeout(() => { Dispatcher.dispatch({ type: "TYPING_STOP", channelId, userId, guildId }); }, c7542_8); r6[userId] = r22; c7542_10[channelId] = r6; if (guildId != null) { let r25 = c7542_11[guildId]; if (r25 == null) { r25 = c7542_13; } const r26 = { ...r25 }; let r11 = r26[channelId]; if (r11 == null) { r11 = c7542_12; } const r30 = { ...r11 }; clearTimeout(r30[userId]); r30[userId] = r22; r26[channelId] = r30; c7542_11[guildId] = r26; } }; handleTypingStop = function handleTypingStop({ channelId: channelId3, userId: userId2, guildId: guildId2 }) { const r15 = c7542_10[channelId3]; if (r15 != null && r15[userId2] != null) { const r10 = { ...r15 }; clearTimeout(r10[userId2]); delete r10[userId2]; c7542_10[channelId3] = r10; if (guildId2 != null) { const r22 = c7542_11[guildId2]; if (r22 != null) { const r23 = r22[channelId3]; if (r23 != null && r23[userId2] != null) { const r25 = { ...r23 }; delete r25[userId2]; const r30 = { ...r22 }; if (Object.keys(r25).length === 0) { delete r30[channelId3]; } else { r30[channelId3] = r25; } if (Object.keys(r30).length === 0) { delete c7542_11[guildId2]; } else { c7542_11[guildId2] = r30; } } } } return void 0; } return false; }; const handleConnectionOpen = function handleConnectionOpen() { c7542_10 = {}; c7542_11 = {}; }; c7542_8 = 10 * Durations.Millis.SECOND; c7542_9 = 1.5 * Durations.Millis.SECOND; c7542_10 = {}; c7542_11 = {}; c7542_12 = Object.freeze({}); c7542_13 = Object.freeze({}); class TypingStore extends Module589.Store { static displayName = "TypingStore"; initialize() { this.waitFor(AuthenticationStore, ChannelStore); } getTypingUsers(a0) { let r4 = c7542_10[a0]; if (r4 == null) { r4 = c7542_12; } return r4; } getTypingUsersByGuild(a0) { let r4 = c7542_11[a0]; if (r4 == null) { r4 = c7542_13; } return r4; } isTyping(a0, a1) { let r4 = c7542_10[a0]; if (r4 == null) { r4 = c7542_12; } return r4[a1] != null; } } const typingStore = new TypingStore(Dispatcher, { TYPING_START: handleTypingStart, TYPING_STOP: handleTypingStop, TYPING_START_LOCAL: function handleTypingStartLocal({ channelId: channelId2 }) { let r1, prevSend; const id = AuthenticationStore.getId(); if (id == null) { return false; } if (channelId2 === FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID) { return false; } if (c7542_3 != null && c7542_3.channelId !== channelId2) { if (c7542_3.timeout != null) { clearTimeout(c7542_3.timeout); } c7542_3 = null; } L11: { prevSend = Date.now(); r1 = 0.8 * c7542_8; if (c7542_3 != null) { if (c7542_3.timeout == null && !(c7542_3.prevSend + r1 > prevSend)) { break L11; } return false; } } c7542_3 = { channelId: channelId2, timeout: setTimeout(() => { if (c7542_3 != null && c7542_3.channelId === channelId2 && id === AuthenticationStore.getId() && c7542_3.timeout != null) { c7542_3.timeout = null; let r9 = c7542_10[channelId2]; if (r9 == null) { r9 = c7542_12; } if (!((r9 !== c7542_12 ? Object.keys(r9).length : 0) > 5)) { HTTP.post({ url: Endpoints.TYPING(channelId2), oldFormErrors: true, rejectWithError: true }).then((result) => { if (result.status === 200) { let message_send_cooldown_ms = result.body.message_send_cooldown_ms; if (message_send_cooldown_ms == null) { message_send_cooldown_ms = 0; } let thread_create_cooldown_ms = result.body.thread_create_cooldown_ms; if (thread_create_cooldown_ms == null) { thread_create_cooldown_ms = 0; } if (message_send_cooldown_ms > 0) { Dispatcher.dispatch({ type: "SLOWMODE_SET_COOLDOWN", channelId: channelId2, slowmodeType: SlowmodeType.SendMessage, cooldownMs: message_send_cooldown_ms }); } if (thread_create_cooldown_ms > 0) { Dispatcher.dispatch({ type: "SLOWMODE_SET_COOLDOWN", channelId: channelId2, slowmodeType: SlowmodeType.CreateThread, cooldownMs: thread_create_cooldown_ms }); } } }); } } }, c7542_3 != null ? c7542_3.prevSend > prevSend - 2 * r1 ? c7542_9 : 0 : c7542_9), prevSend }; const channel = ChannelStore.getChannel(channelId2); let guildId2 = channel == null ? void 0 : channel.getGuildId(); if (guildId2 == null) { guildId2 = void 0; } handleTypingStart({ channelId: channelId2, userId: id, guildId: guildId2 }); }, TYPING_STOP_LOCAL: function handleTypingStopLocal({ channelId: channelId3 }) { const id2 = AuthenticationStore.getId(); let r1 = id2 != null; if (r1) { let r0 = c7542_3 != null && c7542_3.channelId === channelId3 && c7542_3.timeout != null; if (r0) { clearTimeout(c7542_3.timeout); c7542_3 = null; const channel = ChannelStore.getChannel(channelId3); let guildId2 = channel == null ? void 0 : channel.getGuildId(); if (guildId2 == null) { guildId2 = void 0; } r0 = handleTypingStop({ channelId: channelId3, userId: id2, guildId: guildId2 }); } r1 = r0; } return r1; }, CONNECTION_OPEN: handleConnectionOpen, OVERLAY_INITIALIZE: handleConnectionOpen, MESSAGE_CREATE: function handleIncomingMessage(a0) { const channelId3 = a0.channelId; let guildId2 = a0.guildId; const author = a0.message.author; if (a0.optimistic && c7542_3 != null && c7542_3.channelId === channelId3) { if (c7542_3.timeout != null) { clearTimeout(c7542_3.timeout); } c7542_3 = null; } let r21 = author != null; if (r21) { if (guildId2 == null) { const channel = ChannelStore.getChannel(channelId3); let r28 = channel == null ? void 0 : channel.getGuildId(); if (r28 == null) { r28 = void 0; } guildId2 = r28; } r21 = handleTypingStop({ channelId: channelId3, userId: author.id, guildId: guildId2 }); } return r21; } }); export default typingStore;