toJson method

  1. @override
Map<String, dynamic> toJson()
override

Implementation

@override
Map<String, dynamic> toJson() {
  Map<String, dynamic> message = {};
  message['id'] = id;
  if (typ != null) message['typ'] = typ!.value;
  message['type'] = type;
  if (from != null) message['from'] = from;
  if (to != null) message['to'] = to;
  if (threadId != null) message['thid'] = threadId;
  if (parentThreadId != null) message['pthid'] = parentThreadId;
  if (createdTime != null) {
    message['created_time'] = createdTime!.millisecondsSinceEpoch ~/ 1000;
  }
  if (expiresTime != null) {
    message['expires_time'] = expiresTime!.millisecondsSinceEpoch ~/ 1000;
  }

  if (pleaseAck != null) message['please_ack'] = pleaseAck;
  if (ack != null) message['ack'] = ack;
  if (webRedirect != null) message['web_redirect'] = webRedirect!.toJson();
  if (returnRoute != null) message['return_route'] = returnRoute!.value;
  if (additionalHeaders != null) message.addAll(additionalHeaders!);
  message['body'] = body;

  //TODO: from_prior header

  if (attachments != null) {
    List<Map<String, dynamic>> tmp = [];
    for (var a in attachments!) {
      tmp.add(a.toJson());
    }
    message['attachments'] = tmp;
  }

  if (replyUrl != null) message['reply_url'] = replyUrl;
  if (replyTo != null) message['reply_to'] = replyTo;

  return message;
}