-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdaaad9
commit 448a111
Showing
6 changed files
with
391 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
import '../../widgets/matrix.dart'; | ||
import 'settings_homeserver_view.dart'; | ||
|
||
class SettingsHomeserver extends StatefulWidget { | ||
const SettingsHomeserver({super.key}); | ||
|
||
@override | ||
SettingsHomeserverController createState() => SettingsHomeserverController(); | ||
} | ||
|
||
class SettingsHomeserverController extends State<SettingsHomeserver> { | ||
Future<({String name, String version, Uri federationBaseUrl})> | ||
fetchServerInfo() async { | ||
final client = Matrix.of(context).client; | ||
final domain = client.userID!.domain!; | ||
final httpClient = client.httpClient; | ||
var federationBaseUrl = Uri(host: domain, port: 8448, scheme: 'https'); | ||
try { | ||
final serverWellKnownResult = await httpClient.get( | ||
Uri.https(domain, '/.well-known/matrix/server'), | ||
); | ||
final serverWellKnown = jsonDecode(serverWellKnownResult.body); | ||
federationBaseUrl = Uri.https(serverWellKnown['m.server']); | ||
} catch (e, s) { | ||
Logs().w( | ||
'Unable to fetch federation base uri. Use $federationBaseUrl', | ||
e, | ||
s, | ||
); | ||
} | ||
|
||
final serverVersionResult = await http.get( | ||
federationBaseUrl.resolveUri( | ||
Uri(path: '/_matrix/federation/v1/version'), | ||
), | ||
); | ||
final { | ||
'server': { | ||
'name': String name, | ||
'version': String version, | ||
}, | ||
} = Map<String, Map<String, dynamic>>.from( | ||
jsonDecode(serverVersionResult.body), | ||
); | ||
|
||
return (name: name, version: version, federationBaseUrl: federationBaseUrl); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) => SettingsHomeserverView(this); | ||
} |
Oops, something went wrong.