data property

  1. @override
TransportableData get data
override

Encrypted message content (Base64-encoded).

Generated by encrypting the InstantMessage.content with a symmetric key (e.g., AES). Wrapped in TransportableData for standardized encoding/transmission. Cannot be null (core payload of the secure message).

Implementation

@override
TransportableData get data {
  TransportableData? ted = _data;
  if (ted == null) {
    Object? text = this['data'];
    if (text == null) {
      assert(false, 'message data not found: ${super.toMap()}');
    } else if (!BaseMessage.isBroadcast(this)) {
      // message content had been encrypted by a symmetric key,
      // so the data should be encoded here (with algorithm 'base64' as default).
      ted = TransportableData.parse(text);
    } else if (text is String) {
      // broadcast message content will not be encrypted (just encoded to JsON),
      // so return the string data directly
      ted = PlainData.createWithString(text);  // JsON
    } else {
      assert(false, 'content data error: $text');
    }
    _data = ted;
  }
  return ted!;
}