toJson method

Map<String, dynamic> toJson()

Implementation

Map<String, dynamic> toJson() {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['conv_type'] = type;
  String cConvID = '';
  switch (type) {
    case ConversationType.V2TIM_C2C:
      cConvID = userID ?? '';
      break;
    case ConversationType.V2TIM_GROUP:
      cConvID = groupID ?? '';
      break;
    default:
      cConvID = conversationID;
      print('invalid conversation type!');
      break;
  }
  data['conv_id'] = cConvID;
  data['conv_show_name'] = showName;
  data['conv_face_url'] = faceUrl;
  data['conv_group_type'] = groupType;
  data['conv_unread_num'] = unreadCount;
  data['conv_is_pinned'] = isPinned;
  data['conv_recv_opt'] = recvOpt;
  data['conv_active_time'] = orderkey;
  data['conv_custom_data'] = customData;
  data['conv_c2c_read_timestamp'] = c2cReadTimestamp ?? 0;
  data['conv_group_read_sequence'] = groupReadSequence ?? 0;

  if (lastMessage != null) {
    data['conv_last_msg'] = lastMessage!.toJson();
  }

  if (draftText != null && draftText!.isNotEmpty) {
    data['conv_is_has_draft'] = true;

    V2TimTextElem textElem = V2TimTextElem(text: draftText);
    V2TimMessage v2timMessage = V2TimMessage(elemType: MessageElemType.V2TIM_ELEM_TYPE_TEXT);
    v2timMessage.elemList.add(textElem);
    data['conv_draft'] = V2TimConversationDraft(message: v2timMessage, customData: draftText, editTime: draftTimestamp).toJson();
  }

  if (groupAtInfoList != null) {
    data['conv_group_at_info_array'] =
        groupAtInfoList?.map((v) => v?.toJson()).toList();
  }
  if (conversationGroupList != null) {
    data['conv_conversation_group_array'] =
        conversationGroupList?.map((v) => v).toList();
  }
  if (markList != null) {
    data['conv_mark_array'] = markList?.map((v) => v).toList();
  }
  return data;
}