decord/alpha/source/modules/messages/MessageRoundtripTrackerStore.tsx

161 lines
6 KiB
TypeScript
Raw Normal View History

2026-10-09 10:00:15 +00:00
// Module ID: 7174
// Function ID: 7175
// Name: MessageRoundtripTrackerStore
2026-10-09 10:00:15 +00:00
// Dependencies: [2064, 4981, 5281, 1085, 3, 7175, 1265, 7358, 504, 584, 2]
2026-07-20 16:05:17 +00:00
2026-10-09 10:00:15 +00:00
// Module 7174 (MessageRoundtripTrackerStore)
import LoggerDefault from "Logger" /* 3 */;
2026-10-03 08:58:59 +00:00
import get_initializedDefault from "get initialized" /* 504 */;
import DispatcherDefault from "Dispatcher" /* 584 */;
import Constants from "Constants" /* 1085 */;
2026-10-09 10:00:15 +00:00
import AnalyticsUtilsDefault from "AnalyticsUtils" /* 1265 */;
import NetStats from "NetStats" /* 7175 */;
import getDeviceMetadataDefault from "getDeviceMetadata" /* 7358 */;
import ChannelStore from "ChannelStore" /* 2064 */;
import GuildMemberCountStore from "GuildMemberCountStore" /* 4981 */;
import NetworkStore from "NetworkStore" /* 5281 */;
2026-10-03 08:58:59 +00:00
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-07-20 16:05:17 +00:00
function trackRoundtrip(channelId) {
const basicChannel = ChannelStore.getBasicChannel(channelId.channelId);
2026-07-20 16:05:17 +00:00
if (null != basicChannel) {
const _Math = Math;
if (Math.random() <= 0.1) {
let diff = null;
if (null != channelId.apiResponseTimestamp) {
diff = channelId.apiResponseTimestamp - channelId.initialSendTimestamp;
}
let diff1 = null;
if (null != channelId.gatewaySeenTimestamp) {
diff1 = channelId.gatewaySeenTimestamp - channelId.initialSendTimestamp;
}
2026-10-03 08:58:59 +00:00
const obj = NetStats;
const signalStrength = obj.getSignalStrength();
const obj3 = { api_latency_ms: diff, gateway_latency_ms: diff1, guild_size: GuildMemberCountStore.getMemberCount(basicChannel.guild_id), mobile_network_type: NetworkStore.getType(), num_attachments: channelId.attachmentCount };
const track = AnalyticsUtilsDefault.track;
const SEND_MESSAGE_ROUNDTRIP = AnalyticEvents.SEND_MESSAGE_ROUNDTRIP;
AnalyticsUtilsDefault;
2026-08-24 06:08:38 +00:00
const merged = Object.assign(getDeviceMetadataDefault());
2026-10-03 08:58:59 +00:00
({ id: obj2.channel_id, type: obj2.channel_type, guild_id: obj2.guild_id } = basicChannel);
let tmp18 = null != signalStrength;
if (tmp18) {
tmp18 = { mobile_signal_strength_level: signalStrength };
const obj5 = { mobile_signal_strength_level: signalStrength };
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const merged1 = Object.assign(tmp18);
track(SEND_MESSAGE_ROUNDTRIP, obj3);
2026-07-20 16:05:17 +00:00
}
} else {
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
logger.warn("Ignoring a messageData for channel " + channelId.channelId + " because we can't find that channel.");
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
const AnalyticEvents = Constants.AnalyticEvents;
let tmp2 = new LoggerDefault("MessageRoundtripTrackerStore");
const logger = tmp2;
const Store = get_initializedDefault.Store;
2026-07-29 08:29:29 +00:00
class MessageRoundtripTrackerStoreClass extends Store {
constructor() {
2026-10-03 08:58:59 +00:00
const applyArgumentsResult = HermesBuiltin.applyArguments(this, new.target);
applyArgumentsResult.pendingMessages = new Map();
new Map();
2026-07-29 08:29:29 +00:00
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
initialize() {
this.waitFor(ChannelStore, GuildMemberCountStore, NetworkStore);
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
recordMessageSendAttempt(channelId, arg1, arg2) {
const self = this;
let closure_0 = arg1;
let obj = arg2;
if (arg2 === undefined) {
obj = {};
}
const attachments = obj.attachments;
let num;
if (attachments != null) {
num = attachments.length;
}
if (num == null) {
num = 0;
}
const attachmentsToUpload = obj.attachmentsToUpload;
let num2;
if (attachmentsToUpload != null) {
num2 = attachmentsToUpload.length;
}
if (num2 == null) {
num2 = 0;
}
let pendingMessages = this.pendingMessages;
const obj2 = { initialSendTimestamp: Date.now(), apiResponseTimestamp: null, gatewaySeenTimestamp: null, channelId, attachmentCount: num + num2 };
const result = pendingMessages.set(arg1, obj2);
const timerId = setTimeout(() => {
const pendingMessages = self.pendingMessages;
const value = pendingMessages.get(closure_0);
const tmp = self;
const tmp2 = closure_0;
if (null != value) {
trackRoundtrip(value);
const pendingMessages2 = tmp.pendingMessages;
pendingMessages2.delete(tmp2);
}
}, 30000);
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
recordMessageSendApiResponse(arg0) {
const self = this;
const pendingMessages = this.pendingMessages;
const value = pendingMessages.get(arg0);
2026-07-29 08:29:29 +00:00
if (null != value) {
2026-10-03 08:58:59 +00:00
const obj = { apiResponseTimestamp: Date.now() };
const merged = Object.assign(value);
const _Date = Date;
const tmp6 = null != obj.apiResponseTimestamp && null != obj.gatewaySeenTimestamp;
if (tmp6) {
trackRoundtrip(obj);
const pendingMessages3 = self.pendingMessages;
pendingMessages3.delete(arg0);
} else {
const pendingMessages2 = self.pendingMessages;
const result = pendingMessages2.set(arg0, obj);
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
recordGatewayResponse(nonce) {
const self = this;
const pendingMessages = this.pendingMessages;
const value = pendingMessages.get(nonce);
if (null != value) {
const obj = { gatewaySeenTimestamp: Date.now() };
const merged = Object.assign(value);
const _Date = Date;
const tmp6 = null != obj.apiResponseTimestamp && null != obj.gatewaySeenTimestamp;
if (tmp6) {
trackRoundtrip(obj);
const pendingMessages3 = self.pendingMessages;
pendingMessages3.delete(nonce);
} else {
const pendingMessages2 = self.pendingMessages;
const result = pendingMessages2.set(nonce, obj);
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
}
const prototype = MessageRoundtripTrackerStoreClass.prototype;
let obj = {
2026-07-20 16:05:17 +00:00
MESSAGE_CREATE: function handleMessageCreate(optimistic) {
optimistic = optimistic.optimistic;
const nonce = optimistic.message.nonce;
if (!optimistic) {
optimistic = null == nonce;
}
if (!optimistic) {
2026-07-29 08:29:29 +00:00
const result = messageRoundtripTrackerStoreClass.recordGatewayResponse(nonce);
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
};
const messageRoundtripTrackerStoreClass = new MessageRoundtripTrackerStoreClass(DispatcherDefault, obj);
let result = size.fileFinishedImporting("modules/messages/MessageRoundtripTrackerStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default messageRoundtripTrackerStoreClass;