From fd43ed458ae9039158b3d03618308ad9339d5fa6 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 9 Jul 2020 19:25:00 +0200 Subject: [PATCH] Add ResponseMessage::from_request. --- libsignal-service/src/proto.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libsignal-service/src/proto.rs b/libsignal-service/src/proto.rs index 6a612fc17..410bdabad 100644 --- a/libsignal-service/src/proto.rs +++ b/libsignal-service/src/proto.rs @@ -38,3 +38,25 @@ impl WebSocketRequestMessage { false } } + +impl WebSocketResponseMessage { + /// Equivalent of + /// `SignalServiceMessagePipe::isSignalServiceEnvelope(WebSocketMessage)`. + pub fn from_request(msg: &WebSocketRequestMessage) -> Self { + if msg.is_signal_service_envelope() { + WebSocketResponseMessage { + id: msg.id, + status: Some(200), + message: Some("OK".to_string()), + ..Default::default() + } + } else { + WebSocketResponseMessage { + id: msg.id, + status: Some(400), + message: Some("Unknown".to_string()), + ..Default::default() + } + } + } +}