# preprocessPublishOptions method

1. @visibleForTesting

Future <PubSubPublishOptions> preprocessPublishOptions(

1. JID jid,
2. String node,
3. PubSubPublishOptions options

)

## Implementation

    @visibleForTesting
    Future<PubSubPublishOptions> preprocessPublishOptions(
      JID jid,
      String node,
      PubSubPublishOptions options,
    ) async {
      if (options.maxItems != null) {
        final dm = getAttributes().getManagerById<DiscoManager>(discoManager)!;
        final result = await dm.discoInfoQuery(jid);
        if (result.isType<DiscoError>()) {
          if (options.maxItems == 'max') {
            logger.severe(
              'disco#info query failed and options.maxItems is set to "max".',
            );
            return options;
          }
        }

        final nodeMultiItemsSupported = result.isType<DiscoInfo>() &&
            result.get<DiscoInfo>().features.contains(pubsubNodeConfigMultiItems);
        final nodeMaxSupported = result.isType<DiscoInfo>() &&
            result.get<DiscoInfo>().features.contains(pubsubNodeConfigMax);
        if (options.maxItems != null && !nodeMultiItemsSupported) {
          // TODO(PapaTutuWawa): Here, we need to admit defeat
          logger.finest('PubSub host does not support multi-items!');

          return PubSubPublishOptions(
            accessModel: options.accessModel,
          );
        } else if (options.maxItems == 'max' && !nodeMaxSupported) {
          logger.finest(
            'PubSub host does not support node-config-max. Working around it',
          );
          final count = await _getNodeItemCount(jid, node) + 1;

          return PubSubPublishOptions(
            accessModel: options.accessModel,
            maxItems: '$count',
          );
        }
      }

      return options;
    }