// Version: 1.0.0 | Created: 2026-04-02
// Utility extension for extracting the localpart from a Matrix user ID.
// Matrix IDs have the form @localpart:server.name — this extracts "localpart".

/// Extension on [String] for Matrix user ID operations.
extension MatrixIdExtension on String {
  /// Extracts the localpart from a Matrix user ID.
  ///
  /// Example: `'@alice:matrix.m8chat.au'.matrixLocalpart` returns `'alice'`.
  /// Returns the original string unchanged if it does not match the expected
  /// `@localpart:server` format.
  String get matrixLocalpart {
    final value = split(':').first.replaceFirst('@', '');
    return value.isEmpty ? this : value;
  }
}
