Skip to content

Commit

Permalink
feat: Add about server page
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 3, 2024
1 parent cdaaad9 commit 448a111
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 7 deletions.
16 changes: 13 additions & 3 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
"replace": "Replace",
"@replace": {},
"about": "About",
"@about": {
"aboutHomeserver": "About {homeserver}",
"@aboutHomeserver": {
"type": "text",
"placeholders": {}
"placeholders": {
"homeserver": {}
}
},
"accept": "Accept",
"@accept": {
Expand Down Expand Up @@ -2794,5 +2797,12 @@
"blur": "Blur:",
"opacity": "Opacity:",
"setWallpaper": "Set wallpaper",
"manageAccount": "Manage account"
"manageAccount": "Manage account",
"noContactInformationProvided": "Server does not provide any valid contact information",
"contactServerAdmin": "Contact server admin",
"contactServerSecurity": "Contact server security",
"supportPage": "Support page",
"serverInformation": "Server information:",
"name": "Name",
"version": "Version"
}
12 changes: 12 additions & 0 deletions lib/config/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:fluffychat/pages/settings/settings.dart';
import 'package:fluffychat/pages/settings_3pid/settings_3pid.dart';
import 'package:fluffychat/pages/settings_chat/settings_chat.dart';
import 'package:fluffychat/pages/settings_emotes/settings_emotes.dart';
import 'package:fluffychat/pages/settings_homeserver/settings_homeserver.dart';
import 'package:fluffychat/pages/settings_ignore_list/settings_ignore_list.dart';
import 'package:fluffychat/pages/settings_multiple_emotes/settings_multiple_emotes.dart';
import 'package:fluffychat/pages/settings_notifications/settings_notifications.dart';
Expand Down Expand Up @@ -255,6 +256,17 @@ abstract class AppRoutes {
),
],
),
GoRoute(
path: 'homeserver',
pageBuilder: (context, state) {
return defaultPageBuilder(
context,
state,
const SettingsHomeserver(),
);
},
redirect: loggedOutRedirect,
),
GoRoute(
path: 'security',
redirect: loggedOutRedirect,
Expand Down
12 changes: 8 additions & 4 deletions lib/pages/settings/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ class SettingsView extends StatelessWidget {
),
Divider(color: theme.dividerColor),
ListTile(
leading: const Icon(Icons.help_outline_outlined),
title: Text(L10n.of(context).help),
onTap: () => launchUrlString(AppConfig.supportUrl),
leading: const Icon(Icons.dns_outlined),
title: Text(
L10n.of(context).aboutHomeserver(
Matrix.of(context).client.userID?.domain ?? 'homeserver',
),
),
onTap: () => context.go('/rooms/settings/homeserver'),
),
ListTile(
leading: const Icon(Icons.shield_sharp),
leading: const Icon(Icons.privacy_tip_outlined),
title: Text(L10n.of(context).privacy),
onTap: () => launchUrlString(AppConfig.privacyUrl),
),
Expand Down
58 changes: 58 additions & 0 deletions lib/pages/settings_homeserver/settings_homeserver.dart
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);
}
Loading

0 comments on commit 448a111

Please sign in to comment.