Implement well-known support

This commit is contained in:
Christian Pauly 2020-05-16 08:43:27 +02:00
commit 92ee47ac6d
5 changed files with 42 additions and 6 deletions

View file

@ -395,10 +395,12 @@ class _ChatState extends State<_Chat> {
ChatDetails(room),
),
),
title: Text(room.getLocalizedDisplayname(L10n.of(context)),maxLines: 1),
title: Text(room.getLocalizedDisplayname(L10n.of(context)),
maxLines: 1),
subtitle: typingText.isEmpty
? Text(
room.getLocalizedStatus(context),maxLines: 1,
room.getLocalizedStatus(context),
maxLines: 1,
)
: Row(
children: <Widget>[
@ -407,7 +409,8 @@ class _ChatState extends State<_Chat> {
size: 13),
SizedBox(width: 4),
Text(
typingText,maxLines: 1,
typingText,
maxLines: 1,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontStyle: FontStyle.italic,

View file

@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:math';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/app_route.dart';
@ -70,6 +72,35 @@ class _LoginState extends State<Login> {
AppRoute.defaultRoute(context, ChatListView()), (r) => false);
}
Timer _coolDown;
void _checkWellKnownWithCoolDown(String userId, BuildContext context) async {
_coolDown?.cancel();
_coolDown = Timer(
Duration(seconds: 1),
() => _checkWellKnown(userId, context),
);
}
void _checkWellKnown(String userId, BuildContext context) async {
setState(() => usernameError = null);
if (!userId.isValidMatrixId) return;
try {
final wellKnownInformations = await Matrix.of(context)
.client
.getWellKnownInformationsByUserId(userId);
final newDomain = wellKnownInformations.mHomeserver?.baseUrl;
if ((newDomain?.isNotEmpty ?? false) &&
newDomain != Matrix.of(context).client.homeserver) {
await SimpleDialogs(context).tryRequestWithErrorToast(
Matrix.of(context).client.checkServer(newDomain));
setState(() => usernameError = null);
}
} catch (e) {
setState(() => usernameError = e.toString());
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -98,6 +129,7 @@ class _LoginState extends State<Login> {
readOnly: loading,
autocorrect: false,
autofocus: true,
onChanged: (t) => _checkWellKnownWithCoolDown(t, context),
controller: usernameController,
decoration: InputDecoration(
hintText: