fix issue when mentioning room with invalid canonical aliases

This commit is contained in:
Henry Hiles 2026-11-24 12:57:19 -05:00
commit b0d22e5570
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
20 changed files with 35 additions and 32 deletions

View file

@ -66,7 +66,7 @@ class BotArgumentSuggestionsController(final ComposerParams composer)
), ),
) => ) =>
BotArgumentSuggestion( BotArgumentSuggestion(
title: displayName ?? userId.localpart, title: displayName ?? userId.localpart!,
subtitle: userId, subtitle: userId,
avatar: avatarUrl, avatar: avatarUrl,
text: userId, text: userId,

View file

@ -50,7 +50,7 @@ class BotCommandsController(final String roomId)
) => ) =>
BotCommand( BotCommand(
sender: sender, sender: sender,
botName: displayName ?? sender.localpart, botName: displayName ?? sender.localpart!,
botAvatar: avatarUrl, botAvatar: avatarUrl,
description: description, description: description,
), ),

View file

@ -756,7 +756,7 @@ class SettingsSectionsController
return ListTile( return ListTile(
enabled: !saving.active, enabled: !saving.active,
leading: AvatarOrHash(profile?.avatarUrl, name), leading: AvatarOrHash(profile?.avatarUrl, name!),
title: Text(name, overflow: .ellipsis), title: Text(name, overflow: .ellipsis),
subtitle: Text(userId, overflow: .ellipsis), subtitle: Text(userId, overflow: .ellipsis),
onTap: () => context.showAdaptiveSheet( onTap: () => context.showAdaptiveSheet(

View file

@ -1,5 +1,5 @@
extension GetLocalpart on String { extension GetLocalpart on String {
String get localpart => length > 1 ? substring(1).split(":").first : "?"; String? get localpart => length > 1 ? substring(1).split(":").first : null;
/// Whether this looks like a valid Matrix user ID, e.g. `@user:example.com`. /// Whether this looks like a valid Matrix user ID, e.g. `@user:example.com`.
bool get isValidUserId => RegExp(r"^@[^:\s]+:[^\s]+$").hasMatch(this); bool get isValidUserId => RegExp(r"^@[^:\s]+:[^\s]+$").hasMatch(this);

View file

@ -2,6 +2,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:material_ui/material_ui.dart"; import "package:material_ui/material_ui.dart";
import "package:nexus/controllers/rooms.dart"; import "package:nexus/controllers/rooms.dart";
import "package:nexus/controllers/via.dart"; import "package:nexus/controllers/via.dart";
import "package:nexus/helpers/extensions/get_localpart.dart";
import "package:nexus/helpers/extensions/weighted_search.dart"; import "package:nexus/helpers/extensions/weighted_search.dart";
import "package:nexus/widgets/avatars/avatar_or_hash.dart"; import "package:nexus/widgets/avatars/avatar_or_hash.dart";
@ -45,11 +46,9 @@ class const RoomOverlay(
addTag( addTag(
id: "[#$name](matrix:roomid/${room.metadata?.id.substring(1)}$vias)", id: "[#$name](matrix:roomid/${room.metadata?.id.substring(1)}$vias)",
name: name:
(room.metadata?.canonicalAlias ?? room.metadata?.id) room.metadata?.canonicalAlias?.localpart ??
?.substring(1) room.metadata?.id ??
.split(":") "Unknown Room",
.first ??
"",
); );
}, },
); );

View file

@ -36,13 +36,13 @@ class const UserOverlay(
ListTile( ListTile(
leading: AvatarOrHash( leading: AvatarOrHash(
avatarUrl, avatarUrl,
displayName ?? member.stateKey!.localpart, displayName ?? member.stateKey!.localpart!,
), ),
title: Text(displayName ?? member.stateKey!.localpart), title: Text(displayName ?? member.stateKey!.localpart!),
subtitle: Text(member.stateKey!), subtitle: Text(member.stateKey!),
onTap: () => addTag( onTap: () => addTag(
id: "[@${displayName ?? member.stateKey!.localpart}](matrix:u/${member.stateKey!.substring(1)})", id: "[@${displayName ?? member.stateKey!.localpart}](matrix:u/${member.stateKey!.substring(1)})",
name: member.stateKey!.localpart, name: member.stateKey!.localpart!,
), ),
), ),
_ => SizedBox.shrink(), _ => SizedBox.shrink(),

View file

@ -37,7 +37,7 @@ class const TypingIndicator(final String roomId, {super.key})
) )
.value .value
?.displayName ?? ?.displayName ??
typingUserId.localpart, typingUserId.localpart!,
userId: typingUserId, userId: typingUserId,
roomId: roomId, roomId: roomId,
recognizer: recognizers[index], recognizer: recognizers[index],

View file

@ -19,10 +19,10 @@ class const MessageAvatar(
context.showUserPopover(event.sender, roomId: event.roomId), context.showUserPopover(event.sender, roomId: event.roomId),
child: AvatarOrHash( child: AvatarOrHash(
value.avatarUrl, value.avatarUrl,
value.displayName ?? event.sender.localpart, value.displayName ?? event.sender.localpart!,
dimension: height, dimension: height,
), ),
), ),
_ => AvatarOrHash(null, event.sender.localpart, dimension: height), _ => AvatarOrHash(null, event.sender.localpart!, dimension: height),
}; };
} }

View file

@ -27,7 +27,7 @@ class const MessageDisplayname(
: null, : null,
child: switch ([ child: switch ([
Text( Text(
value?.displayName ?? event.sender.localpart, value?.displayName ?? event.sender.localpart!,
style: style ?? .new(color: color, fontWeight: .bold), style: style ?? .new(color: color, fontWeight: .bold),
maxLines: 1, maxLines: 1,
overflow: .ellipsis, overflow: .ellipsis,

View file

@ -118,7 +118,7 @@ class const ReactionsPopover(
return ListTile( return ListTile(
leading: AvatarOrHash( leading: AvatarOrHash(
member?.avatarUrl, member?.avatarUrl,
name, name!,
dimension: 40, dimension: 40,
), ),
title: Text(name, overflow: .ellipsis), title: Text(name, overflow: .ellipsis),

View file

@ -73,7 +73,7 @@ class const ReadReceiptsRow(
receipt.userId.localpart; receipt.userId.localpart;
return AvatarRing( return AvatarRing(
tooltip: name, tooltip: name!,
onTap: () => context.showUserPopover( onTap: () => context.showUserPopover(
receipt.userId, receipt.userId,
roomId: chat.roomId, roomId: chat.roomId,

View file

@ -38,7 +38,7 @@ class const ReadReceiptsSheet(
final name = member?.displayName ?? receipt.userId.localpart; final name = member?.displayName ?? receipt.userId.localpart;
return ListTile( return ListTile(
leading: AvatarOrHash(member?.avatarUrl, name, dimension: 40), leading: AvatarOrHash(member?.avatarUrl, name!, dimension: 40),
title: Text(name, overflow: .ellipsis), title: Text(name, overflow: .ellipsis),
subtitle: Text(receipt.userId, overflow: .ellipsis), subtitle: Text(receipt.userId, overflow: .ellipsis),
onTap: () => context.showUserPopover( onTap: () => context.showUserPopover(

View file

@ -104,7 +104,7 @@ class const PowerLevelsDiff(
) )
.value .value
?.displayName ?? ?.displayName ??
change.$1.localpart, change.$1.localpart!,
style: style?.copyWith( style: style?.copyWith(
fontWeight: .bold, fontWeight: .bold,
color: ref.displaynameColorAt( color: ref.displaynameColorAt(

View file

@ -34,7 +34,7 @@ class const MembershipRenderer(
[ [
UserSpan( UserSpan(
context, context,
content.displayName ?? event.stateKey!.localpart, content.displayName ?? event.stateKey!.localpart!,
userId: event.stateKey!, userId: event.stateKey!,
roomId: event.roomId, roomId: event.roomId,
recognizer: targetRecognizer, recognizer: targetRecognizer,

View file

@ -140,7 +140,7 @@ class const MemberList(final String roomId, {super.key})
displayName ?? displayName ??
members[index] members[index]
.stateKey! .stateKey!
.localpart, .localpart!,
overflow: .ellipsis, overflow: .ellipsis,
style: .new( style: .new(
color: ref.displaynameColor( color: ref.displaynameColor(
@ -162,7 +162,7 @@ class const MemberList(final String roomId, {super.key})
displayName ?? displayName ??
members[index] members[index]
.stateKey! .stateKey!
.localpart, .localpart!,
), ),
), ),
), ),

View file

@ -141,7 +141,7 @@ class const RoomSummarySheet(
ListTile( ListTile(
leading: AvatarOrHash( leading: AvatarOrHash(
summary.inviterProfile?.avatarUrl, summary.inviterProfile?.avatarUrl,
summary.inviterProfile?.displayName ?? invitedBy.localpart, summary.inviterProfile?.displayName ?? invitedBy.localpart!,
), ),
title: Text( title: Text(
"${summary.isDirect ? "Direct message from" : "Invited by"} ${summary.inviterProfile?.displayName ?? invitedBy.localpart}", "${summary.isDirect ? "Direct message from" : "Invited by"} ${summary.inviterProfile?.displayName ?? invitedBy.localpart}",

View file

@ -5,6 +5,7 @@ import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
import "package:nexus/controllers/client_state.dart"; import "package:nexus/controllers/client_state.dart";
import "package:nexus/controllers/local_aliases.dart"; import "package:nexus/controllers/local_aliases.dart";
import "package:nexus/helpers/extensions/better_when.dart"; import "package:nexus/helpers/extensions/better_when.dart";
import "package:nexus/helpers/extensions/get_localpart.dart";
import "package:nexus/helpers/hooks/saving.dart"; import "package:nexus/helpers/hooks/saving.dart";
import "package:nexus/main.dart"; import "package:nexus/main.dart";
import "package:nexus/models/gomuks_exception.dart"; import "package:nexus/models/gomuks_exception.dart";
@ -24,7 +25,7 @@ class const LocalAliasesSheet(
final localpart = useValueListenable(controller).text.trim(); final localpart = useValueListenable(controller).text.trim();
final server = ref.watch( final server = ref.watch(
ClientStateController.provider.select( ClientStateController.provider.select(
(state) => state?.userId?.split(":").skip(1).join(":"), (state) => state?.userId?.serverName,
), ),
); );

View file

@ -46,7 +46,7 @@ class const MemberChooser({
.nonNulls, .nonNulls,
); );
String nameOf(String id) => members[id]?.displayName ?? id.localpart; String nameOf(String id) => members[id]?.displayName ?? id.localpart!;
void add(String id) { void add(String id) {
if (excluded.contains(id)) { if (excluded.contains(id)) {

View file

@ -76,7 +76,7 @@ final class const UserBottomSheet(
downloadFilename: member.displayName ?? userId.localpart, downloadFilename: member.displayName ?? userId.localpart,
child: AvatarOrHash( child: AvatarOrHash(
member.avatarUrl, member.avatarUrl,
member.displayName ?? userId.localpart, member.displayName ?? userId.localpart!,
dimension: 200, dimension: 200,
), ),
); );
@ -231,7 +231,7 @@ final class const UserBottomSheet(
if (editable) if (editable)
InlineTextField( InlineTextField(
value: profile?.displayName, value: profile?.displayName,
hint: userId.localpart, hint: userId.localpart!,
style: textTheme.headlineLarge, style: textTheme.headlineLarge,
onChanged: profile == null onChanged: profile == null
? null ? null
@ -240,7 +240,7 @@ final class const UserBottomSheet(
) )
else else
SelectableText( SelectableText(
member.displayName ?? userId.localpart, member.displayName ?? userId.localpart!,
style: textTheme.headlineLarge, style: textTheme.headlineLarge,
textAlign: .center, textAlign: .center,
), ),
@ -404,7 +404,7 @@ final class const UserBottomSheet(
if (hasDm) { if (hasDm) {
context.startDirectMessage( context.startDirectMessage(
userId, userId,
name: name, name: name!,
); );
} else if (await context } else if (await context
.showAdaptiveSheet<bool>( .showAdaptiveSheet<bool>(

View file

@ -47,8 +47,11 @@ class UserSpan(
return UserSpan( return UserSpan(
context, context,
ref.watch(AuthorController.provider(.fromEvent(event))).value?.displayName ?? ref
event.sender.localpart, .watch(AuthorController.provider(.fromEvent(event)))
.value
?.displayName ??
event.sender.localpart!,
userId: event.sender, userId: event.sender,
roomId: event.roomId, roomId: event.roomId,
recognizer: recognizer, recognizer: recognizer,