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(
title: displayName ?? userId.localpart,
title: displayName ?? userId.localpart!,
subtitle: userId,
avatar: avatarUrl,
text: userId,

View file

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

View file

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

View file

@ -1,5 +1,5 @@
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`.
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:nexus/controllers/rooms.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/widgets/avatars/avatar_or_hash.dart";
@ -45,11 +46,9 @@ class const RoomOverlay(
addTag(
id: "[#$name](matrix:roomid/${room.metadata?.id.substring(1)}$vias)",
name:
(room.metadata?.canonicalAlias ?? room.metadata?.id)
?.substring(1)
.split(":")
.first ??
"",
room.metadata?.canonicalAlias?.localpart ??
room.metadata?.id ??
"Unknown Room",
);
},
);

View file

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

View file

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

View file

@ -19,10 +19,10 @@ class const MessageAvatar(
context.showUserPopover(event.sender, roomId: event.roomId),
child: AvatarOrHash(
value.avatarUrl,
value.displayName ?? event.sender.localpart,
value.displayName ?? event.sender.localpart!,
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,
child: switch ([
Text(
value?.displayName ?? event.sender.localpart,
value?.displayName ?? event.sender.localpart!,
style: style ?? .new(color: color, fontWeight: .bold),
maxLines: 1,
overflow: .ellipsis,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -141,7 +141,7 @@ class const RoomSummarySheet(
ListTile(
leading: AvatarOrHash(
summary.inviterProfile?.avatarUrl,
summary.inviterProfile?.displayName ?? invitedBy.localpart,
summary.inviterProfile?.displayName ?? invitedBy.localpart!,
),
title: Text(
"${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/local_aliases.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/main.dart";
import "package:nexus/models/gomuks_exception.dart";
@ -24,7 +25,7 @@ class const LocalAliasesSheet(
final localpart = useValueListenable(controller).text.trim();
final server = ref.watch(
ClientStateController.provider.select(
(state) => state?.userId?.split(":").skip(1).join(":"),
(state) => state?.userId?.serverName,
),
);

View file

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

View file

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

View file

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