Files
discord-decomp/modules/voice_calls/native/VoiceNotificationManager.android.tsx
T
2026-11-01 12:12:55 +02:00

245 lines
8.5 KiB
TypeScript

// Metro module 13517 (f13518).
import { processColor } from "react-native";
import EmbeddedActivitiesStore from "../../activities/EmbeddedActivitiesStore";
import "../../applications/ApplicationStore";
import ApplicationStreamingStore from "../../../stores/ApplicationStreamingStore";
import "../../../stores/ChannelStore";
import MediaEngineStore from "../../../stores/MediaEngineStore";
import RTCConnectionStore from "../../../stores/RTCConnectionStore";
import "../../../stores/RelationshipStore";
import "../../../stores/UserStore";
import "../../../Constants";
import Module712 from "../../../_bundle/Module712";
import { ServiceNotificationIcon } from "../../foreground_service/mobile/ForegroundServiceManagerTypes";
import LifecycleManager from "../../../lib/LifecycleManager";
function $mk91419($env) {
return () => {
const r3 = $env.$parent[9];
const channelId = r3.getChannelId();
const state = r3.getState();
const r4 = $env[0];
if (!(r4.state.channelId === channelId && r4.state.connectionState === state)) {
r4.handleUpdate({
...r4.state,
channelId,
connectionState: state
});
}
};
}
function $mk91420($env) {
return () => {
const r3 = $env.$parent;
const r8 = r3[8];
const selfMute = r8.isSelfMute() || r8.isSelfMutedTemporarily();
const deafened = r8.isSelfDeaf() || r8.isDeaf();
const r5 = $env;
const mode = r8.getMode();
const PUSH_TO_TALK = r3[12].PUSH_TO_TALK;
const r18 = r5[0];
let r0 = r18.state.selfMute === selfMute && r18.state.deafened === deafened;
const isPushToTalk = mode === PUSH_TO_TALK;
if (r0) {
r0 = r18.state.isPushToTalk === isPushToTalk;
}
if (!r0) {
r18.handleUpdate({
...r18.state,
selfMute,
deafened,
isPushToTalk
});
}
};
}
function $mk91421($env) {
return () => {
const r3 = $env[0];
if (r3.state.channelId != null) {
r3.handleUpdate({
...r3.state,
embeddedActivity: $env.$parent[4].getCurrentEmbeddedActivity()
});
}
};
}
function $mk91422($env) {
return () => {
const isStreaming = $env.$parent[6].getCurrentUserActiveStream() != null;
const r3 = $env[0];
if (r3.state.isStreaming !== isStreaming) {
r3.handleUpdate({
...r3.state,
isStreaming
});
}
};
}
function $mk91423($env) {
return ({ deafened, selfMute, isPushToTalk }) => deafened ? [ServiceNotificationIcon.DEAFENED, c9380_14] : selfMute ? [ServiceNotificationIcon.MUTED, c9380_14] : isPushToTalk ? [ServiceNotificationIcon.DEFAULT, c9380_13] : [ServiceNotificationIcon.IDLE, c9380_13];
}
function $mk91424($env) {
return (a0) => {
L33: {
const r4 = $env;
if (a0.connectionState != null) {
const r24 = r4[0];
const icon = r24.getIcon(r24.state);
const r27 = $env.$parent;
const r9 = r27[3];
const r28 = r9(icon, 2);
const r10 = r28[0];
const r29 = r28[1];
const r31 = r9(r24.getIcon(a0), 2);
const icon2 = r31[0];
const color = r31[1];
if (r24.state.channelId === a0.channelId && r24.state.connectionState === a0.connectionState && r24.state.selfMute === a0.selfMute && r24.state.deafened === a0.deafened) {
if (r24.state.embeddedActivity?.compositeInstanceId === a0.embeddedActivity?.compositeInstanceId && r24.state.isStreaming === a0.isStreaming && r10 === icon2 && r29 === color) {
r24.state = a0;
break L33;
}
}
const { channelId, connectionState, selfMute, deafened, embeddedActivity, isStreaming } = a0;
r24.state = a0;
const channel = r27[7].getChannel(channelId);
if (channel != null) {
const r64 = r27[1];
const r65 = r27[2];
const connectionStatusText = r64(r65[14]).getStatus(connectionState).connectionStatusText;
const r70 = embeddedActivity != null;
let r17 = "";
if (r70) {
const application = r27[5].getApplication(embeddedActivity?.applicationId);
r17 = ` - ${r64(r65[15])(application?.name)}`;
}
const r85 = r27[0];
const r91 = r85(r65[16]).computeChannelName(channel, r27[11], r27[10]);
const r100 = {
title: r85(r65[17]).intl.formatToPlainString(r85(r65[17]).t["aUT3+M"], {
callState: connectionStatusText
}),
content: `${r91}${r17}`,
priority: r85(r65[12]).ServiceNotificationPriority.HIGH,
contentAction: r24.createAction(channel, "SelectVoiceChannel", void 0),
auxiliaryActions: null,
type: null,
usesGateway: true,
icon: null,
color: null
};
const auxiliaryActions = [r24.createAction(channel, "Disconnect", r85(r65[17]).intl.string(r85(r65[17]).t["6vrfgt"])), , ,];
const intl = r85(r65[17]).intl;
const r132 = r85(r65[17]).t;
auxiliaryActions[1] = r24.createAction(channel, "ToggleSelfMute", selfMute ? intl.string(r132.YqAjXy) : intl.string(r132.w4m945));
const intl2 = r85(r65[17]).intl;
const r145 = r85(r65[17]).t;
auxiliaryActions[2] = r24.createAction(channel, "ToggleDeafen", deafened ? intl2.string(r145["2US872"]) : intl2.string(r145.wjcRFX));
r100.auxiliaryActions = auxiliaryActions;
const ServiceNotificationType = r85(r65[12]).ServiceNotificationType;
r100.type = isStreaming ? ServiceNotificationType.SCREEN_SHARE : ServiceNotificationType.VOICE_CALL;
r100.icon = icon2;
r100.color = color;
r64(r65[13]).updateServiceHandler(r24.voiceServiceHandlerId, r100);
} else {
(0, r27[1])(r27[2][13]).removeServiceHandler(r24.voiceServiceHandlerId);
}
} else {
r4[0].state = a0;
}
}
};
}
function $mk91425() {
return (a0, a1, a2) => ({
tag: `${a1}${a0.id}`,
taskName: a1,
title: a2,
data: {
channelId: a0.id
}
});
}
let c9381_0, c9380_15, c9380_16;
let env9380;
let env9381;
const r6 = env9380 = {};
const c9380_13 = processColor(Module712.unsafe_rawColors.BRAND_500);
const c9380_14 = processColor(Module712.unsafe_rawColors.RED_NEW_46);
class VoiceNotificationManager {
constructor() {
let env20505;
const r3 = env20505 = {
$parent: env9380
};
env20505[0] = this;
this.voiceServiceHandlerId = 9000;
this.state = {
channelId: void 0,
connectionState: void 0,
selfMute: false,
deafened: false,
isPushToTalk: false,
embeddedActivity: void 0,
isStreaming: false
};
this.handleVoiceStateChange = $mk91419(r3);
this.handleMediaEngineStateChange = $mk91420(r3);
this.handleEmbeddedActivityStateChange = $mk91421(r3);
this.handleApplicationStreamStateChange = $mk91422(r3);
this.getIcon = $mk91423(env9380);
this.handleUpdate = $mk91424(r3);
this.createAction = $mk91425();
}
initialize() {
RTCConnectionStore.addChangeListener(this.handleVoiceStateChange);
MediaEngineStore.addChangeListener(this.handleMediaEngineStateChange);
EmbeddedActivitiesStore.addChangeListener(this.handleEmbeddedActivityStateChange);
ApplicationStreamingStore.addChangeListener(this.handleApplicationStreamStateChange);
}
terminate() {
RTCConnectionStore.removeChangeListener(this.handleVoiceStateChange);
MediaEngineStore.removeChangeListener(this.handleMediaEngineStateChange);
EmbeddedActivitiesStore.removeChangeListener(this.handleEmbeddedActivityStateChange);
ApplicationStreamingStore.removeChangeListener(this.handleApplicationStreamStateChange);
}
}
const r59 = {
__proto__: VoiceNotificationManager.prototype
};
const r60 = env9381 = {
$parent: r6
};
c9381_0 = r59;
r59.voiceServiceHandlerId = 9000;
r59.state = {
channelId: void 0,
connectionState: void 0,
selfMute: false,
deafened: false,
isPushToTalk: false,
embeddedActivity: void 0,
isStreaming: false
};
r59.handleVoiceStateChange = $mk91419(r60);
r59.handleMediaEngineStateChange = $mk91420(r60);
r59.handleEmbeddedActivityStateChange = $mk91421(r60);
r59.handleApplicationStreamStateChange = $mk91422(r60);
r59.getIcon = $mk91423(r6);
r59.handleUpdate = $mk91424(r60);
r59.createAction = $mk91425();
c9380_15 = r59;
class VoiceNotificationLifecycleManager extends LifecycleManager {
constructor() {
super(...arguments);
}
_initialize() {
c9380_15.initialize();
}
_terminate() {
c9380_15.terminate();
}
}
c9380_16 = VoiceNotificationLifecycleManager;
const r78 = new VoiceNotificationLifecycleManager();
export default r78;