Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
UserNotFoundError,
UserNotInWaitlistError,
} from '../errors/index.js';
import skipIfCurrentDJ from '../utils/skipIfCurrentDJ.js';
import getOffsetPagination from '../utils/getOffsetPagination.js';
import toItemResponse from '../utils/toItemResponse.js';
import toListResponse from '../utils/toListResponse.js';
Expand Down Expand Up @@ -190,7 +189,14 @@ async function changeAvatar() {
* @param {UserID} userID
*/
async function disconnectUser(uw, userID) {
await skipIfCurrentDJ(uw, userID);
try {
await uw.booth.removeUser(userID);
} catch (err) {
// It's expected that the user would not be in the waitlist
if (!(err instanceof UserNotInWaitlistError)) {
throw err;
}
}

try {
await uw.waitlist.removeUser(userID);
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/booth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mutex from 'p-mutex';
import { sql } from 'kysely';
import { EmptyPlaylistError, PlaylistItemNotFoundError } from '../errors/index.js';
import { EmptyPlaylistError, PlaylistItemNotFoundError, UserNotInWaitlistError } from '../errors/index.js';
import routes from '../routes/booth.js';
import { randomUUID } from 'node:crypto';
import { fromJson, jsonb, jsonGroupArray } from '../utils/sqlite.js';
Expand Down Expand Up @@ -499,6 +499,19 @@ class Booth {
}
return null;
}

/**
* Remove the given user from the booth. Throw an error if the user is not playing.
*
* @param {UserID} userID
*/
async removeUser(userID) {
const currentDJ = await this.#uw.keyv.get(KEY_CURRENT_DJ_ID);
if (userID !== currentDJ) {
throw new UserNotInWaitlistError({ id: userID });
}
await this.advance({ remove: true });
}
}

/**
Expand Down
19 changes: 0 additions & 19 deletions src/utils/skipIfCurrentDJ.js

This file was deleted.