# discoItemsQuery method

Future <Result<StanzaError, List <DiscoItem>>> discoItemsQuery(

1. JID entity,
2. {String? node,
3. bool shouldEncrypt = false}

)

Sends a disco items query to the (full) jid `entity`, optionally with node=`node`.

## Implementation

    Future<Result<StanzaError, List<DiscoItem>>> discoItemsQuery(
      JID entity, {
      String? node,
      bool shouldEncrypt = false,
    }) async {
      final key = DiscoCacheKey(entity, node);
      final future = await _discoItemsTracker.waitFor(key);
      if (future != null) {
        return future;
      }

      final stanza = (await getAttributes().sendStanza(
        StanzaDetails(
          buildDiscoItemsQueryStanza(entity, node: node),
          encrypted: !shouldEncrypt,
        ),
      ))!;

      // Error handling
      if (stanza.attributes['type'] == 'error') {
        final result =
            Result<StanzaError, List<DiscoItem>>(StanzaError.fromXMLNode(stanza));
        await _discoItemsTracker.resolve(key, result);
        return result;
      }

      final query = stanza.firstTag('query');
      if (query == null) {
        final result =
            Result<DiscoError, List<DiscoItem>>(InvalidResponseDiscoError());
        await _discoItemsTracker.resolve(key, result);
        return result;
      }

      final items = query
          .findTags('item')
          .map(
            (node) => DiscoItem(
              jid: JID.fromString(node.attributes['jid']! as String),
              node: node.attributes['node'] as String?,
              name: node.attributes['name'] as String?,
            ),
          )
          .toList();

      final result = Result<DiscoError, List<DiscoItem>>(items);
      await _discoItemsTracker.resolve(key, result);
      return result;
    }