forked from Nexus/nexus
use canonical alias ahead of room id for mentions
This commit is contained in:
parent
6e6bcaaad1
commit
a7e60b9464
2 changed files with 30 additions and 21 deletions
|
|
@ -84,6 +84,7 @@ class ComposerDraftController(final ComposerParams composer)
|
||||||
static final _tagPattern = RegExp(
|
static final _tagPattern = RegExp(
|
||||||
r"\[@[^\]]*\]\(matrix:u/([^)\s]+)\)"
|
r"\[@[^\]]*\]\(matrix:u/([^)\s]+)\)"
|
||||||
r"|\[#[^\]]*\]\(matrix:roomid/([^)?\s]+)[^)\s]*\)"
|
r"|\[#[^\]]*\]\(matrix:roomid/([^)?\s]+)[^)\s]*\)"
|
||||||
|
r"|\[#[^\]]*\]\(matrix:r/([^)?\s]+)[^)\s]*\)"
|
||||||
r'|!\[:([^\]\s]+):\]\(mxc://[^)\s]+(?: "(?:[^"\\]|\\.)*")?\)',
|
r'|!\[:([^\]\s]+):\]\(mxc://[^)\s]+(?: "(?:[^"\\]|\\.)*")?\)',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -91,20 +92,26 @@ class ComposerDraftController(final ComposerParams composer)
|
||||||
/// tags, formatted like the composer's tagTextFormatter.
|
/// tags, formatted like the composer's tagTextFormatter.
|
||||||
({String text, IList<Tag> tags}) _restoreTags(String text) {
|
({String text, IList<Tag> tags}) _restoreTags(String text) {
|
||||||
final rooms = ref.read(RoomsController.provider);
|
final rooms = ref.read(RoomsController.provider);
|
||||||
Tag tagOf(Match match) => switch ((match[1], match[2], match[3])) {
|
Tag tagOf(Match match) =>
|
||||||
(final userId?, _, _) => .new(
|
switch ((match[1], match[2], match[3], match[4])) {
|
||||||
|
(final userId?, _, _, _) => .new(
|
||||||
id: match[0]!,
|
id: match[0]!,
|
||||||
text: userId.split(":").first,
|
text: userId.split(":").first,
|
||||||
triggerCharacter: "@",
|
triggerCharacter: "@",
|
||||||
),
|
),
|
||||||
(_, final roomId?, _) => .new(
|
(_, final roomId?, _, _) => .new(
|
||||||
id: match[0]!,
|
id: match[0]!,
|
||||||
text:
|
text:
|
||||||
rooms["!$roomId"]?.metadata?.canonicalAlias?.localpart ??
|
rooms["!$roomId"]?.metadata?.canonicalAlias?.localpart ??
|
||||||
"!$roomId",
|
"!$roomId",
|
||||||
triggerCharacter: "#",
|
triggerCharacter: "#",
|
||||||
),
|
),
|
||||||
(_, _, final shortcode) => .new(
|
(_, _, final alias?, _) => .new(
|
||||||
|
id: match[0]!,
|
||||||
|
text: "#$alias".localpart!,
|
||||||
|
triggerCharacter: "#",
|
||||||
|
),
|
||||||
|
(_, _, _, final shortcode) => .new(
|
||||||
id: match[0]!,
|
id: match[0]!,
|
||||||
text: shortcode!,
|
text: shortcode!,
|
||||||
triggerCharacter: ":",
|
triggerCharacter: ":",
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,11 @@ class const RoomOverlay(
|
||||||
? null
|
? null
|
||||||
: Text(room.metadata!.topic!, maxLines: 1),
|
: Text(room.metadata!.topic!, maxLines: 1),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final vias = ref.watch(ViaController.provider(room)).viaQuery;
|
final alias = room.metadata?.canonicalAlias;
|
||||||
addTag(
|
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:
|
name:
|
||||||
room.metadata?.canonicalAlias?.localpart ??
|
room.metadata?.canonicalAlias?.localpart ??
|
||||||
room.metadata?.id ??
|
room.metadata?.id ??
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue