Fix loading message status from mycelium
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -86,13 +86,13 @@ impl MyceliumClient {
|
|||||||
&self,
|
&self,
|
||||||
id_hex: &str,
|
id_hex: &str,
|
||||||
) -> Result<TransportStatus, MyceliumClientError> {
|
) -> Result<TransportStatus, MyceliumClientError> {
|
||||||
let params = json!({ "id": id_hex });
|
let params = json!(id_hex);
|
||||||
let body = self.jsonrpc("messageStatus", params).await?;
|
let body = self.jsonrpc("getMessageInfo", params).await?;
|
||||||
let result = body.get("result").ok_or_else(|| {
|
let result = body.get("result").ok_or_else(|| {
|
||||||
MyceliumClientError::InvalidResponse(format!("missing result in response: {body}"))
|
MyceliumClientError::InvalidResponse(format!("missing result in response: {body}"))
|
||||||
})?;
|
})?;
|
||||||
// Accept both { status: "..."} and bare "..."
|
// Accept both { state: "..."} and bare "..."
|
||||||
let status_str = if let Some(s) = result.get("status").and_then(|v| v.as_str()) {
|
let status_str = if let Some(s) = result.get("state").and_then(|v| v.as_str()) {
|
||||||
s.to_string()
|
s.to_string()
|
||||||
} else if let Some(s) = result.as_str() {
|
} else if let Some(s) = result.as_str() {
|
||||||
s.to_string()
|
s.to_string()
|
||||||
@@ -101,18 +101,19 @@ impl MyceliumClient {
|
|||||||
"unexpected result shape: {result}"
|
"unexpected result shape: {result}"
|
||||||
)));
|
)));
|
||||||
};
|
};
|
||||||
Self::map_status(&status_str).ok_or_else(|| {
|
let status = Self::map_status(&status_str).ok_or_else(|| {
|
||||||
MyceliumClientError::InvalidResponse(format!("unknown status: {status_str}"))
|
MyceliumClientError::InvalidResponse(format!("unknown status: {status_str}"))
|
||||||
})
|
});
|
||||||
|
tracing::info!(%id_hex, status = %status.as_ref().unwrap(), "queried messages status");
|
||||||
|
status
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_status(s: &str) -> Option<TransportStatus> {
|
fn map_status(s: &str) -> Option<TransportStatus> {
|
||||||
match s {
|
match s {
|
||||||
"queued" => Some(TransportStatus::Queued),
|
"pending" => Some(TransportStatus::Queued),
|
||||||
"sent" => Some(TransportStatus::Sent),
|
"received" => Some(TransportStatus::Delivered),
|
||||||
"delivered" => Some(TransportStatus::Delivered),
|
|
||||||
"read" => Some(TransportStatus::Read),
|
"read" => Some(TransportStatus::Read),
|
||||||
"failed" => Some(TransportStatus::Failed),
|
"aborted" => Some(TransportStatus::Failed),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user