From f271681b5dcb1c641f45a2c5f08df721230d9289 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 4 Nov 2025 22:04:36 +0800 Subject: [PATCH] :zap: Ring service now provide batch variant of get websocket status endpoint --- .../Services/PusherServiceGrpc.cs | 21 ++- DysonNetwork.Shared/Proto/ring.proto | 121 ++++++++++-------- 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/DysonNetwork.Ring/Services/PusherServiceGrpc.cs b/DysonNetwork.Ring/Services/PusherServiceGrpc.cs index ef133e6..15758c7 100644 --- a/DysonNetwork.Ring/Services/PusherServiceGrpc.cs +++ b/DysonNetwork.Ring/Services/PusherServiceGrpc.cs @@ -2,6 +2,7 @@ using DysonNetwork.Ring.Connection; using DysonNetwork.Ring.Notification; using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Proto; +using Google.Protobuf.Collections; using Google.Protobuf.WellKnownTypes; using Grpc.Core; @@ -44,7 +45,7 @@ public class RingServiceGrpc( } public override Task PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest request, - ServerCallContext context) + ServerCallContext context) { var packet = Shared.Models.WebSocketPacket.FromProtoValue(request.Packet); @@ -139,10 +140,24 @@ public class RingServiceGrpc( { GetWebsocketConnectionStatusRequest.IdOneofCase.DeviceId => WebSocketService.GetDeviceIsConnected(request.DeviceId), - GetWebsocketConnectionStatusRequest.IdOneofCase.UserId => WebSocketService.GetAccountIsConnected(Guid.Parse(request.UserId)), + GetWebsocketConnectionStatusRequest.IdOneofCase.UserId => WebSocketService.GetAccountIsConnected( + Guid.Parse(request.UserId)), _ => false }; return Task.FromResult(new GetWebsocketConnectionStatusResponse { IsConnected = isConnected }); } -} + + public override Task GetWebsocketConnectionStatusBatch( + GetWebsocketConnectionStatusBatchRequest request, ServerCallContext context) + { + var resp = new GetWebsocketConnectionStatusBatchResponse(); + foreach (var id in request.UsersId) + { + var gid = Guid.Parse(id); + resp.IsConnected[id] = WebSocketService.GetAccountIsConnected(gid); + } + + return Task.FromResult(resp); + } +} \ No newline at end of file diff --git a/DysonNetwork.Shared/Proto/ring.proto b/DysonNetwork.Shared/Proto/ring.proto index aba6010..3632de8 100644 --- a/DysonNetwork.Shared/Proto/ring.proto +++ b/DysonNetwork.Shared/Proto/ring.proto @@ -12,117 +12,126 @@ import "account.proto"; // RingService provides methods to send various types of notifications. service RingService { - // Sends an email. - rpc SendEmail(SendEmailRequest) returns (google.protobuf.Empty) {} + // Sends an email. + rpc SendEmail(SendEmailRequest) returns (google.protobuf.Empty) {} - // Pushes a packet to a user via WebSocket. - rpc PushWebSocketPacket(PushWebSocketPacketRequest) returns (google.protobuf.Empty) {} + // Pushes a packet to a user via WebSocket. + rpc PushWebSocketPacket(PushWebSocketPacketRequest) returns (google.protobuf.Empty) {} - // Pushes a packet to a list of users via WebSocket. - rpc PushWebSocketPacketToUsers(PushWebSocketPacketToUsersRequest) returns (google.protobuf.Empty) {} + // Pushes a packet to a list of users via WebSocket. + rpc PushWebSocketPacketToUsers(PushWebSocketPacketToUsersRequest) returns (google.protobuf.Empty) {} - // Pushes a packet to a device via WebSocket. - rpc PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest) returns (google.protobuf.Empty) {} + // Pushes a packet to a device via WebSocket. + rpc PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest) returns (google.protobuf.Empty) {} - // Pushes a packet to a list of devices via WebSocket. - rpc PushWebSocketPacketToDevices(PushWebSocketPacketToDevicesRequest) returns (google.protobuf.Empty) {} + // Pushes a packet to a list of devices via WebSocket. + rpc PushWebSocketPacketToDevices(PushWebSocketPacketToDevicesRequest) returns (google.protobuf.Empty) {} - // Sends a push notification to a user. - rpc SendPushNotificationToUser(SendPushNotificationToUserRequest) returns (google.protobuf.Empty) {} + // Sends a push notification to a user. + rpc SendPushNotificationToUser(SendPushNotificationToUserRequest) returns (google.protobuf.Empty) {} - // Sends a push notification to a list of users. - rpc SendPushNotificationToUsers(SendPushNotificationToUsersRequest) returns (google.protobuf.Empty) {} + // Sends a push notification to a list of users. + rpc SendPushNotificationToUsers(SendPushNotificationToUsersRequest) returns (google.protobuf.Empty) {} - // Unsubscribes a device from push notifications. - rpc UnsubscribePushNotifications(UnsubscribePushNotificationsRequest) returns (google.protobuf.Empty) {} + // Unsubscribes a device from push notifications. + rpc UnsubscribePushNotifications(UnsubscribePushNotificationsRequest) returns (google.protobuf.Empty) {} - // Gets the WebSocket connection status for a device or user. - rpc GetWebsocketConnectionStatus(GetWebsocketConnectionStatusRequest) returns (GetWebsocketConnectionStatusResponse) {} + // Gets the WebSocket connection status for a device or user. + rpc GetWebsocketConnectionStatus(GetWebsocketConnectionStatusRequest) returns (GetWebsocketConnectionStatusResponse) {} + + rpc GetWebsocketConnectionStatusBatch(GetWebsocketConnectionStatusBatchRequest) returns (GetWebsocketConnectionStatusBatchResponse) {} } // Represents an email message. message EmailMessage { - string to_name = 1; - string to_address = 2; - string subject = 3; - string body = 4; + string to_name = 1; + string to_address = 2; + string subject = 3; + string body = 4; } message SendEmailRequest { - EmailMessage email = 1; + EmailMessage email = 1; } // Represents a WebSocket packet. message WebSocketPacket { - string type = 1; - bytes data = 2; - google.protobuf.StringValue error_message = 3; + string type = 1; + bytes data = 2; + google.protobuf.StringValue error_message = 3; } message PushWebSocketPacketRequest { - string user_id = 1; - WebSocketPacket packet = 2; + string user_id = 1; + WebSocketPacket packet = 2; } message PushWebSocketPacketToUsersRequest { - repeated string user_ids = 1; - WebSocketPacket packet = 2; + repeated string user_ids = 1; + WebSocketPacket packet = 2; } message PushWebSocketPacketToDeviceRequest { - string device_id = 1; - WebSocketPacket packet = 2; + string device_id = 1; + WebSocketPacket packet = 2; } message PushWebSocketPacketToDevicesRequest { - repeated string device_ids = 1; - WebSocketPacket packet = 2; + repeated string device_ids = 1; + WebSocketPacket packet = 2; } // Represents a push notification. message PushNotification { - string topic = 1; - string title = 2; - string subtitle = 3; - string body = 4; - optional bytes meta = 5; - optional string action_uri = 6; - bool is_silent = 7; - bool is_savable = 8; + string topic = 1; + string title = 2; + string subtitle = 3; + string body = 4; + optional bytes meta = 5; + optional string action_uri = 6; + bool is_silent = 7; + bool is_savable = 8; } message SendPushNotificationToUserRequest { - string user_id = 1; - PushNotification notification = 2; + string user_id = 1; + PushNotification notification = 2; } message SendPushNotificationToUsersRequest { - repeated string user_ids = 1; - PushNotification notification = 2; + repeated string user_ids = 1; + PushNotification notification = 2; } message UnsubscribePushNotificationsRequest { - string device_id = 1; + string device_id = 1; } message GetWebsocketConnectionStatusRequest { - oneof id { - string device_id = 1; - string user_id = 2; - } + oneof id { + string device_id = 1; + string user_id = 2; + } } message GetWebsocketConnectionStatusResponse { - bool is_connected = 1; + bool is_connected = 1; } +message GetWebsocketConnectionStatusBatchRequest { + repeated string users_id = 1; +} + +message GetWebsocketConnectionStatusBatchResponse { + map is_connected = 1; +} service RingHandlerService { - rpc ReceiveWebSocketPacket(ReceiveWebSocketPacketRequest) returns (google.protobuf.Empty) {} + rpc ReceiveWebSocketPacket(ReceiveWebSocketPacketRequest) returns (google.protobuf.Empty) {} } message ReceiveWebSocketPacketRequest { - WebSocketPacket packet = 1; - Account account = 2; - string device_id = 3; + WebSocketPacket packet = 1; + Account account = 2; + string device_id = 3; }