From 1d1e94da851c8eb9bc94f85235179a4f091cd910 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Sat, 24 May 2025 09:42:55 +0200 Subject: [PATCH] Add "queue to waitingroom" feature --- syng/queue.py | 14 ++++++++++++++ syng/server.py | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/syng/queue.py b/syng/queue.py index 3078fae..d7e5566 100644 --- a/syng/queue.py +++ b/syng/queue.py @@ -120,6 +120,20 @@ class Queue: return item 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]: """ Find an entry by its uuid and return it. diff --git a/syng/server.py b/syng/server.py index ddfadc2..383266e 100644 --- a/syng/server.py +++ b/syng/server.py @@ -682,6 +682,33 @@ class Server: 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 @with_state async def handle_waiting_room_to_queue(