360 lines
12 KiB
TypeScript
360 lines
12 KiB
TypeScript
// Metro module 12705 (f12706).
|
|
import _objectWithoutProperties from "../../_bundle/_objectWithoutProperties";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { AnalyticEvents, ChannelTypes } from "../../Constants";
|
|
import Module10 from "../../_bundle/Module10";
|
|
import TTITracker from "../tti_analytics/TTITracker";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
let _excluded, _excluded2, _excluded3, eachTraceCall;
|
|
const prettyPrintTrace_ = function prettyPrintTrace_(calls, a1) {
|
|
let length;
|
|
if (calls == null) {
|
|
return "";
|
|
}
|
|
const r26 = 0 < calls.length;
|
|
let r10 = "";
|
|
let r0 = 0;
|
|
let r27 = "";
|
|
if (r26) {
|
|
do {
|
|
const r23 = calls[r0];
|
|
const r1 = r0 + 1;
|
|
r10 = r10 + `
|
|
${a1}${r23}: ${calls[r1].micros / 1000}` + prettyPrintTrace_(calls[r1].calls, a1 + "| ");
|
|
r0 = r0 + 2;
|
|
length = calls.length;
|
|
r27 = r10;
|
|
} while (r0 < length);
|
|
}
|
|
return r27;
|
|
};
|
|
eachTraceCall = function eachTraceCall(calls, a1) {
|
|
if (calls != null && calls.length > 0) {
|
|
const r6 = 0 < calls.length;
|
|
let r0 = 0;
|
|
if (r6) {
|
|
do {
|
|
const r12 = calls[r0];
|
|
const r15 = calls[r0 + 1];
|
|
a1(r12, r15.micros);
|
|
eachTraceCall(r15.calls, a1);
|
|
r0 = r0 + 2;
|
|
} while (r0 < calls.length);
|
|
}
|
|
}
|
|
};
|
|
_excluded = ["guilds", "merged_presences", "merged_members", "read_state", "private_channels", "user_guild_settings", "user_settings", "user_settings_proto", "experiments", "guild_experiments", "relationships", "users"];
|
|
_excluded2 = ["features"];
|
|
_excluded3 = ["threads", "guild_scheduled_events"];
|
|
export function reportDevtoolsEvent() {}
|
|
export function logReadyPayloadReceived(a0, a1, a2, a3, a4) {
|
|
const r13 = (function getReadyPayloadTraceAnalytics({ _trace }) {
|
|
const r8 = {};
|
|
let c27353_0 = r8;
|
|
try {
|
|
const r9 = JSON.parse(_trace);
|
|
if (r9[0] != null && r9[0] !== "" && typeof r9[0] === "string" && r9[0].startsWith("gateway-")) {
|
|
r8.identify_total_server_duration_ms = typeof r9[1] === "object" ? "micros" in r9[1] ? Math.floor(r9[1].micros / 1000) : 0 : 0;
|
|
}
|
|
eachTraceCall(r9, (a0, a1) => {
|
|
if (a0 === "start_session") {
|
|
c27353_0.identify_api_duration_ms = Math.floor(a1 / 1000);
|
|
} else if (a0 === "guilds_connect") {
|
|
c27353_0.identify_guilds_duration_ms = Math.floor(a1 / 1000);
|
|
}
|
|
});
|
|
} catch ($e) {}
|
|
return r8;
|
|
})(a1);
|
|
if (a3 != null) {
|
|
Module10.addDetail("payload_size(kb)", Math.round(a3.uncompressed_byte_size / 1024));
|
|
}
|
|
let identify_total_server_duration_ms = r13.identify_total_server_duration_ms;
|
|
if (identify_total_server_duration_ms == null) {
|
|
identify_total_server_duration_ms = 0;
|
|
}
|
|
Module10.addDetail("server_time(ms)", identify_total_server_duration_ms);
|
|
const r38 = {
|
|
...a3,
|
|
...r13
|
|
};
|
|
const guilds = a1.guilds;
|
|
let num_guild_category_channels = 0;
|
|
let num_guild_channels = 0;
|
|
guilds.forEach((guild) => {
|
|
if (!guild.unavailable) {
|
|
const r6 = guild.data_mode === "partial" ? guild.partial_updates.channels : guild.channels;
|
|
if (r6 != null && r6.forEach != null) {
|
|
r6.forEach((item) => {
|
|
num_guild_channels = num_guild_channels + 1;
|
|
if (item.type === ChannelTypes.GUILD_CATEGORY) {
|
|
num_guild_category_channels = num_guild_category_channels + 1;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
HermesBuiltin.copyDataProperties(r38, {
|
|
num_guilds: guilds.length,
|
|
num_guild_channels,
|
|
num_guild_category_channels
|
|
});
|
|
HermesBuiltin.copyDataProperties(r38, a4);
|
|
r38.duration_ms_since_identify_start = a2 - a0.identifyStartTime;
|
|
r38.duration_ms_since_connection_start = a2 - a0.connectionStartTime;
|
|
r38.duration_ms_since_emit_start = Date.now() - a2;
|
|
r38.is_reconnect = a0.hasConnectedOnce;
|
|
r38.is_fast_connect = a0.isFastConnect;
|
|
r38.did_force_clear_guild_hashes = a0.didForceClearGuildHashes;
|
|
r38.identify_uncompressed_byte_size = a0.identifyUncompressedByteSize;
|
|
r38.identify_compressed_byte_size = a0.identifyCompressedByteSize;
|
|
let hadCacheAtStartup = a0.analytics.hadCacheAtStartup;
|
|
if (hadCacheAtStartup == null) {
|
|
hadCacheAtStartup = false;
|
|
}
|
|
r38.had_cache_at_startup = hadCacheAtStartup;
|
|
let usedCacheAtStartup = a0.analytics.usedCacheAtStartup;
|
|
if (usedCacheAtStartup == null) {
|
|
usedCacheAtStartup = false;
|
|
}
|
|
r38.used_cache_at_startup = usedCacheAtStartup;
|
|
TTITracker.attachReadyPayloadProperties(r38);
|
|
AnalyticsUtils.track(AnalyticEvents.READY_PAYLOAD_RECEIVED, r38, {
|
|
logEventProperties: true
|
|
});
|
|
}
|
|
export function getConnectionPath(a0) {
|
|
let r10;
|
|
L5: {
|
|
try {
|
|
const _trace = a0._trace;
|
|
const r9 = (function prettyPrintTrace(a0) {
|
|
let length, length2;
|
|
const r9 = a0 == null;
|
|
let r11 = null;
|
|
if (!r9) {
|
|
const r21 = JSON.parse(a0);
|
|
const r36 = r21 == null;
|
|
let r37 = "";
|
|
if (!r36) {
|
|
const r39 = 0 < r21.length;
|
|
let r7 = 0;
|
|
let r15 = "";
|
|
let r40 = "";
|
|
if (r39) {
|
|
do {
|
|
const r33 = r21[r7];
|
|
const r8 = r7 + 1;
|
|
const r24 = r15 + `
|
|
${r33}: ${r21[r8].micros / 1000}`;
|
|
const calls = r21[r8].calls;
|
|
const r47 = calls == null;
|
|
const r48 = r7;
|
|
let r49 = "";
|
|
if (!r47) {
|
|
const r50 = 0 < calls.length;
|
|
let r0 = 0;
|
|
let r27 = "";
|
|
let r51 = "";
|
|
if (r50) {
|
|
do {
|
|
const r52 = calls[r0];
|
|
const r1 = r0 + 1;
|
|
r27 = r27 + `
|
|
| ${r52}: ${calls[r1].micros / 1000}` + prettyPrintTrace_(calls[r1].calls, "| | ");
|
|
r0 = r0 + 2;
|
|
length = calls.length;
|
|
r51 = r27;
|
|
} while (r0 < length);
|
|
}
|
|
r49 = r51;
|
|
}
|
|
r15 = r24 + r49;
|
|
r7 = r48 + 2;
|
|
length2 = r21.length;
|
|
r40 = r15;
|
|
} while (r7 < length2);
|
|
}
|
|
r37 = r40;
|
|
}
|
|
r11 = r37;
|
|
}
|
|
return r11;
|
|
})(_trace == null ? void 0 : _trace[0]);
|
|
r10 = r9;
|
|
if (r9 != null) {
|
|
break L5;
|
|
}
|
|
} catch ($e) {}
|
|
return a0._trace != null ? a0._trace.join(" -> ") : "???";
|
|
}
|
|
return r10;
|
|
}
|
|
export function getReadyPayloadByteSizeAnalytics(a0) {
|
|
if (Math.random() > 0.01) {
|
|
return void 0;
|
|
}
|
|
const r33 = Date.now();
|
|
const { guilds, merged_presences } = a0;
|
|
let merged_members = a0.merged_members;
|
|
const { read_state, private_channels, user_guild_settings } = a0;
|
|
let user_settings = a0.user_settings;
|
|
let user_settings_proto = a0.user_settings_proto;
|
|
let experiments = a0.experiments;
|
|
let guild_experiments = a0.guild_experiments;
|
|
const { relationships, users } = a0;
|
|
let r36 = _objectWithoutProperties(a0, _excluded);
|
|
const r18 = [];
|
|
let c19987_0 = r18;
|
|
const r15 = [];
|
|
let c19987_1 = r15;
|
|
const r14 = [];
|
|
let c19987_2 = r14;
|
|
const r13 = [];
|
|
let c19987_3 = r13;
|
|
const r12 = [];
|
|
let c19987_4 = r12;
|
|
const r37 = [];
|
|
let c19987_5 = r37;
|
|
const r11 = [];
|
|
let c19987_6 = r11;
|
|
const r38 = [];
|
|
let c19987_7 = r38;
|
|
guilds.forEach((guild) => {
|
|
if (!guild.unavailable) {
|
|
let properties = guild.properties;
|
|
if (properties == null) {
|
|
properties = {};
|
|
}
|
|
const { features, ...rest } = properties;
|
|
const { threads, guild_scheduled_events, ...rest2 } = guild;
|
|
c19987_0.push(guild.data_mode === "partial" ? guild.partial_updates.channels : guild.channels);
|
|
c19987_1.push(guild.data_mode === "partial" ? guild.partial_updates.roles : guild.roles);
|
|
c19987_2.push(guild.data_mode === "partial" ? guild.partial_updates.emojis : guild.emojis);
|
|
c19987_3.push(threads);
|
|
c19987_4.push(guild.data_mode === "partial" ? guild.partial_updates.stickers : guild.stickers);
|
|
c19987_5.push(features);
|
|
c19987_6.push(guild_scheduled_events);
|
|
c19987_7.push(rest2, rest);
|
|
}
|
|
});
|
|
const r29 = JSON;
|
|
let r42 = merged_presences?.friends;
|
|
if (r42 == null) {
|
|
r42 = [];
|
|
}
|
|
const r45 = {
|
|
presences_size: r29.stringify(r42).length,
|
|
users_size: JSON.stringify(users).length,
|
|
read_states_size: JSON.stringify(read_state).length,
|
|
private_channels_size: JSON.stringify(private_channels).length,
|
|
user_settings_size: null,
|
|
experiments_size: null,
|
|
user_guild_settings_size: null,
|
|
relationships_size: null,
|
|
remaining_data_size: null,
|
|
guild_channels_size: null,
|
|
guild_members_size: null,
|
|
guild_presences_size: null,
|
|
guild_roles_size: null,
|
|
guild_emojis_size: null,
|
|
guild_threads_size: null,
|
|
guild_stickers_size: null,
|
|
guild_events_size: null,
|
|
guild_features_size: null,
|
|
guild_remaining_data_size: null,
|
|
size_metrics_duration_ms: null
|
|
};
|
|
const r58 = JSON;
|
|
if (user_settings == null) {
|
|
user_settings = "";
|
|
}
|
|
const length = r58.stringify(user_settings).length;
|
|
if (user_settings_proto == null) {
|
|
user_settings_proto = "";
|
|
}
|
|
r45.user_settings_size = length + user_settings_proto.length;
|
|
const r64 = JSON;
|
|
if (experiments == null) {
|
|
experiments = [];
|
|
}
|
|
const length2 = r64.stringify(experiments).length;
|
|
const r68 = JSON;
|
|
if (guild_experiments == null) {
|
|
guild_experiments = [];
|
|
}
|
|
r45.experiments_size = length2 + r68.stringify(guild_experiments).length;
|
|
r45.user_guild_settings_size = JSON.stringify(user_guild_settings).length;
|
|
r45.relationships_size = JSON.stringify(relationships).length;
|
|
const r81 = JSON;
|
|
if (r36 == null) {
|
|
r36 = {};
|
|
}
|
|
r45.remaining_data_size = r81.stringify(r36).length;
|
|
r45.guild_channels_size = JSON.stringify(r18).length;
|
|
const r89 = JSON;
|
|
if (merged_members == null) {
|
|
merged_members = [];
|
|
}
|
|
r45.guild_members_size = r89.stringify(merged_members).length;
|
|
const r93 = JSON;
|
|
let r96 = merged_presences?.guilds;
|
|
if (r96 == null) {
|
|
r96 = [];
|
|
}
|
|
r45.guild_presences_size = r93.stringify(r96).length;
|
|
r45.guild_roles_size = JSON.stringify(r15).length;
|
|
r45.guild_emojis_size = JSON.stringify(r14).length;
|
|
r45.guild_threads_size = JSON.stringify(r13).length;
|
|
r45.guild_stickers_size = JSON.stringify(r12).length;
|
|
r45.guild_events_size = JSON.stringify(r11).length;
|
|
r45.guild_features_size = JSON.stringify(r37).length;
|
|
r45.guild_remaining_data_size = JSON.stringify(r38).length;
|
|
r45.size_metrics_duration_ms = Date.now() - r33;
|
|
return r45;
|
|
}
|
|
export function logGatewayConnected({ socket, altGateway, gatewayUrl, now }) {
|
|
AnalyticsUtils.track(AnalyticEvents.GATEWAY_CONNECTED, {
|
|
num_failed_connect_attempts: socket.failedConnectAttempts,
|
|
gateway_url: gatewayUrl,
|
|
assigned_to_alt_gateway: altGateway.isAssignedToAltGateway(),
|
|
did_fall_back_from_alt_gateway: altGateway.getDidFallBack(),
|
|
is_reconnect: socket.hasConnectedOnce,
|
|
is_fast_connect: socket.isFastConnect,
|
|
duration_ms_since_first_connect_attempt: now - socket.firstConnectAttemptStartTime,
|
|
duration_ms_since_connect_attempt_start: now - socket.connectionStartTime
|
|
}, {
|
|
logEventProperties: true
|
|
});
|
|
}
|
|
export function createResumeAnalytics(a0) {
|
|
return {
|
|
connectTime: a0 == null ? 0 : a0,
|
|
numEvents: 0,
|
|
largestWaitTime: 0,
|
|
dispatchTime: 0,
|
|
totalWaitTime: 0,
|
|
initialWaitTime: 0,
|
|
startTime: performance.now(),
|
|
lastUpdateTime: performance.now()
|
|
};
|
|
}
|
|
export function logResumeAnalytics(a0) {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
const r15 = currentUser == null ? void 0 : currentUser.isStaff();
|
|
if (!(r15 ? !r15 : Math.random() < 0.5)) {
|
|
AnalyticsUtils.track(AnalyticEvents.CONNECTION_RESUMED, {
|
|
connect_time_ms: a0.connectTime,
|
|
resume_time_ms: Math.floor(performance.now() - a0.startTime),
|
|
num_events: a0.numEvents,
|
|
largest_wait_time_ms: Math.floor(a0.largestWaitTime),
|
|
initial_wait_time_ms: Math.floor(a0.initialWaitTime),
|
|
total_wait_time_ms: Math.floor(a0.totalWaitTime),
|
|
total_dispatch_time_ms: Math.floor(a0.dispatchTime)
|
|
}, {
|
|
logEventProperties: true
|
|
});
|
|
}
|
|
}
|