forked from Henry-Hiles/nexus
shows room but not really
This commit is contained in:
parent
7b0fea3a07
commit
5f96c8e57f
23 changed files with 885 additions and 805 deletions
40
lib/helpers/extensions/link_to_mention.dart
Normal file
40
lib/helpers/extensions/link_to_mention.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
extension LinkToMention on String {
|
||||
/// Extracts a Matrix identifier from this string.
|
||||
///
|
||||
/// Supports:
|
||||
/// - https://matrix.to/#/...
|
||||
/// - matrix:roomid/...
|
||||
/// - matrix:r/...
|
||||
/// - matrix:u/...
|
||||
///
|
||||
/// Returns the decoded identifier (e.g. "#room:matrix.org")
|
||||
/// or null if this is not a Matrix link.
|
||||
String? get mention {
|
||||
final trimmed = trim();
|
||||
|
||||
final matrixTo = RegExp(
|
||||
r"^https?://matrix\.to/#/([^/?#]+)",
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
final matrixToMatch = matrixTo.firstMatch(trimmed);
|
||||
if (matrixToMatch != null) {
|
||||
return Uri.decodeComponent(matrixToMatch.group(1)!);
|
||||
}
|
||||
|
||||
if (trimmed.toLowerCase().startsWith("matrix:")) {
|
||||
try {
|
||||
final uri = Uri.parse(trimmed);
|
||||
|
||||
if (uri.pathSegments.isNotEmpty) {
|
||||
final identifier = uri.pathSegments.last;
|
||||
if (identifier.isNotEmpty) {
|
||||
return Uri.decodeComponent(identifier);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue