fix: Open matrix.to urls

This commit is contained in:
Christian Pauly 2021-08-24 14:15:35 +02:00
parent 0728a30565
commit 956d766a3f
2 changed files with 11 additions and 55 deletions

View File

@ -1,4 +1,5 @@
import 'package:fluffychat/pages/qr_scanner_modal.dart'; import 'package:fluffychat/pages/qr_scanner_modal.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/fluffy_share.dart'; import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/pages/views/new_private_chat_view.dart'; import 'package:fluffychat/pages/views/new_private_chat_view.dart';
@ -21,40 +22,12 @@ class NewPrivateChatController extends State<NewPrivateChat> {
static const Set<String> supportedSigils = {'@', '!', '#'}; static const Set<String> supportedSigils = {'@', '!', '#'};
static const String prefix = 'https://matrix.to/#/';
void submitAction([_]) async { void submitAction([_]) async {
controller.text = controller.text.trim(); controller.text = controller.text.trim();
if (!formKey.currentState.validate()) return; if (!formKey.currentState.validate()) return;
final client = Matrix.of(context).client; UrlLauncher(context, '$prefix${controller.text}').openMatrixToUrl();
LoadingDialogResult roomIdResult;
switch (controller.text.sigil) {
case '@':
roomIdResult = await showFutureLoadingDialog(
context: context,
future: () => client.startDirectChat(controller.text),
);
break;
case '#':
case '!':
roomIdResult = await showFutureLoadingDialog(
context: context,
future: () async {
final roomId = await client.joinRoom(controller.text);
if (client.getRoomById(roomId) == null) {
await client.onSync.stream
.where((s) => s.rooms.join.containsKey(roomId))
.first;
}
return roomId;
},
);
break;
}
if (roomIdResult.error == null) {
VRouter.of(context).toSegments(['rooms', roomIdResult.result]);
}
} }
String validateForm(String value) { String validateForm(String value) {

View File

@ -150,33 +150,16 @@ class UrlLauncher {
}); });
} }
} else if (identityParts.primaryIdentifier.sigil == '@') { } else if (identityParts.primaryIdentifier.sigil == '@') {
final user = User( final result = await showFutureLoadingDialog<String>(
identityParts.primaryIdentifier, context: context,
room: Room(id: '', client: matrix.client), future: () => matrix.client.startDirectChat(
identityParts.primaryIdentifier,
),
); );
var roomId = matrix.client.getDirectChatFromUserId(user.id); if (result.error == null) {
if (roomId != null) { VRouter.of(context).toSegments(['rooms', result.result]);
VRouter.of(context).toSegments(['rooms', roomId]);
return; return;
} }
if (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: 'Message user ${user.id}',
) ==
OkCancelResult.ok) {
roomId = (await showFutureLoadingDialog(
context: context,
future: () => user.startDirectChat(),
))
.result;
if (roomId != null) {
VRouter.of(context).toSegments(['rooms', roomId]);
}
}
} }
} }
} }