buildUpdateMessageMetaArray static method Null safety

Command buildUpdateMessageMetaArray(
  1. BaseMessage message,
  2. List<MessageMetaArray> metaArrays,
  3. MetaArrayUpdateMode updateMode,
  4. bool upsert
)

Implementation

static Command buildUpdateMessageMetaArray(
    BaseMessage message,
    List<MessageMetaArray> metaArrays,
    MetaArrayUpdateMode updateMode,
    bool upsert) {
  if (message.messageId <= 0) {
    throw InvalidParameterError();
  }
  if (metaArrays.isEmpty) {
    throw InvalidParameterError();
  }

  String type;
  if (message is UserMessage) {
    type = CommandString.userMessageUpdate;
  } else if (message is FileMessage) {
    type = CommandString.fileMessageUpdate;
  } else {
    throw InvalidParameterError();
  }

  return Command(cmd: type, payload: {
    'channel_url': message.channelUrl,
    'msg_id': message.messageId,
    'metaarray': {
      'array': metaArrays.map((e) => e.toJson()).toList(),
      'mode': updateMode.asString(),
      'upsert': upsert
    }
  });
}