Refactor dialog stuff
This commit is contained in:
parent
185ee37f04
commit
a8383951ba
6 changed files with 83 additions and 90 deletions
27
lib/helpers/extensions/focus_room.dart
Normal file
27
lib/helpers/extensions/focus_room.dart
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
import "package:collection/collection.dart";
|
||||
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/controllers/key_controller.dart";
|
||||
import "package:nexus/controllers/spaces_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";
|
||||
|
||||
|
|
@ -14,7 +12,7 @@ extension JoinRoomWithSnackbars on ClientController {
|
|||
String roomAlias,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
final roomIdOrAlias = roomAlias.mention ?? roomAlias;
|
||||
final roomIdOrAlias = roomAlias.mention;
|
||||
// TODO: Parse vias properly
|
||||
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
|
|
@ -41,33 +39,7 @@ extension JoinRoomWithSnackbars on ClientController {
|
|||
content: Text("Room $roomIdOrAlias successfully joined."),
|
||||
action: SnackBarAction(
|
||||
label: "Open",
|
||||
onPressed: () async {
|
||||
final spaces = ref.watch(SpacesController.provider);
|
||||
final space = spaces.firstWhereOrNull((space) => space.id == id);
|
||||
|
||||
await ref
|
||||
.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 ref
|
||||
.watch(
|
||||
KeyController.provider(KeyController.roomKey).notifier,
|
||||
)
|
||||
.set(id);
|
||||
}
|
||||
},
|
||||
onPressed: () => ref.focusRoom(id),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ extension LinkToMention on String {
|
|||
///
|
||||
/// Returns the decoded identifier (e.g. "#room:matrix.org")
|
||||
/// or null if this is not a Matrix link.
|
||||
String? get mention {
|
||||
String get mention {
|
||||
final trimmed = trim();
|
||||
|
||||
final matrixTo = RegExp(
|
||||
|
|
@ -39,6 +39,6 @@ extension LinkToMention on String {
|
|||
} catch (_) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue