createMessage function

NERoomChatMessage? createMessage(
  1. RoomMessage? message
)

Implementation

NERoomChatMessage? createMessage(RoomMessage? message) {
  if (message != null) {
    switch (message.type) {
      case 'text':
        {
          return _NERoomTextMessageImpl(
            messageUuid: message.uuid,
            fromUserUuid: message.fromAccount,
            fromNick: message.fromNick,
            fromAvatar: message.fromAvatar,
            text: message.content ?? '',
            time: message.time,
            toUserUuidList: message.toAccounts?.whereType<String>().toList(),
            chatroomType: convertToNEChatroomType(message.chatroomType),
          );
        }
      case 'file':
        {
          final attachment = message.attachment as RoomMessageAttachment;
          return _NERoomFileMessageImpl(
            messageUuid: message.uuid,
            fromUserUuid: message.fromAccount,
            fromNick: message.fromNick,
            fromAvatar: message.fromAvatar,
            time: message.time,
            toUserUuidList: message.toAccounts?.whereType<String>().toList(),
            displayName: attachment.displayName,
            extension: attachment.extension,
            md5: attachment.md5,
            url: attachment.url,
            size: attachment.size,
            thumbPath: attachment.thumbPath,
            path: attachment.path,
            chatroomType: convertToNEChatroomType(message.chatroomType),
          );
        }
      case 'image':
        {
          final attachment = message.attachment as RoomMessageAttachment;
          return _NERoomImageMessageImpl(
            messageUuid: message.uuid,
            fromUserUuid: message.fromAccount,
            fromNick: message.fromNick,
            fromAvatar: message.fromAvatar,
            time: message.time,
            toUserUuidList: message.toAccounts?.whereType<String>().toList(),
            displayName: attachment.displayName,
            extension: attachment.extension,
            md5: attachment.md5,
            url: attachment.url,
            size: attachment.size,
            thumbPath: attachment.thumbPath,
            path: attachment.path,
            width: attachment.width ?? 0,
            height: attachment.height ?? 0,
            chatroomType: convertToNEChatroomType(message.chatroomType),
          );
        }
      case 'custom':
        {
          return _NERoomCustomMessageImpl(
            messageUuid: message.uuid,
            fromUserUuid: message.fromAccount,
            fromNick: message.fromNick,
            fromAvatar: message.fromAvatar,
            attachStr: message.content ?? '',
            time: message.time,
            toUserUuidList: message.toAccounts?.whereType<String>().toList(),
            chatroomType: convertToNEChatroomType(message.chatroomType),
          );
        }
      case 'notification':
        {
          final notification = message.notification as RoomNotification;
          NERoomMember? operateBy;
          if (notification.operateBy != null) {
            operateBy = convertMember(notification.operateBy!);
          }
          var eventType = NERoomChatEventType.kUndefined;
          switch (notification.eventType) {
            case 'enter':
              eventType = NERoomChatEventType.kEnter;
              break;
            case 'exit':
              eventType = NERoomChatEventType.kExit;
              break;
            case 'recall':
              eventType = NERoomChatEventType.kRecall;
              break;
            case 'undefined':
              eventType = NERoomChatEventType.kUndefined;
              break;
            default:
              break;
          }
          var members = List<NERoomMember>.empty(growable: true);
          for (var element in notification.members) {
            if (element != null) {
              members.add(convertMember(element));
            }
          }
          var m = _NERoomNotificationMessageImpl(
            messageUuid: message.uuid,
            fromUserUuid: message.fromAccount,
            fromNick: message.fromNick,
            fromAvatar: message.fromAvatar,
            time: message.time,
            toUserUuidList: message.toAccounts?.whereType<String>().toList(),
            eventType: eventType,
            operateBy: operateBy,
            recalledMessageId: message.recallMessageId,
            members: members,
            chatroomType: convertToNEChatroomType(message.chatroomType),
          );
          return m;
        }
    }
  }
  return null;
}