v2TimMessageElem2CElem static method

Map<String, dynamic> v2TimMessageElem2CElem(
  1. int type,
  2. V2TimMessage message
)

Implementation

static Map<String, dynamic> v2TimMessageElem2CElem(int type, V2TimMessage message) {
  Map<String, dynamic> map = {};
  switch (type) {
    case MessageElemType.V2TIM_ELEM_TYPE_TEXT:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Text,
        "text_elem_content": message.textElem?.text,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_CUSTOM:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Custom,
        "custom_elem_data": message.customElem?.data,
        "custom_elem_desc": message.customElem?.desc,
        "custom_elem_ext": message.customElem?.extension,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_IMAGE:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Image,
        "image_elem_orig_path": message.imageElem?.path,
        "image_elem_orig_id": message.imageElem?.imageList![0]?.uuid,
        "image_elem_orig_pic_height": message.imageElem?.imageList![0]?.height,
        "image_elem_orig_pic_width": message.imageElem?.imageList![0]?.width,
        "image_elem_orig_url": message.imageElem?.imageList![0]?.url,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_SOUND:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Sound,
        "sound_elem_file_path": message.soundElem?.path,
        "sound_elem_file_id": message.soundElem?.UUID,
        "sound_elem_file_size": message.soundElem?.dataSize,
        "sound_elem_file_time": message.soundElem?.duration,
        "sound_elem_url": message.soundElem?.url,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_VIDEO:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Video,
        "video_elem_video_path": message.videoElem?.videoPath,
        "video_elem_video_id": message.videoElem?.UUID,
        "video_elem_video_size": message.videoElem?.videoSize,
        "video_elem_video_duration": message.videoElem?.duration,
        "video_elem_image_path": message.videoElem?.snapshotPath,
        "video_elem_image_id": message.videoElem?.snapshotUUID,
        "video_elem_image_size": message.videoElem?.snapshotSize,
        "video_elem_image_width": message.videoElem?.snapshotWidth,
        "video_elem_image_height": message.videoElem?.snapshotHeight,
        "video_elem_video_url": message.videoElem?.videoUrl,
        "video_elem_image_url": message.videoElem?.snapshotUrl,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_FILE:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_File,
        "file_elem_file_path": message.fileElem?.path,
        "file_elem_file_name": message.fileElem?.fileName,
        "file_elem_file_id": message.fileElem?.UUID,
        "file_elem_url": message.fileElem?.url,
        "file_elem_file_size": message.fileElem?.fileSize
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_LOCATION:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Location,
        "location_elem_desc": message.locationElem?.desc,
        "location_elem_longitude": message.locationElem?.longitude,
        "location_elem_latitude": message.locationElem?.latitude,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_FACE:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Face,
        "face_elem_index": message.faceElem?.index,
        "face_elem_buf": message.faceElem?.data,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS:
      List memberInfo = List.empty(growable: true);
      if (message.groupTipsElem?.memberList != null) {
        message.groupTipsElem?.memberList?.forEach((element) {
          memberInfo.add(groupMemberInfo2CGroupMemberInfo(element));
        });
      }
      List memberchange = List.empty(growable: true);
      if (message.groupTipsElem?.memberChangeInfoList != null) {
        message.groupTipsElem?.memberChangeInfoList?.forEach((element) {
          memberchange.add(memberChangeInfo2CMemberChange(element));
        });
      }
      List groupchange = List.empty(growable: true);
      if (message.groupTipsElem?.groupChangeInfoList != null) {
        message.groupTipsElem?.groupChangeInfoList?.forEach((element) {
          groupchange.add(groupChangeInfo2CGroupChange(element));
        });
      }
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_GroupTips,
        "group_tips_elem_group_id": message.groupTipsElem?.groupID,
        "group_tips_elem_tip_type": (message.groupTipsElem?.type ?? 1) - 1,
        "group_tips_elem_op_user_info": groupMemberInfo2CUserProfile(message.groupTipsElem?.opMember),
        // memberInfo = object[groupMemberInfo]??
        "group_tips_elem_op_group_memberinfo": memberInfo,
        "group_tips_elem_member_change_info_array": memberchange,
        "group_tips_elem_group_change_info_array": groupchange,
        "group_tips_elem_member_num": message.groupTipsElem?.memberCount,
      });
      break;
    case MessageElemType.V2TIM_ELEM_TYPE_MERGER:
      map.addAll({
        "elem_type": TIMElemType.kTIMElem_Merge,
        "merge_elem_layer_over_limit": message.mergerElem?.isLayersOverLimit,
        "merge_elem_title": message.mergerElem?.title,
        "merge_elem_abstract_array": message.mergerElem?.abstractList,
      });
      break;
    default:
  }
  return map;
}