V2TimConversation.fromJson constructor

V2TimConversation.fromJson(
  1. Map json
)

Implementation

V2TimConversation.fromJson(Map json) {
  json = Utils.formatJson(json);
  String cConvID = json['conv_id'] ?? '';
  type = json['conv_type'] ?? ConversationType.CONVERSATION_TYPE_INVALID;
  switch (type) {
    case ConversationType.V2TIM_C2C:
      userID = cConvID;
      conversationID = 'c2c_$userID';
      break;
    case ConversationType.V2TIM_GROUP:
      groupID = cConvID;
      conversationID = 'group_$groupID';
      break;
    default:
      conversationID = cConvID;
      print('invalid conversation type!');
      break;
  }

  showName = json['conv_show_name'];
  faceUrl = json['conv_face_url'];
  if (json['conv_group_type'] != null) {
    groupType = EnumUtils.cGroupType2DartType(json['conv_group_type']);
  }
  unreadCount = json['conv_unread_num'];
  isPinned = json['conv_is_pinned'];
  recvOpt = EnumUtils.cReceiveMessageOpt2DartOpt(json['conv_recv_opt']).index;
  orderkey = json['conv_active_time'];
  lastMessage = json['conv_last_msg'] != null
      ? V2TimMessage.fromJson(json['conv_last_msg'])
      : null;
  if (json['conv_is_has_draft'] ?? false) {
      V2TimConversationDraft draft = V2TimConversationDraft.fromJson(json['conv_draft'] ?? {});
      draftText = draft.message?.textElem?.text;
      draftTimestamp = draft.editTime;
  }
  customData = json['conv_custom_data'];
  if (json['conv_mark_array'] != null) {
    markList = List.empty(growable: true);
    json['conv_mark_array'].forEach((v) {
      markList?.add(EnumUtils.cConversationMarkType2DartType(v));
    });
  }
  if (json['conv_conversation_group_array'] != null) {
    conversationGroupList = List.empty(growable: true);
    json['conv_conversation_group_array'].forEach((v) {
      conversationGroupList?.add(v);
    });
  }

  if (json['conv_group_at_info_array'] != null) {
    groupAtInfoList = List.empty(growable: true);
    json['conv_group_at_info_array'].forEach((v) {
      groupAtInfoList!.add(V2TimGroupAtInfo.fromJson(v));
    });
  }

  c2cReadTimestamp = json["conv_c2c_read_timestamp"] ?? 0;
  groupReadSequence = json["conv_group_read_sequence"] ?? 0;
}