chore: Follow up join space children
This commit is contained in:
parent
c7b9acfcdf
commit
76b7fbf36f
2 changed files with 25 additions and 35 deletions
|
|
@ -11,10 +11,12 @@ import 'package:matrix/matrix.dart';
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
||||||
|
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/stream_extension.dart';
|
import 'package:fluffychat/utils/stream_extension.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
||||||
|
|
||||||
enum AddRoomType { chat, subspace }
|
enum AddRoomType { chat, subspace }
|
||||||
|
|
||||||
|
|
@ -95,38 +97,23 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
final client = Matrix.of(context).client;
|
final client = Matrix.of(context).client;
|
||||||
final space = client.getRoomById(widget.spaceId);
|
final space = client.getRoomById(widget.spaceId);
|
||||||
|
|
||||||
final consent = await showOkCancelAlertDialog(
|
final joined = await showAdaptiveBottomSheet<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
title: item.name ?? item.canonicalAlias ?? L10n.of(context)!.emptyChat,
|
builder: (_) => PublicRoomBottomSheet(
|
||||||
message: item.topic,
|
outerContext: context,
|
||||||
okLabel: L10n.of(context)!.joinRoom,
|
chunk: item,
|
||||||
cancelLabel: L10n.of(context)!.cancel,
|
via: space?.spaceChildren
|
||||||
|
.firstWhereOrNull(
|
||||||
|
(child) => child.roomId == item.roomId,
|
||||||
|
)
|
||||||
|
?.via,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
if (consent != OkCancelResult.ok) return;
|
if (mounted && joined == true) {
|
||||||
if (!mounted) return;
|
setState(() {
|
||||||
|
_discoveredChildren.remove(item);
|
||||||
await showFutureLoadingDialog(
|
});
|
||||||
context: context,
|
}
|
||||||
future: () async {
|
|
||||||
await client.joinRoom(
|
|
||||||
item.roomId,
|
|
||||||
serverName: space?.spaceChildren
|
|
||||||
.firstWhereOrNull(
|
|
||||||
(child) => child.roomId == item.roomId,
|
|
||||||
)
|
|
||||||
?.via,
|
|
||||||
);
|
|
||||||
if (client.getRoomById(item.roomId) == null) {
|
|
||||||
// Wait for room actually appears in sync
|
|
||||||
await client.waitForRoomInSync(item.roomId, join: true);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (!mounted) return;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_discoveredChildren.remove(item);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSpaceAction(SpaceActions action) async {
|
void _onSpaceAction(SpaceActions action) async {
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ class PublicRoomBottomSheet extends StatelessWidget {
|
||||||
final String? roomAlias;
|
final String? roomAlias;
|
||||||
final BuildContext outerContext;
|
final BuildContext outerContext;
|
||||||
final PublicRoomsChunk? chunk;
|
final PublicRoomsChunk? chunk;
|
||||||
final VoidCallback? onRoomJoined;
|
final List<String>? via;
|
||||||
|
|
||||||
PublicRoomBottomSheet({
|
PublicRoomBottomSheet({
|
||||||
this.roomAlias,
|
this.roomAlias,
|
||||||
required this.outerContext,
|
required this.outerContext,
|
||||||
this.chunk,
|
this.chunk,
|
||||||
this.onRoomJoined,
|
this.via,
|
||||||
super.key,
|
super.key,
|
||||||
}) {
|
}) {
|
||||||
assert(roomAlias != null || chunk != null);
|
assert(roomAlias != null || chunk != null);
|
||||||
|
|
@ -38,8 +38,11 @@ class PublicRoomBottomSheet extends StatelessWidget {
|
||||||
return chunk.roomId;
|
return chunk.roomId;
|
||||||
}
|
}
|
||||||
final roomId = chunk != null && knock
|
final roomId = chunk != null && knock
|
||||||
? await client.knockRoom(chunk.roomId)
|
? await client.knockRoom(chunk.roomId, serverName: via)
|
||||||
: await client.joinRoom(roomAlias ?? chunk!.roomId);
|
: await client.joinRoom(
|
||||||
|
roomAlias ?? chunk!.roomId,
|
||||||
|
serverName: via,
|
||||||
|
);
|
||||||
|
|
||||||
if (!knock && client.getRoomById(roomId) == null) {
|
if (!knock && client.getRoomById(roomId) == null) {
|
||||||
await client.waitForRoomInSync(roomId);
|
await client.waitForRoomInSync(roomId);
|
||||||
|
|
@ -51,7 +54,7 @@ class PublicRoomBottomSheet extends StatelessWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result.error == null) {
|
if (result.error == null) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop<bool>(true);
|
||||||
// don't open the room if the joined room is a space
|
// don't open the room if the joined room is a space
|
||||||
if (chunk?.roomType != 'm.space' &&
|
if (chunk?.roomType != 'm.space' &&
|
||||||
!client.getRoomById(result.result!)!.isSpace) {
|
!client.getRoomById(result.result!)!.isSpace) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue