Fix via handling

This commit is contained in:
Henry Hiles 2026-04-06 09:57:03 -04:00
commit 2c23951ea8
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
5 changed files with 101 additions and 99 deletions

View file

@ -1,27 +0,0 @@
import "package:collection/collection.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:nexus/controllers/key_controller.dart";
import "package:nexus/controllers/spaces_controller.dart";
extension FocusRoom on WidgetRef {
Future<void> focusRoom(String id) async {
final spaces = watch(SpacesController.provider);
final space = spaces.firstWhereOrNull((space) => space.id == id);
await watch(KeyController.provider(KeyController.spaceKey).notifier).set(
space?.id ??
spaces
.firstWhere(
(space) =>
space.children.any((child) => child.metadata?.id == id),
)
.id,
);
if (space == null) {
await watch(
KeyController.provider(KeyController.roomKey).notifier,
).set(id);
}
}
}

View file

@ -1,63 +0,0 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:nexus/controllers/client_controller.dart";
import "package:nexus/helpers/extensions/focus_room.dart";
import "package:nexus/helpers/extensions/link_to_mention.dart";
import "package:nexus/models/requests/join_room_request.dart";
extension JoinRoomWithSnackbars on ClientController {
Future<void> joinRoomWithSnackBars(
BuildContext context,
String roomAlias,
WidgetRef ref,
) async {
final roomIdOrAlias = roomAlias.mention ?? roomAlias;
// TODO: Parse vias properly
final scaffoldMessenger = ScaffoldMessenger.of(context);
final snackbar = scaffoldMessenger.showSnackBar(
SnackBar(
content: Text("Joining room $roomIdOrAlias."),
duration: Duration(days: 999),
),
);
try {
final id = await joinRoom(
JoinRoomRequest(
roomIdOrAlias: roomIdOrAlias,
via: IList(Uri.tryParse(roomAlias)?.queryParametersAll["via"] ?? []),
),
);
snackbar.close();
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text("Room $roomIdOrAlias successfully joined."),
action: SnackBarAction(
label: "Open",
onPressed: () => ref.focusRoom(id),
),
),
);
} catch (error) {
snackbar.close();
if (context.mounted) {
scaffoldMessenger.showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).colorScheme.errorContainer,
content: Text(
error.toString(),
style: TextStyle(
color: Theme.of(context).colorScheme.onErrorContainer,
),
),
),
);
}
}
}
}

View file

@ -30,7 +30,8 @@ extension LinkToMention on String {
final identifier = uri.pathSegments.last;
if (identifier.isNotEmpty) {
return "${switch (uri.pathSegments.firstOrNull) {
"r" || "roomid" => "#",
"r" => "#",
"roomid" => "!",
"u" => "@",
_ => "",
}}${Uri.decodeComponent(identifier)}";