mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-25 19:00:45 +01:00
fix: Open matrix.to urls
This commit is contained in:
parent
0728a30565
commit
956d766a3f
@ -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) {
|
||||||
|
@ -150,33 +150,16 @@ class UrlLauncher {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (identityParts.primaryIdentifier.sigil == '@') {
|
} else if (identityParts.primaryIdentifier.sigil == '@') {
|
||||||
final user = User(
|
final result = await showFutureLoadingDialog<String>(
|
||||||
|
context: context,
|
||||||
|
future: () => matrix.client.startDirectChat(
|
||||||
identityParts.primaryIdentifier,
|
identityParts.primaryIdentifier,
|
||||||
room: Room(id: '', client: matrix.client),
|
),
|
||||||
);
|
);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user