mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-28 00:54:16 +00:00
Fix voice state query trying to include member
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { Channel, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
import { Channel, DiscordApiErrors, emitEvent, getPermission, Member, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { ChannelType, VoiceStateUpdateSchema } from "@spacebar/schemas";
|
||||
|
||||
@@ -59,17 +59,16 @@ router.patch(
|
||||
if (!body.suppress) body.request_to_speak_timestamp = new Date();
|
||||
if (body.request_to_speak_timestamp) perms.hasThrow("REQUEST_TO_SPEAK");
|
||||
|
||||
const voice_state = await VoiceState.findOne({
|
||||
const voiceState = await VoiceState.findOne({
|
||||
where: {
|
||||
guild_id,
|
||||
channel_id: body.channel_id,
|
||||
user_id,
|
||||
},
|
||||
relations: { member: true },
|
||||
});
|
||||
if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE;
|
||||
if (!voiceState) throw DiscordApiErrors.UNKNOWN_VOICE_STATE;
|
||||
|
||||
voice_state.assign(body);
|
||||
voiceState.assign(body);
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { guild_id, id: body.channel_id },
|
||||
});
|
||||
@@ -77,13 +76,20 @@ router.patch(
|
||||
throw DiscordApiErrors.CANNOT_EXECUTE_ON_THIS_CHANNEL_TYPE;
|
||||
}
|
||||
|
||||
voiceState.member = await Member.findOneOrFail({
|
||||
where: {
|
||||
id: voiceState.user_id,
|
||||
guild_id: voiceState.guild_id,
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
voice_state.save(),
|
||||
voiceState.save(),
|
||||
emitEvent({
|
||||
event: "VOICE_STATE_UPDATE",
|
||||
data: {
|
||||
...voice_state.toPublicVoiceState(),
|
||||
member: voice_state.member.toPublicMember(),
|
||||
...voiceState.toPublicVoiceState(),
|
||||
member: voiceState.member.toPublicMember(),
|
||||
},
|
||||
guild_id,
|
||||
} satisfies VoiceStateUpdateEvent),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
import { WebSocket } from "@spacebar/gateway";
|
||||
import { emitEvent, PresenceUpdateEvent, Session, SessionsReplace, User, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
import { emitEvent, Member, PresenceUpdateEvent, Session, SessionsReplace, User, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
|
||||
export async function Close(this: WebSocket, code: number, reason: Buffer) {
|
||||
console.log("[WebSocket] closed", code, reason.toString());
|
||||
@@ -32,7 +32,6 @@ export async function Close(this: WebSocket, code: number, reason: Buffer) {
|
||||
|
||||
const voiceState = await VoiceState.findOne({
|
||||
where: { user_id: this.user_id },
|
||||
relations: { member: true },
|
||||
});
|
||||
|
||||
// clear the voice state for this session if user was in voice channel
|
||||
@@ -48,6 +47,12 @@ export async function Close(this: WebSocket, code: number, reason: Buffer) {
|
||||
voiceState.self_video = false;
|
||||
await voiceState.save();
|
||||
|
||||
voiceState.member = await Member.findOneOrFail({
|
||||
where: {
|
||||
id: voiceState.user_id,
|
||||
guild_id: prevGuildId,
|
||||
},
|
||||
});
|
||||
// let the users in previous guild/channel know that user disconnected
|
||||
await emitEvent({
|
||||
event: "VOICE_STATE_UPDATE",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parseStreamKey, Payload, WebSocket } from "@spacebar/gateway";
|
||||
import { emitEvent, Stream, StreamDeleteEvent, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
import { emitEvent, Member, Stream, StreamDeleteEvent, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
|
||||
import { check } from "./instanceOf";
|
||||
import { StreamDeleteSchema } from "@spacebar/schemas";
|
||||
|
||||
@@ -53,6 +53,12 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
|
||||
if (voiceState) {
|
||||
voiceState.self_stream = false;
|
||||
await voiceState.save();
|
||||
voiceState.member = await Member.findOneOrFail({
|
||||
where: {
|
||||
id: voiceState.user_id,
|
||||
guild_id: voiceState.guild_id,
|
||||
},
|
||||
});
|
||||
|
||||
await emitEvent({
|
||||
event: "VOICE_STATE_UPDATE",
|
||||
|
||||
Reference in New Issue
Block a user