Files
discord-decomp/modules/guild_rooms/GuildRoomAnalytics.tsx
T
2026-11-01 12:12:55 +02:00

525 lines
17 KiB
TypeScript

// Metro module 16197 (f16198).
import AuthenticationStore from "../../stores/AuthenticationStore";
import ChannelStore from "../../stores/ChannelStore";
import RTCConnectionStore from "../../stores/RTCConnectionStore";
import VoiceStateStore from "../../stores/VoiceStateStore";
import GuildRoomStore from "./GuildRoomStore";
import { getSeatName } from "./GuildRoomConstants";
import { AnalyticEvents } from "../../Constants";
import AppAnalyticsUtils from "../app_analytics/AppAnalyticsUtils";
import { HermesBuiltin } from "../../_hermes/prelude";
function $mk98940($env) {
return function onChange() {
const r7 = $env.$parent;
const r5 = r7[4];
const mediaSessionId = r5.getMediaSessionId();
if (mediaSessionId != null) {
const r4 = $env;
r5.removeChangeListener(r4[3]);
clearTimeout(r4[2]);
(0, r4[1])({
voice_state_count: Object.keys(r7[5].getVoiceStatesForChannel(r4[0])).length,
voice_media_session_id: mediaSessionId
});
}
};
}
function $mk98941($env) {
return () => {
const r3 = $env;
const r6 = $env.$parent;
r6[4].removeChangeListener(r3[3]);
clearTimeout(r3[2]);
(0, r3[1])({
voice_state_count: Object.keys(r6[5].getVoiceStatesForChannel(r3[0])).length
});
};
}
let env11614 = {};
export function trackGuildRoomObjectInteracted({ interactionType, ...rest }) {
let env22865;
let c22864_1 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_OBJECT_INTERACTED = AnalyticEvents.GUILD_ROOM_OBJECT_INTERACTED;
let userId = c22864_1.userId;
let guildId = c22864_1.guildId;
const channelId = c22864_1.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_OBJECT_INTERACTED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
interaction_type: interactionType,
...a0
});
};
const r18 = env22865 = {
$parent: env11614
};
env22865[0] = channelId;
env22865[1] = r7;
env22865[2] = void 0;
const r5 = $mk98940(r18);
env22865[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22865[2] = setTimeout($mk98941(r18), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomInteracted({ interactionType: interactionType2, ...rest }) {
let env22867;
let c22866_1 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_INTERACTED = AnalyticEvents.GUILD_ROOM_INTERACTED;
let userId = c22866_1.userId;
let guildId = c22866_1.guildId;
const channelId = c22866_1.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_INTERACTED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
interaction_type: interactionType2,
...a0
});
};
const r18 = env22867 = {
$parent: env11614
};
env22867[0] = channelId;
env22867[1] = r7;
env22867[2] = void 0;
const r5 = $mk98940(r18);
env22867[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22867[2] = setTimeout($mk98941(r18), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomLayoutToggled({ location: location2, guildRoomOpen, ...rest }) {
let env22869;
let c22868_2 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_LAYOUT_TOGGLED = AnalyticEvents.GUILD_ROOM_LAYOUT_TOGGLED;
let userId = c22868_2.userId;
let guildId = c22868_2.guildId;
const channelId = c22868_2.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_LAYOUT_TOGGLED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
location: location2,
guild_room_open: guildRoomOpen,
...a0
});
};
const r19 = env22869 = {
$parent: env11614
};
env22869[0] = channelId;
env22869[1] = r7;
env22869[2] = void 0;
const r5 = $mk98940(r19);
env22869[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22869[2] = setTimeout($mk98941(r19), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomOpened({ location: location3, ...rest }) {
let env22871;
let c22870_1 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_OPENED = AnalyticEvents.GUILD_ROOM_OPENED;
let userId = c22870_1.userId;
let guildId = c22870_1.guildId;
const channelId = c22870_1.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_OPENED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
location: location3,
...a0
});
};
const r18 = env22871 = {
$parent: env11614
};
env22871[0] = channelId;
env22871[1] = r7;
env22871[2] = void 0;
const r5 = $mk98940(r18);
env22871[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22871[2] = setTimeout($mk98941(r18), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomSeatSelected({ actualSeatPosition, targetSeatPosition, ...rest }) {
let env22873;
let c22872_2 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_SEAT_SELECTED = AnalyticEvents.GUILD_ROOM_SEAT_SELECTED;
let userId = c22872_2.userId;
let guildId = c22872_2.guildId;
const channelId = c22872_2.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
const r29 = {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
seat_name: (0, getSeatName)(actualSeatPosition.x, actualSeatPosition.y),
seat_position_v2: [actualSeatPosition.x, actualSeatPosition.y]
};
const update_reason = actualSeatPosition.x === targetSeatPosition?.x ? actualSeatPosition.y !== targetSeatPosition?.y ? "default" : "user_selected" : "default";
r29.update_reason = update_reason;
const channelId2 = c22872_2.channelId;
const seated_user_ids = [];
let c28283_0 = seated_user_ids;
const seated_user_seat_names = [];
let c28283_1 = seated_user_seat_names;
const seated_user_x_positions = [];
let c28283_2 = seated_user_x_positions;
const seated_user_y_positions = [];
let c28283_3 = seated_user_y_positions;
GuildRoomStore.getRoomUsers(channelId2).forEach((item, index) => {
c28283_0.push(index);
c28283_1.push((0, getSeatName)(item.position.x, item.position.y));
c28283_2.push(item.position.x);
c28283_3.push(item.position.y);
});
HermesBuiltin.copyDataProperties(r29, {
seated_user_ids,
seated_user_seat_names,
seated_user_x_positions,
seated_user_y_positions
});
HermesBuiltin.copyDataProperties(r29, a0);
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_SEAT_SELECTED, r29);
};
const r19 = env22873 = {
$parent: env11614
};
env22873[0] = channelId;
env22873[1] = r7;
env22873[2] = void 0;
const r5 = $mk98940(r19);
env22873[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22873[2] = setTimeout($mk98941(r19), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomUserInteracted({ targetUserId, interactionType: interactionType3, ...rest }) {
let env22875;
let c22874_2 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_USER_INTERACTED = AnalyticEvents.GUILD_ROOM_USER_INTERACTED;
let userId = c22874_2.userId;
let guildId = c22874_2.guildId;
const channelId = c22874_2.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_USER_INTERACTED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
target_user_id: targetUserId,
interaction_type: interactionType3,
...a0
});
};
const r19 = env22875 = {
$parent: env11614
};
env22875[0] = channelId;
env22875[1] = r7;
env22875[2] = void 0;
const r5 = $mk98940(r19);
env22875[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22875[2] = setTimeout($mk98941(r19), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomUserConnected(a0) {
let env22877;
let c22876_0 = a0;
const channelId = a0.channelId;
const r7 = (a0) => {
const GUILD_ROOM_USER_CONNECTED = AnalyticEvents.GUILD_ROOM_USER_CONNECTED;
let userId = c22876_0.userId;
let guildId = c22876_0.guildId;
const channelId = c22876_0.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_USER_CONNECTED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
...a0
});
};
const r6 = env22877 = {
$parent: env11614
};
env22877[0] = channelId;
env22877[1] = r7;
env22877[2] = void 0;
const r5 = $mk98940(r6);
env22877[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22877[2] = setTimeout($mk98941(r6), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}
export function trackGuildRoomUserDisconnected(a0) {
const GUILD_ROOM_USER_DISCONNECTED = AnalyticEvents.GUILD_ROOM_USER_DISCONNECTED;
let userId = a0.userId;
let guildId = a0.guildId;
const channelId = a0.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r26 = channel == null ? void 0 : channel.getGuildId();
if (r26 == null) {
r26 = void 0;
}
guildId = r26;
}
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_USER_DISCONNECTED, {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
},
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(a0.channelId)).length,
voice_media_session_id: GuildRoomStore.getMediaSessionId(a0.channelId)
});
}
export function trackGuildRoomUserUpdated({ update, ...rest }) {
let env22879;
let c22878_1 = rest;
const channelId = rest.channelId;
const r7 = (a0) => {
const GUILD_ROOM_USER_UPDATED = AnalyticEvents.GUILD_ROOM_USER_UPDATED;
let userId = c22878_1.userId;
let guildId = c22878_1.guildId;
const channelId = c22878_1.channelId;
if (userId == null) {
userId = AuthenticationStore.getId();
}
const roomUsers = GuildRoomStore.getRoomUsers(channelId);
if (guildId == null) {
const channel = ChannelStore.getChannel(channelId);
let r27 = channel == null ? void 0 : channel.getGuildId();
if (r27 == null) {
r27 = void 0;
}
guildId = r27;
}
const r29 = {
...{
user_id: userId,
guild_id: guildId,
channel_id: channelId,
guild_room_user_count: roomUsers.size,
guild_room_user_connected: roomUsers.has(userId)
}
};
const r36 = {
update_type: update.updateType,
update_reason: update.updateReason
};
const updateType = update.updateType;
HermesBuiltin.copyDataProperties(r29, updateType === "position" ? {
...r36,
position_v2: [update.position.x, update.position.y]
} : updateType === "status_id" ? {
...r36,
status_id: update.statusId
} : updateType === "status_text" ? {
...r36,
status_text: update.statusText
} : void 0);
HermesBuiltin.copyDataProperties(r29, a0);
AppAnalyticsUtils.trackWithMetadata(GUILD_ROOM_USER_UPDATED, r29);
};
const r18 = env22879 = {
$parent: env11614
};
env22879[0] = channelId;
env22879[1] = r7;
env22879[2] = void 0;
const r5 = $mk98940(r18);
env22879[3] = r5;
const mediaSessionId = RTCConnectionStore.getMediaSessionId();
if (mediaSessionId == null) {
env22879[2] = setTimeout($mk98941(r18), 2500);
RTCConnectionStore.addChangeListener(r5);
} else {
r7({
voice_state_count: Object.keys(VoiceStateStore.getVoiceStatesForChannel(channelId)).length,
voice_media_session_id: mediaSessionId
});
}
}