forked from Nexus/nexus
add invite blocking support plus msc4494 support
To accomplish this I also reworked how account data is stored and added a method to fetch capabilities, and another method to set account data
This commit is contained in:
parent
115bec5f05
commit
f97c5548a3
11 changed files with 176 additions and 24 deletions
|
|
@ -1,16 +1,22 @@
|
|||
import "dart:convert";
|
||||
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
|
||||
class AccountDataController extends Notifier<IMap<String, AccountData>> {
|
||||
class AccountDataController extends Notifier<AccountData> {
|
||||
@override
|
||||
IMap<String, AccountData> build() => .new();
|
||||
AccountData build() => .new();
|
||||
|
||||
void update(IMap<String, AccountData> newData) =>
|
||||
state = .new({...state.unlock, ...newData.unlock});
|
||||
void update(IMap<String, IMap<String, dynamic>> newAccountData) =>
|
||||
state = .fromJson({
|
||||
...json.decode(json.encode(state.toJson())),
|
||||
...newAccountData
|
||||
.map((key, value) => MapEntry(key, value["content"]))
|
||||
.unlock,
|
||||
});
|
||||
|
||||
static final provider =
|
||||
NotifierProvider<AccountDataController, IMap<String, AccountData>>(
|
||||
AccountDataController.new,
|
||||
);
|
||||
static final provider = NotifierProvider<AccountDataController, AccountData>(
|
||||
AccountDataController.new,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,10 +33,12 @@ import "package:nexus/models/requests/redact_event.dart";
|
|||
import "package:nexus/models/requests/report.dart";
|
||||
import "package:nexus/models/requests/send_event.dart";
|
||||
import "package:nexus/models/requests/send_message.dart";
|
||||
import "package:nexus/models/requests/set_account_data.dart";
|
||||
import "package:nexus/models/requests/set_membership.dart";
|
||||
import "package:nexus/models/requests/set_state.dart";
|
||||
import "package:nexus/models/requests/upload_media.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:nexus/models/spec_versions_response.dart";
|
||||
import "package:nexus/models/sync_data.dart";
|
||||
import "package:nexus/src/third_party/gomuks.g.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
|
|
@ -268,6 +270,9 @@ class ClientController extends AsyncNotifier<int> {
|
|||
Future<void> setMembership(SetMembershipRequest request) =>
|
||||
_sendCommand("set_membership", request.toJson());
|
||||
|
||||
Future<void> setAccountData(SetAccountDataRequest request) =>
|
||||
_sendCommand("set_account_data", request.toJson());
|
||||
|
||||
Future<MessageContent> uploadMedia(UploadMediaRequest request) async =>
|
||||
.fromJson(await _sendCommand("upload_media", request.toJson()));
|
||||
|
||||
|
|
@ -302,6 +307,9 @@ class ClientController extends AsyncNotifier<int> {
|
|||
Future<void> exchangeToken(OAuthExchangeTokenRequest request) async =>
|
||||
await _sendCommand("oauth_exchange_token", request.toJson());
|
||||
|
||||
Future<SpecVersionsResponse> getSpecVersions() async =>
|
||||
.fromJson(await _sendCommand("get_versions"));
|
||||
|
||||
Future<Uri?> discoverHomeserver(Uri homeserver) async {
|
||||
try {
|
||||
final response = await _sendCommand("discover_homeserver", {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import "package:flutter/material.dart";
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:intl/intl.dart";
|
||||
import "package:m3e_buttons/m3e_buttons.dart";
|
||||
import "package:nexus/controllers/account_data.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/controllers/client_state.dart";
|
||||
import "package:nexus/controllers/settings.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
import "package:nexus/models/settings_category.dart";
|
||||
import "package:nexus/main.dart";
|
||||
import "package:nexus/widgets/settings/dialog_list_tile.dart";
|
||||
|
|
@ -16,6 +18,9 @@ class SettingsSectionsController
|
|||
@override
|
||||
Future<IMap<String, IList<SettingsCategory>>> build() async {
|
||||
final settings = await ref.watch(SettingsController.provider.future);
|
||||
final specVersionsResponse = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.getSpecVersions();
|
||||
|
||||
return .new({
|
||||
"General": .new([
|
||||
|
|
@ -93,6 +98,51 @@ class SettingsSectionsController
|
|||
if (ref.watch(ClientStateController.provider)?.isLoggedIn == true)
|
||||
"Account": .new([
|
||||
.new(title: "Profile", icon: Icons.person, settings: .new([])),
|
||||
.new(
|
||||
title: "Safety",
|
||||
icon: Icons.gpp_good,
|
||||
settings: .new([
|
||||
.new(
|
||||
title: "Invite Blocking",
|
||||
description:
|
||||
"Block invites, either completely, or block only invites from users without shared private rooms (depends on server support).",
|
||||
builder: (title, description, icon) => Consumer(
|
||||
builder: (context, ref, _) =>
|
||||
DialogListTile<DefaultInviteAction>(
|
||||
icon: Icon(icon),
|
||||
title: title,
|
||||
subtitle: Text(description),
|
||||
initialValue: ref
|
||||
.watch(AccountDataController.provider)
|
||||
.invitePermissionConfig
|
||||
.defaultAction,
|
||||
options: specVersionsResponse.unstableFeatures.msc4494
|
||||
? DefaultInviteAction.values
|
||||
: IList(
|
||||
DefaultInviteAction.values,
|
||||
).remove(.denyPublic).toList(),
|
||||
getName: (option) => switch (option) {
|
||||
.allow => "Allow",
|
||||
.deny => "Deny",
|
||||
.denyPublic => "Deny public",
|
||||
},
|
||||
onChanged: (value) => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.setAccountData(
|
||||
.new(
|
||||
type: InvitePermissionConfig.key,
|
||||
content: InvitePermissionConfig(
|
||||
defaultAction: value,
|
||||
),
|
||||
),
|
||||
)
|
||||
.onError(showError),
|
||||
),
|
||||
),
|
||||
icon: Icons.person_off,
|
||||
),
|
||||
]),
|
||||
),
|
||||
.new(
|
||||
title: "Other",
|
||||
icon: Icons.key,
|
||||
|
|
|
|||
|
|
@ -84,9 +84,7 @@ class SpacesController extends Notifier<IList<Space>> {
|
|||
],
|
||||
}.nonNulls.toISet();
|
||||
|
||||
final directMessages = IMap(
|
||||
accountData["m.direct"]?.content ?? {},
|
||||
).values.expand((e) => e).toISet();
|
||||
final directMessages = accountData.directMessages.values.flattened;
|
||||
|
||||
final otherRooms = rooms.entries
|
||||
.where(
|
||||
|
|
|
|||
Loading…
Reference in a new issue