onPresence method

  1. @visibleForTesting
Future<StanzaHandlerData> onPresence(
  1. Stanza stanza,
  2. StanzaHandlerData state
)

Implementation

@visibleForTesting
Future<StanzaHandlerData> onPresence(
  Stanza stanza,
  StanzaHandlerData state,
) async {
  if (stanza.from == null) {
    return state;
  }

  final from = JID.fromString(stanza.from!);
  final c = stanza.firstTag('c', xmlns: capsXmlns)!;

  final hashFunctionName = c.attributes['hash'] as String?;
  final capabilityNode = c.attributes['node'] as String?;
  final ver = c.attributes['ver'] as String?;
  if (hashFunctionName == null || capabilityNode == null || ver == null) {
    return state;
  }

  // Check if we know of the hash
  final isCached =
      await _cacheLock.synchronized(() => _capHashCache.containsKey(ver));
  if (isCached) {
    return state;
  }

  unawaited(
    _performQuery(
      stanza,
      ver,
      hashFunctionName,
      capabilityNode,
      from,
    ),
  );
  return state;
}