derivePairDisplayName function

String derivePairDisplayName(
  1. String? webId
)

Returns a human-readable label for the POD addressed by webId, used purely for UI surfacing (notification centre listings, error dialogs).

Currently this is the first non-trivial path segment of the WebID (typically the POD name) — john-doe for https://pods.solidcommunity.au/john-doe/profile/card#me. Falls back to the WebID itself when the URL cannot be parsed.

Implementation

String derivePairDisplayName(String? webId) {
  if (webId == null || webId.isEmpty) return '';
  try {
    final uri = Uri.parse(webId);
    for (final segment in uri.pathSegments) {
      if (segment.isEmpty) continue;
      if (segment == 'profile' || segment == 'card') continue;
      if (segment.startsWith('#')) continue;
      return segment;
    }
    return webId;
  } on FormatException {
    return webId;
  }
}