Add "queue to waitingroom" feature
All checks were successful
Check / mypy (push) Successful in 52s
Check / ruff (push) Successful in 5s

This commit is contained in:
Christoph Stahl 2025-05-24 09:42:55 +02:00
parent 648d3afc21
commit 1d1e94da85
2 changed files with 41 additions and 0 deletions

View file

@ -120,6 +120,20 @@ class Queue:
return item return item
return None return None
def find_all_by_name(self, name: str) -> Iterable[Entry]:
"""
Find all entries by their performer and return them as an iterable.
:param name: The name of the performer to search for.
:type name: str
:returns: The entries with the performer.
:rtype: Iterable[Entry]
"""
for item in self._queue:
if item.shares_performer(name):
yield item
def find_by_uuid(self, uuid: UUID | str) -> Optional[Entry]: def find_by_uuid(self, uuid: UUID | str) -> Optional[Entry]:
""" """
Find an entry by its uuid and return it. Find an entry by its uuid and return it.

View file

@ -682,6 +682,33 @@ class Server:
await self.sio.emit("play", current, room=sid) await self.sio.emit("play", current, room=sid)
@admin
@with_state
async def handle_queue_to_waiting_room(
self, state: State, sid: str, data: dict[str, Any]
) -> None:
"""
Handle the "queue-to-waiting" message.
If on an admin-connection, removes a song from the queue and appends it to
the waiting room. If the performer has only one entry in the queue, it is
put back into the queue immediately.
:param sid: The session id of the requesting client
:type sid: str
:rtype: None
"""
entry = state.queue.find_by_uuid(data["uuid"])
if entry is not None:
performer_entries = list(state.queue.find_all_by_name(entry.performer))
print(performer_entries)
if len(performer_entries) == 1:
return
await state.queue.remove(entry)
state.waiting_room.append(entry)
await self.broadcast_state(state, sid=sid)
@admin @admin
@with_state @with_state
async def handle_waiting_room_to_queue( async def handle_waiting_room_to_queue(