180 lines
4.7 KiB
TypeScript
180 lines
4.7 KiB
TypeScript
// Metro module 4866 (f4867).
|
|
import ChannelStore from "./ChannelStore";
|
|
import SelectedChannelStore from "./SelectedChannelStore";
|
|
import SelectedGuildStore from "./SelectedGuildStore";
|
|
import { Endpoints } from "../Constants";
|
|
import Dispatcher from "../Dispatcher";
|
|
import { HTTP } from "../_bundle/sendRequest";
|
|
import Module12 from "../_bundle/Module12";
|
|
import Module589 from "../_bundle/Module589";
|
|
let calls, enqueuedRings;
|
|
const callConnect = function callConnect() {
|
|
let r6 = arguments[1];
|
|
if (r6 === void 0) {
|
|
r6 = SelectedChannelStore.getChannelId();
|
|
}
|
|
const channel = ChannelStore.getChannel(r6);
|
|
let r0 = channel == null;
|
|
const channelId = r6;
|
|
if (!r0) {
|
|
r0 = channel.getGuildId() != null;
|
|
}
|
|
if (!r0) {
|
|
r0 = channelId == null;
|
|
}
|
|
if (!r0) {
|
|
r0 = calls[channelId] != null && !arguments[0];
|
|
}
|
|
let r19 = !r0;
|
|
if (!r0) {
|
|
let r21 = calls[channelId];
|
|
if (r21 == null) {
|
|
r21 = {
|
|
channelId,
|
|
ringing: []
|
|
};
|
|
}
|
|
calls[channelId] = r21;
|
|
Dispatcher.dispatch({
|
|
type: "CALL_CONNECT",
|
|
channelId
|
|
});
|
|
r19 = true;
|
|
}
|
|
return r19;
|
|
};
|
|
calls = {};
|
|
enqueuedRings = {};
|
|
class CallStore extends Module589.Store {
|
|
static displayName = "CallStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, SelectedChannelStore, SelectedGuildStore);
|
|
}
|
|
getCall(a0) {
|
|
return calls[a0];
|
|
}
|
|
getCalls() {
|
|
return Object.values(calls);
|
|
}
|
|
getMessageId(a0) {
|
|
const call = this.getCall(a0);
|
|
return call != null ? call.messageId : null;
|
|
}
|
|
isCallActive(a0, a1) {
|
|
const r7 = calls[a0];
|
|
return r7 != null && !r7.unavailable && (a1 != null ? r7.messageId === a1 : r7.region != null);
|
|
}
|
|
isCallUnavailable(a0) {
|
|
const r4 = calls[a0];
|
|
return r4 != null && r4.unavailable;
|
|
}
|
|
getInternalState() {
|
|
return {
|
|
calls,
|
|
enqueuedRings
|
|
};
|
|
}
|
|
}
|
|
const callStore = new CallStore(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen() {
|
|
return callConnect(true);
|
|
},
|
|
CONNECTION_CLOSED: function handleConnectionClosed() {
|
|
calls = {};
|
|
enqueuedRings = {};
|
|
},
|
|
OVERLAY_INITIALIZE: function handleOverlayInitialize({ callStoreInternalState }) {
|
|
calls = {
|
|
...callStoreInternalState.calls
|
|
};
|
|
enqueuedRings = {
|
|
...callStoreInternalState.enqueuedRings
|
|
};
|
|
},
|
|
CONNECTION_RESUMED: function handleConnectionResumed() {
|
|
return callConnect(true);
|
|
},
|
|
CHANNEL_SELECT: function handleChannelSelect(a0) {
|
|
return callConnect(false, a0.channelId);
|
|
},
|
|
CHANNEL_DELETE: function handleChannelDelete({ channel }) {
|
|
if (enqueuedRings[channel.id] != null) {
|
|
delete enqueuedRings[channel.id];
|
|
}
|
|
if (calls[channel.id] == null) {
|
|
return false;
|
|
}
|
|
delete calls[channel.id];
|
|
},
|
|
CALL_CREATE: function handleCallCreate(a0) {
|
|
const channelId = a0.channelId;
|
|
calls[channelId] = {
|
|
channelId,
|
|
messageId: a0.messageId,
|
|
region: a0.region,
|
|
ringing: Object.keys(a0.ongoingRings),
|
|
unavailable: false,
|
|
regionUpdated: false
|
|
};
|
|
if (enqueuedRings[channelId] != null) {
|
|
const r18 = enqueuedRings[channelId];
|
|
delete enqueuedRings[channelId];
|
|
const recipients = r18.indexOf("all") !== 1 ? null : r18;
|
|
HTTP.post({
|
|
url: Endpoints.CALL_RING(channelId),
|
|
body: {
|
|
recipients
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
}
|
|
},
|
|
CALL_UPDATE: function handleCallUpdate({ channelId, messageId, region, ongoingRings }) {
|
|
const r8 = calls[channelId];
|
|
const regionUpdated = r8 != null && (r8.regionUpdated || r8.region !== region);
|
|
calls[channelId] = {
|
|
...calls[channelId],
|
|
messageId,
|
|
region,
|
|
ringing: Object.keys(ongoingRings),
|
|
regionUpdated
|
|
};
|
|
},
|
|
CALL_DELETE: function handleCallDelete({ channelId, unavailable }) {
|
|
const r7 = calls[channelId];
|
|
calls[channelId] = unavailable === true && r7 != null ? {
|
|
...r7,
|
|
unavailable
|
|
} : {
|
|
channelId,
|
|
ringing: [],
|
|
messageId: null,
|
|
region: null,
|
|
regionUpdated: false,
|
|
unavailable
|
|
};
|
|
if (enqueuedRings[channelId] != null) {
|
|
delete enqueuedRings[channelId];
|
|
}
|
|
},
|
|
CALL_ENQUEUE_RING: function handleCallEnqueueRing(a0) {
|
|
const channelId = a0.channelId;
|
|
let recipients = a0.recipients;
|
|
let r13 = enqueuedRings[channelId];
|
|
if (r13 == null) {
|
|
r13 = [];
|
|
}
|
|
if (recipients == null) {
|
|
recipients = ["all"];
|
|
}
|
|
enqueuedRings[channelId] = Module12.union(r13, recipients);
|
|
},
|
|
VOICE_CHANNEL_SELECT: function handleVoiceChannelSelect(a0) {
|
|
if (a0.channelId == null) {
|
|
enqueuedRings = {};
|
|
}
|
|
}
|
|
});
|
|
export default callStore;
|