forked from Nexus/nexus
parent
8d4745cc12
commit
79d556a830
5 changed files with 122 additions and 30 deletions
24
lib/controllers/account_management.dart
Normal file
24
lib/controllers/account_management.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
|
import "package:nexus/controllers/client.dart";
|
||||||
|
import "package:nexus/controllers/client_state.dart";
|
||||||
|
import "package:nexus/models/account_management.dart";
|
||||||
|
|
||||||
|
/// Where the homeserver lets the user manage their account, if it says.
|
||||||
|
class AccountManagementController extends AsyncNotifier<AccountManagement?> {
|
||||||
|
@override
|
||||||
|
Future<AccountManagement?> build() async {
|
||||||
|
final homeserver = ref.watch(
|
||||||
|
ClientStateController.provider.select((state) => state?.homeserverUrl),
|
||||||
|
);
|
||||||
|
if (homeserver == null) return null;
|
||||||
|
|
||||||
|
return ref
|
||||||
|
.read(ClientController.provider.notifier)
|
||||||
|
.getAccountManagement(.parse(homeserver));
|
||||||
|
}
|
||||||
|
|
||||||
|
static final provider =
|
||||||
|
AsyncNotifierProvider<AccountManagementController, AccountManagement?>(
|
||||||
|
AccountManagementController.new,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -37,6 +37,7 @@ import "package:nexus/models/requests/get_related_events.dart";
|
||||||
import "package:nexus/models/requests/get_room_state.dart";
|
import "package:nexus/models/requests/get_room_state.dart";
|
||||||
import "package:nexus/models/requests/get_specific_room_state.dart";
|
import "package:nexus/models/requests/get_specific_room_state.dart";
|
||||||
import "package:nexus/models/content/content.dart";
|
import "package:nexus/models/content/content.dart";
|
||||||
|
import "package:nexus/models/account_management.dart";
|
||||||
import "package:nexus/models/requests/get_space_hierarchy.dart";
|
import "package:nexus/models/requests/get_space_hierarchy.dart";
|
||||||
import "package:nexus/models/requests/get_room_directory.dart";
|
import "package:nexus/models/requests/get_room_directory.dart";
|
||||||
import "package:nexus/models/requests/get_threads.dart";
|
import "package:nexus/models/requests/get_threads.dart";
|
||||||
|
|
@ -281,24 +282,19 @@ class ClientController(final String? accountId) extends AsyncNotifier<int> {
|
||||||
Future<void> resetEncryption(RecoveryKey key) =>
|
Future<void> resetEncryption(RecoveryKey key) =>
|
||||||
sendCommand("reset_encryption", key.toJson());
|
sendCommand("reset_encryption", key.toJson());
|
||||||
|
|
||||||
Future<Uri?> getCrossSigningResetUrl(Uri homeserver) async {
|
Future<AccountManagement?> getAccountManagement(Uri homeserver) async =>
|
||||||
const action = "org.matrix.cross_signing_reset";
|
switch ((await sendCommand("get_login_flows", {
|
||||||
final oauth = (await sendCommand("get_login_flows", {
|
|
||||||
"homeserver_url": homeserver.toString(),
|
"homeserver_url": homeserver.toString(),
|
||||||
}))["oauth"];
|
}))["oauth"]) {
|
||||||
|
{"account_management_uri": final String uri} && final oauth => .new(
|
||||||
if (oauth?["account_management_uri"] case final String uri
|
.parse(uri),
|
||||||
when (oauth["account_management_actions_supported"] as List?)?.contains(
|
.new(
|
||||||
action,
|
(oauth["account_management_actions_supported"] as List? ?? [])
|
||||||
) ??
|
.whereType<String>(),
|
||||||
false) {
|
),
|
||||||
final parsed = Uri.parse(uri);
|
),
|
||||||
return parsed.replace(
|
_ => null,
|
||||||
queryParameters: {...parsed.queryParameters, "action": action},
|
};
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> joinRoom(JoinRoomRequest request) async =>
|
Future<String> joinRoom(JoinRoomRequest request) async =>
|
||||||
(await sendCommand("join_room", request.toJson()))["room_id"];
|
(await sendCommand("join_room", request.toJson()))["room_id"];
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import "package:m3e_buttons/m3e_buttons.dart";
|
||||||
import "package:multi_state_switch/multi_state_switch.dart";
|
import "package:multi_state_switch/multi_state_switch.dart";
|
||||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||||
import "package:nexus/controllers/account_data.dart";
|
import "package:nexus/controllers/account_data.dart";
|
||||||
|
import "package:nexus/controllers/account_management.dart";
|
||||||
import "package:nexus/controllers/client.dart";
|
import "package:nexus/controllers/client.dart";
|
||||||
import "package:nexus/controllers/client_state.dart";
|
import "package:nexus/controllers/client_state.dart";
|
||||||
import "package:nexus/controllers/enabled_image_packs.dart";
|
import "package:nexus/controllers/enabled_image_packs.dart";
|
||||||
|
|
@ -24,6 +25,7 @@ import "package:nexus/helpers/extensions/distributor_name.dart";
|
||||||
import "package:nexus/helpers/extensions/get_localpart.dart";
|
import "package:nexus/helpers/extensions/get_localpart.dart";
|
||||||
import "package:nexus/helpers/extensions/room_image_packs.dart";
|
import "package:nexus/helpers/extensions/room_image_packs.dart";
|
||||||
import "package:nexus/helpers/hooks/saving.dart";
|
import "package:nexus/helpers/hooks/saving.dart";
|
||||||
|
import "package:nexus/helpers/launch_helper.dart";
|
||||||
import "package:nexus/models/account_data.dart";
|
import "package:nexus/models/account_data.dart";
|
||||||
import "package:nexus/models/client_state.dart";
|
import "package:nexus/models/client_state.dart";
|
||||||
import "package:nexus/models/image_pack.dart";
|
import "package:nexus/models/image_pack.dart";
|
||||||
|
|
@ -50,6 +52,40 @@ class SettingsSectionsController
|
||||||
@override
|
@override
|
||||||
Future<IMap<String, IList<SettingsCategory>>> build() async {
|
Future<IMap<String, IList<SettingsCategory>>> build() async {
|
||||||
final settings = await ref.watch(SettingsController.provider.future);
|
final settings = await ref.watch(SettingsController.provider.future);
|
||||||
|
// Not awaited, so a slow homeserver doesn't hold up the rest of settings
|
||||||
|
final accountManagement = ref
|
||||||
|
.watch(AccountManagementController.provider)
|
||||||
|
.value;
|
||||||
|
|
||||||
|
// Opens [url], a page of the homeserver's account management
|
||||||
|
Setting link(
|
||||||
|
String title,
|
||||||
|
String description,
|
||||||
|
IconData icon,
|
||||||
|
Uri url, {
|
||||||
|
bool danger = false,
|
||||||
|
}) => .new(
|
||||||
|
title: title,
|
||||||
|
description: description,
|
||||||
|
icon: icon,
|
||||||
|
builder: (title, description, icon) => Builder(
|
||||||
|
builder: (context) {
|
||||||
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
return M3EButton.icon(
|
||||||
|
onPressed: () => ref.read(LaunchHelper.provider).launchUrl(url),
|
||||||
|
label: Text(title),
|
||||||
|
icon: Icon(icon),
|
||||||
|
tooltip: description,
|
||||||
|
decoration: danger
|
||||||
|
? .styleFrom(
|
||||||
|
backgroundColor: colorScheme.error,
|
||||||
|
foregroundColor: colorScheme.onError,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Loads the enabled packs' state, so they can be shown
|
// Loads the enabled packs' state, so they can be shown
|
||||||
ref.watch(EnabledImagePacksController.provider);
|
ref.watch(EnabledImagePacksController.provider);
|
||||||
|
|
@ -793,9 +829,23 @@ class SettingsSectionsController
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
.new(
|
.new(
|
||||||
title: "Other",
|
title: "Account Management",
|
||||||
icon: Icons.key,
|
icon: Icons.manage_accounts,
|
||||||
settings: .new([
|
settings: .new([
|
||||||
|
if (accountManagement case final management?)
|
||||||
|
link(
|
||||||
|
"Manage Account",
|
||||||
|
"Change your password, email, and other account details on your homeserver's website.",
|
||||||
|
Icons.manage_accounts,
|
||||||
|
management.uri,
|
||||||
|
),
|
||||||
|
if (accountManagement?.urlFor(.devicesList) case final url?)
|
||||||
|
link(
|
||||||
|
"Devices",
|
||||||
|
"See and sign out the devices logged in to your account, on your homeserver's website.",
|
||||||
|
Icons.devices,
|
||||||
|
url,
|
||||||
|
),
|
||||||
.new(
|
.new(
|
||||||
title: "Reset Encryption Identity",
|
title: "Reset Encryption Identity",
|
||||||
description: "Replace your encryption identity and recovery key with new ones, if you've lost your recovery key or your encryption is broken.",
|
description: "Replace your encryption identity and recovery key with new ones, if you've lost your recovery key or your encryption is broken.",
|
||||||
|
|
@ -811,6 +861,14 @@ class SettingsSectionsController
|
||||||
),
|
),
|
||||||
icon: Icons.key_off,
|
icon: Icons.key_off,
|
||||||
),
|
),
|
||||||
|
if (accountManagement?.urlFor(.accountDeactivate) case final url?)
|
||||||
|
link(
|
||||||
|
"Deactivate Account",
|
||||||
|
"Permanently deactivate your account, on your homeserver's website. This can't be undone.",
|
||||||
|
Icons.no_accounts,
|
||||||
|
url,
|
||||||
|
danger: true,
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
|
|
||||||
19
lib/models/account_management.dart
Normal file
19
lib/models/account_management.dart
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import "package:collection/collection.dart";
|
||||||
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
|
|
||||||
|
// Later names first, then those from MSC4191, which servers may still use
|
||||||
|
enum AccountManagementAction(final List<String> names) {
|
||||||
|
devicesList(["org.matrix.devices_list", "org.matrix.sessions_list"]),
|
||||||
|
accountDeactivate(["org.matrix.account_deactivate"]),
|
||||||
|
crossSigningReset(["org.matrix.cross_signing_reset"]),
|
||||||
|
}
|
||||||
|
|
||||||
|
class const AccountManagement(final Uri uri, final ISet<String> actions) {
|
||||||
|
Uri? urlFor(AccountManagementAction action) =>
|
||||||
|
switch (action.names.firstWhereOrNull(actions.contains)) {
|
||||||
|
final name? => uri.replace(
|
||||||
|
queryParameters: {...uri.queryParameters, "action": name},
|
||||||
|
),
|
||||||
|
null => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||||
import "package:nexus/controllers/client.dart";
|
import "package:nexus/controllers/client.dart";
|
||||||
import "package:nexus/controllers/client_state.dart";
|
import "package:nexus/controllers/account_management.dart";
|
||||||
import "package:nexus/helpers/launch_helper.dart";
|
import "package:nexus/helpers/launch_helper.dart";
|
||||||
import "package:nexus/models/gomuks_exception.dart";
|
import "package:nexus/models/gomuks_exception.dart";
|
||||||
import "package:nexus/models/recovery_key.dart";
|
import "package:nexus/models/recovery_key.dart";
|
||||||
|
|
@ -41,14 +41,9 @@ class const RecoveryKeySheet(
|
||||||
// Open the approval page straight away the first time.
|
// Open the approval page straight away the first time.
|
||||||
if (!needsApproval.value) {
|
if (!needsApproval.value) {
|
||||||
needsApproval.value = true;
|
needsApproval.value = true;
|
||||||
final homeserver = ref
|
final url = await ref
|
||||||
.read(ClientStateController.provider)
|
.read(AccountManagementController.provider.future)
|
||||||
?.homeserverUrl;
|
.then((management) => management?.urlFor(.crossSigningReset))
|
||||||
final url = homeserver == null
|
|
||||||
? null
|
|
||||||
: await ref
|
|
||||||
.read(ClientController.provider.notifier)
|
|
||||||
.getCrossSigningResetUrl(.parse(homeserver))
|
|
||||||
.onError((_, _) => null);
|
.onError((_, _) => null);
|
||||||
if (!context.mounted || url == null) return;
|
if (!context.mounted || url == null) return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue