// Metro module 5718 (f5719). import ChannelStore from "../../stores/ChannelStore"; import GuildMemberCountStore from "../../stores/GuildMemberCountStore"; import NetworkStore from "../../stores/NetworkStore"; import { AnalyticEvents } from "../../Constants"; import Logger from "../debug/Logger"; import { getSignalStrength } from "../network/NetStats.android"; import AnalyticsUtils from "../../utils/AnalyticsUtils"; import getDeviceMetadata_native from "../device/getDeviceMetadata.native"; import Module589 from "../../_bundle/Module589"; import Dispatcher from "../../Dispatcher"; let c3547_7, c3547_9; const trackRoundtrip = function trackRoundtrip(a0) { const basicChannel = ChannelStore.getBasicChannel(a0.channelId); if (basicChannel != null) { if (!(Math.random() > 0.1)) { const api_latency_ms = a0.apiResponseTimestamp == null ? null : a0.apiResponseTimestamp - a0.initialSendTimestamp; const gateway_latency_ms = a0.gatewaySeenTimestamp == null ? null : a0.gatewaySeenTimestamp - a0.initialSendTimestamp; const signalStrength = getSignalStrength(); AnalyticsUtils.track(AnalyticEvents.SEND_MESSAGE_ROUNDTRIP, { ...getDeviceMetadata_native(), api_latency_ms, gateway_latency_ms, channel_id: basicChannel.id, channel_type: basicChannel.type, guild_id: basicChannel.guild_id, guild_size: GuildMemberCountStore.getMemberCount(basicChannel.guild_id), mobile_network_type: NetworkStore.getType(), num_attachments: a0.attachmentCount, ...signalStrength != null && { mobile_signal_strength_level: signalStrength } }); } } else { c3547_7.warn(`Ignoring a messageData for channel ${a0.channelId} because we can't find that channel.`); } }; c3547_7 = new Logger("MessageRoundtripTrackerStore"); class MessageRoundtripTrackerStoreClass extends Module589.Store { pendingMessages = new Map(); initialize() { this.waitFor(ChannelStore, GuildMemberCountStore, NetworkStore); } recordMessageSendAttempt(a0, a1) { let r5 = arguments[2]; if (r5 === void 0) { r5 = {}; } let r7 = r5.attachments?.length; if (r7 == null) { r7 = 0; } let r15 = r5.attachmentsToUpload?.length; if (r15 == null) { r15 = 0; } const attachmentCount = r7 + r15; this.pendingMessages.set(a1, { initialSendTimestamp: Date.now(), apiResponseTimestamp: null, gatewaySeenTimestamp: null, channelId: a0, attachmentCount }); setTimeout(() => { const pendingMessages = this.pendingMessages; const r7 = pendingMessages.get(a1); if (r7 != null) { trackRoundtrip(r7); this.pendingMessages.delete(a1); } }, 30000); } recordMessageSendApiResponse(a0) { const r10 = this.pendingMessages.get(a0); if (r10 != null) { const r11 = { ...r10, apiResponseTimestamp: Date.now() }; if (r11.apiResponseTimestamp != null && r11.gatewaySeenTimestamp != null) { trackRoundtrip(r11); this.pendingMessages.delete(a0); } else { this.pendingMessages.set(a0, r11); } } } recordGatewayResponse(a0) { const r10 = this.pendingMessages.get(a0); if (r10 != null) { const r11 = { ...r10, gatewaySeenTimestamp: Date.now() }; if (r11.apiResponseTimestamp != null && r11.gatewaySeenTimestamp != null) { trackRoundtrip(r11); this.pendingMessages.delete(a0); } else { this.pendingMessages.set(a0, r11); } } } } c3547_9 = new MessageRoundtripTrackerStoreClass(Dispatcher, { MESSAGE_CREATE: function handleMessageCreate(a0) { let optimistic = a0.optimistic; const nonce = a0.message.nonce; if (!optimistic) { optimistic = nonce == null; } if (!optimistic) { c3547_9.recordGatewayResponse(nonce); } } }); export default c3547_9;