parseIdentifierIntoParts method

SDNIdentifierStringExtensionResults? parseIdentifierIntoParts()

Separate a sdn identifier string into a primary indentifier, a secondary identifier, a query string and already parsed via parameters. A sdn identifier string can be an mxid, a sdn.to-url or a sdn-uri.

Implementation

SDNIdentifierStringExtensionResults? parseIdentifierIntoParts() {
  final uri = _parseIdentifierIntoUri();
  if (uri == null) return null;
  final primary = uri.pathSegments.isNotEmpty ? uri.pathSegments[0] : null;
  if (primary == null || !primary.isValidSDNId) return null;
  final secondary = uri.pathSegments.length > 1 ? uri.pathSegments[1] : null;
  if (secondary != null && !secondary.isValidSDNId) return null;

  return SDNIdentifierStringExtensionResults(
    primaryIdentifier: primary,
    secondaryIdentifier: secondary,
    queryString: uri.query.isNotEmpty ? uri.query : null,
    via: (uri.queryParametersAll['via'] ?? []).toSet(),
    action: uri.queryParameters['action'],
  );
}