decode method

  1. @override
void decode(
  1. MessagePayload payload
)
override

Implementation

@override
void decode(MessagePayload payload) {
  super.decode(payload);
  title = payload.content;
  messages = [];
  Map<dynamic, dynamic> map = json.decode(utf8.decode(payload.binaryContent!));
  List<dynamic> ms = map['ms'];
  for (int i = 0; i < ms.length; ++i) {
    Map map = ms[i];
    Message msg = new Message();
    msg.messageUid = map['uid'];
    msg.conversation = new Conversation();
    msg.conversation!.conversationType = ConversationType.values[map['type']];
    msg.conversation!.target = map['target'];
    msg.conversation!.line = map['line'];

    msg.fromUser = map['from'];
    msg.toUsers = map['tos'];
    msg.direction = MessageDirection.MessageDirection_Send;
    if(map['direction'] != null)
      msg.direction = MessageDirection.values[map['direction']];
    msg.status = MessageStatus.values[map['status']];
    msg.serverTime = map['serverTime'];

    MessagePayload payload = new MessagePayload();
    payload.contentType = map['ctype'];
    payload.searchableContent = map['csc'];
    payload.pushContent = map['cpc'];
    payload.pushData = map['cpd'];
    payload.content = map['cc'];
    if (map['cbc'] != null) {
      payload.binaryContent = Base64Decoder().convert(map['cbc']);
    }
    payload.mentionedType = map['cmt'];
    payload.mentionedTargets = map['cmts'];
    payload.extra = map['ce'];
    payload.mediaType = MediaType.values[map['mt']];
    payload.remoteMediaUrl = map['mru'];

    msg.content = FlutterImclient.decodeMessageContent(payload);
    messages.add(msg);
  }
}