forked from Henry-Hiles/nexus
joining rooms from matrix uri or plaintext
This commit is contained in:
parent
cafdf43fd3
commit
82b6f2c647
5 changed files with 99 additions and 68 deletions
|
|
@ -1,9 +1,12 @@
|
|||
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/link_to_mention.dart";
|
||||
import "package:nexus/models/requests/join_room_request.dart";
|
||||
|
||||
extension JoinRoomWithSnackbars on ClientController {
|
||||
Future<void> joinRoomWithSnackBars(
|
||||
|
|
@ -11,77 +14,77 @@ extension JoinRoomWithSnackbars on ClientController {
|
|||
String roomAlias,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
// final parsed = roomAlias.parseIdentifierIntoParts();
|
||||
// final alias = parsed?.primaryIdentifier ?? roomAlias;
|
||||
final roomIdOrAlias = roomAlias.mention ?? roomAlias;
|
||||
|
||||
// final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
|
||||
// final snackbar = scaffoldMessenger.showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Joining room $alias."),
|
||||
// duration: Duration(days: 999),
|
||||
// ),
|
||||
// );
|
||||
final snackbar = scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Joining room $roomIdOrAlias."),
|
||||
duration: Duration(days: 999),
|
||||
),
|
||||
);
|
||||
|
||||
// try {
|
||||
// final id = await joinRoom(alias, via: parsed?.via.toList());
|
||||
try {
|
||||
final id = await joinRoom(
|
||||
JoinRoomRequest(
|
||||
roomIdOrAlias: roomIdOrAlias,
|
||||
via: IList(Uri.tryParse(roomAlias)?.queryParametersAll["via"] ?? []),
|
||||
),
|
||||
);
|
||||
|
||||
// snackbar.close();
|
||||
snackbar.close();
|
||||
|
||||
// scaffoldMessenger.showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text("Room $alias successfully joined."),
|
||||
// action: SnackBarAction(
|
||||
// label: "Open",
|
||||
// onPressed: () async {
|
||||
// final spaces = await ref.refresh(
|
||||
// SpacesController.provider.future,
|
||||
// );
|
||||
// final space = spaces.firstWhereOrNull((space) => space.id == id);
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
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.firstWhereOrNull(
|
||||
// (child) => child.roomData.id == id,
|
||||
// ) !=
|
||||
// null,
|
||||
// )
|
||||
// .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);
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// } 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,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
if (space == null) {
|
||||
await ref
|
||||
.watch(
|
||||
KeyController.provider(KeyController.roomKey).notifier,
|
||||
)
|
||||
.set(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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue