Skip to main content

decode_body

Function decode_body 

Source
pub fn decode_body(bytes: &[u8]) -> Result<DirectMessageBody, String>
Expand description

Decode wire bytes back into a DirectMessageBody.

Decoding rules:

  1. If bytes is empty → returns DirectMessageBody::Text with 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.)
  2. If bytes[0] == DM_BODY_MAGIC → strip the magic byte and CBOR- decode the rest. Failures bubble up as Err(String) so the caller can render a placeholder (matches the existing “unable to decrypt” placeholder UX for inbound DMs).
  3. 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.