diff --git a/lib/controllers/composer_draft.dart b/lib/controllers/composer_draft.dart index c6e8e78..65eb3cb 100644 --- a/lib/controllers/composer_draft.dart +++ b/lib/controllers/composer_draft.dart @@ -84,6 +84,7 @@ class ComposerDraftController(final ComposerParams composer) static final _tagPattern = RegExp( r"\[@[^\]]*\]\(matrix:u/([^)\s]+)\)" r"|\[#[^\]]*\]\(matrix:roomid/([^)?\s]+)[^)\s]*\)" + r"|\[#[^\]]*\]\(matrix:r/([^)?\s]+)[^)\s]*\)" r'|!\[:([^\]\s]+):\]\(mxc://[^)\s]+(?: "(?:[^"\\]|\\.)*")?\)', ); @@ -91,25 +92,31 @@ class ComposerDraftController(final ComposerParams composer) /// tags, formatted like the composer's tagTextFormatter. ({String text, IList tags}) _restoreTags(String text) { final rooms = ref.read(RoomsController.provider); - Tag tagOf(Match match) => switch ((match[1], match[2], match[3])) { - (final userId?, _, _) => .new( - id: match[0]!, - text: userId.split(":").first, - triggerCharacter: "@", - ), - (_, final roomId?, _) => .new( - id: match[0]!, - text: - rooms["!$roomId"]?.metadata?.canonicalAlias?.localpart ?? - "!$roomId", - triggerCharacter: "#", - ), - (_, _, final shortcode) => .new( - id: match[0]!, - text: shortcode!, - triggerCharacter: ":", - ), - }; + Tag tagOf(Match match) => + switch ((match[1], match[2], match[3], match[4])) { + (final userId?, _, _, _) => .new( + id: match[0]!, + text: userId.split(":").first, + triggerCharacter: "@", + ), + (_, final roomId?, _, _) => .new( + id: match[0]!, + text: + rooms["!$roomId"]?.metadata?.canonicalAlias?.localpart ?? + "!$roomId", + triggerCharacter: "#", + ), + (_, _, final alias?, _) => .new( + id: match[0]!, + text: "#$alias".localpart!, + triggerCharacter: "#", + ), + (_, _, _, final shortcode) => .new( + id: match[0]!, + text: shortcode!, + triggerCharacter: ":", + ), + }; return ( text: text.replaceAllMapped(_tagPattern, (match) { diff --git a/lib/widgets/composer/overlays/room_overlay.dart b/lib/widgets/composer/overlays/room_overlay.dart index f6b4bed..0c2fed9 100644 --- a/lib/widgets/composer/overlays/room_overlay.dart +++ b/lib/widgets/composer/overlays/room_overlay.dart @@ -42,9 +42,11 @@ class const RoomOverlay( ? null : Text(room.metadata!.topic!, maxLines: 1), onTap: () { - final vias = ref.watch(ViaController.provider(room)).viaQuery; + final alias = room.metadata?.canonicalAlias; addTag( - id: "[#$name](matrix:roomid/${room.metadata?.id.substring(1)}$vias)", + id: alias == null + ? "[#$name](matrix:roomid/${room.metadata?.id.substring(1)}${ref.read(ViaController.provider(room)).viaQuery})" + : "[#$name](matrix:r/${alias.substring(1)})", name: room.metadata?.canonicalAlias?.localpart ?? room.metadata?.id ??