pub fn decode_body(bytes: &[u8]) -> Result<DirectMessageBody, String>Expand description
Decode wire bytes back into a DirectMessageBody.
Decoding rules:
- If
bytesis empty → returnsDirectMessageBody::Textwith an empty string. (Defensive — a zero-length plaintext shouldn’t happen in practice but we’d rather surface it as an empty text bubble than an error.) - If
bytes[0] == DM_BODY_MAGIC→ strip the magic byte and CBOR- decode the rest. Failures bubble up asErr(String)so the caller can render a placeholder (matches the existing “unable to decrypt” placeholder UX for inbound DMs). - Otherwise → treat as legacy plaintext, lossy-UTF-8-convert the
entire byte slice, and return
DirectMessageBody::Text. This is the path that keeps DMs sent by pre-Invite clients still rendering as text after this change ships.