feat: Get jitsi instance from wellknown

This commit is contained in:
Christian Pauly 2021-02-13 09:56:16 +01:00
parent aa5ce5610f
commit bd24387212
5 changed files with 69 additions and 8 deletions

View File

@ -380,8 +380,9 @@ class MatrixState extends State<Matrix> {
wallpaper = file;
}
});
store.getItem(SettingKeys.fontSizeFactor).then((value) => AppConfig
.fontSizeFactor = double.tryParse(value) ?? AppConfig.fontSizeFactor);
store.getItem(SettingKeys.fontSizeFactor).then((value) =>
AppConfig.fontSizeFactor =
double.tryParse(value ?? '') ?? AppConfig.fontSizeFactor);
store
.getItemBool(SettingKeys.renderHtml, AppConfig.renderHtml)
.then((value) => AppConfig.renderHtml = value);

View File

@ -18,6 +18,22 @@
"username": {}
}
},
"badServerVersionsException": "The homeserver supports the Spec versions:\n{serverVersions}\nBut this app supports only {supportedVersions}",
"@badServerVersionsException": {
"type": "text",
"placeholders": {
"serverVersions": {},
"supportedVersions": {}
}
},
"badServerLoginTypesException": "The homeserver supports the login types:\n{serverVersions}\nBut this app supports only:\n{supportedVersions}",
"@badServerLoginTypesException": {
"type": "text",
"placeholders": {
"serverVersions": {},
"supportedVersions": {}
}
},
"account": "Account",
"@account": {
"type": "text",

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -14,7 +16,35 @@ extension LocalizedExceptionExtension on Object {
return (this as MatrixException).errorMessage;
}
}
if (this is MatrixConnectionException) {
if (this is BadServerVersionsException) {
final serverVersions = (this as BadServerVersionsException)
.serverVersions
.toString()
.replaceAll('{', '"')
.replaceAll('}', '"');
final supportedVersions = (this as BadServerVersionsException)
.supportedVersions
.toString()
.replaceAll('{', '"')
.replaceAll('}', '"');
return L10n.of(context)
.badServerVersionsException(serverVersions, supportedVersions);
}
if (this is BadServerLoginTypesException) {
final serverVersions = (this as BadServerLoginTypesException)
.serverLoginTypes
.toString()
.replaceAll('{', '"')
.replaceAll('}', '"');
final supportedVersions = (this as BadServerLoginTypesException)
.supportedLoginTypes
.toString()
.replaceAll('{', '"')
.replaceAll('}', '"');
return L10n.of(context)
.badServerLoginTypesException(serverVersions, supportedVersions);
}
if (this is MatrixConnectionException || this is SocketException) {
L10n.of(context).noConnectionToTheServer;
}
Logs().w('Something went wrong: ', this);

View File

@ -6,6 +6,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/default_app_bar_search_field.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:flutter/foundation.dart';
@ -78,7 +79,23 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
}
setState(() => _isLoading = true);
final wellKnown =
await Matrix.of(context).client.checkHomeserver(homeserver);
var jitsi = wellKnown?.content
?.tryGet<Map<String, dynamic>>('im.vector.riot.jitsi')
?.tryGet<String>('preferredDomain');
if (jitsi != null) {
if (!jitsi.endsWith('/')) {
jitsi += '/';
}
Logs().v('Found custom jitsi instance $jitsi');
await Matrix.of(context)
.store
.setItem(SettingKeys.jitsiInstance, jitsi);
AppConfig.jitsiInstance = jitsi;
}
final loginTypes = await Matrix.of(context).client.requestLoginTypes();
if (loginTypes.flows
.any((flow) => flow.type == AuthenticationTypes.password)) {
@ -92,9 +109,6 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
await launch(
'${Matrix.of(context).client.homeserver?.toString()}/_matrix/client/r0/login/sso/redirect?redirectUrl=$redirectUrl');
}
} on String catch (e) {
// ignore: unawaited_futures
FlushbarHelper.createError(message: e).show(context);
} catch (e) {
// ignore: unawaited_futures
FlushbarHelper.createError(

View File

@ -223,7 +223,7 @@ packages:
description:
path: "."
ref: main
resolved-ref: "9faf07e31ae825147c2b295517f04233e9342e25"
resolved-ref: fc8563849a4706ecef7c37fdd7d4fbb93757ec9b
url: "https://gitlab.com/famedly/famedlysdk.git"
source: git
version: "0.0.1"