File tree Expand file tree Collapse file tree 3 files changed +22
-22
lines changed
Expand file tree Collapse file tree 3 files changed +22
-22
lines changed Original file line number Diff line number Diff line change 44 UserNotFoundError ,
55 UserNotInWaitlistError ,
66} from '../errors/index.js' ;
7- import skipIfCurrentDJ from '../utils/skipIfCurrentDJ.js' ;
87import getOffsetPagination from '../utils/getOffsetPagination.js' ;
98import toItemResponse from '../utils/toItemResponse.js' ;
109import toListResponse from '../utils/toListResponse.js' ;
@@ -190,7 +189,14 @@ async function changeAvatar() {
190189 * @param {UserID } userID
191190 */
192191async function disconnectUser ( uw , userID ) {
193- await skipIfCurrentDJ ( uw , userID ) ;
192+ try {
193+ await uw . booth . removeUser ( userID ) ;
194+ } catch ( err ) {
195+ // It's expected that the user would not be in the waitlist
196+ if ( ! ( err instanceof UserNotInWaitlistError ) ) {
197+ throw err ;
198+ }
199+ }
194200
195201 try {
196202 await uw . waitlist . removeUser ( userID ) ;
Original file line number Diff line number Diff line change 11import Mutex from 'p-mutex' ;
22import { sql } from 'kysely' ;
3- import { EmptyPlaylistError , PlaylistItemNotFoundError } from '../errors/index.js' ;
3+ import { EmptyPlaylistError , PlaylistItemNotFoundError , UserNotInWaitlistError } from '../errors/index.js' ;
44import routes from '../routes/booth.js' ;
55import { randomUUID } from 'node:crypto' ;
66import { fromJson , jsonb , jsonGroupArray } from '../utils/sqlite.js' ;
@@ -499,6 +499,19 @@ class Booth {
499499 }
500500 return null ;
501501 }
502+
503+ /**
504+ * Remove the given user from the booth. Throw an error if the user is not playing.
505+ *
506+ * @param {UserID } userID
507+ */
508+ async removeUser ( userID ) {
509+ const currentDJ = await this . #uw. keyv . get ( KEY_CURRENT_DJ_ID ) ;
510+ if ( userID !== currentDJ ) {
511+ throw new UserNotInWaitlistError ( { id : userID } ) ;
512+ }
513+ await this . advance ( { remove : true } ) ;
514+ }
502515}
503516
504517/**
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments