ChatRoomMessage.from constructor

ChatRoomMessage.from(
  1. Map<String, dynamic> data
)

Implementation

ChatRoomMessage.from(Map<String, dynamic> data) {
  oId = data['oId'] ?? '';
  userOId = data['userOId'] ?? 0;
  userName = data['userName'] ?? '';
  nickname = data['userNickname'] ?? '';
  avatarURL = data['userAvatarURL'] ?? '';
  sysMetal = toMetal(data['sysMetal']);
  via = ChatSource.from(data['client']);
  content = data['content'];
  md = data['md'] ?? data['content'] ?? '';
  try {
    dynamic contentData = json.decode(data['content'] ?? 'null');
    type = contentData["msgType"];
    if (type == ChatRoomMessageType.redPacket) {
      redpacket = RedPacketMessage.from(contentData);
    } else if (type == ChatRoomMessageType.weather) {
      weather = WeatherMsg.from(contentData);
    } else if (type == ChatRoomMessageType.music) {
      music = MusicMsg.from(contentData);
    } else {
      unknown = contentData;
    }
    // ignore: empty_catches
  } catch (e) {}
  time = data['time'];
}