diff --git a/BililiveRecorder.Web/Graphql/RecorderQuery.cs b/BililiveRecorder.Web/Graphql/RecorderQuery.cs index 5d9bb41..3f9095c 100644 --- a/BililiveRecorder.Web/Graphql/RecorderQuery.cs +++ b/BililiveRecorder.Web/Graphql/RecorderQuery.cs @@ -28,7 +28,29 @@ namespace BililiveRecorder.Web.Graphql this.Field("defaultConfig", resolve: context => DefaultConfig.Instance); - this.Field>("rooms", resolve: context => this.recorder.Rooms); + this.Field>("rooms", arguments: new QueryArguments( + new QueryArgument> { Name = "objectIds" }, + new QueryArgument> { Name = "roomIds" } + ), + resolve: context => + { + var objectIds = context.GetArgument("objectIds"); + var roomIds = context.GetArgument("roomIds"); + + // If no arguments are provided, return all rooms + if (objectIds == null && roomIds == null) + return this.recorder.Rooms; + + // Remove any "0" from the roomIds + roomIds = roomIds?.Where(x => x != 0).ToArray(); + + // Otherwise, filter the rooms + return this.recorder.Rooms.Where(x => + (objectIds?.Contains(x.ObjectId) ?? false) || + (roomIds?.Contains(x.RoomConfig.RoomId) ?? false) || + (roomIds?.Contains(x.ShortId) ?? false) + ); + }); this.Field("room", arguments: new QueryArguments( @@ -38,11 +60,15 @@ namespace BililiveRecorder.Web.Graphql resolve: context => { var objectId = context.GetArgument("objectId"); - var roomid = context.GetArgument("roomId"); + var roomId = context.GetArgument("roomId"); - var room = objectId != default - ? this.recorder.Rooms.FirstOrDefault(x => x.ObjectId == objectId) - : this.recorder.Rooms.FirstOrDefault(x => x.RoomConfig.RoomId == roomid || x.ShortId == roomid); + IRoom? room; + if (objectId != default) + room = this.recorder.Rooms.FirstOrDefault(x => x.ObjectId == objectId); + else if (roomId != 0) + room = this.recorder.Rooms.FirstOrDefault(x => x.RoomConfig.RoomId == roomId || x.ShortId == roomId); + else + room = null; return room; }