Merge pull request #1022 from krille-chan/krille/new-chat-access-settings
design: New chat access settingspull/1019/head
commit
5795857b78
@ -0,0 +1,216 @@
|
|||||||
|
import 'package:flutter/material.dart' hide Visibility;
|
||||||
|
|
||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/pages/chat_access_settings/chat_access_settings_page.dart';
|
||||||
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
|
class ChatAccessSettings extends StatefulWidget {
|
||||||
|
final String roomId;
|
||||||
|
const ChatAccessSettings({required this.roomId, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChatAccessSettings> createState() => ChatAccessSettingsController();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
||||||
|
bool joinRulesLoading = false;
|
||||||
|
bool visibilityLoading = false;
|
||||||
|
bool historyVisibilityLoading = false;
|
||||||
|
bool guestAccessLoading = false;
|
||||||
|
Room get room => Matrix.of(context).client.getRoomById(widget.roomId)!;
|
||||||
|
|
||||||
|
void setJoinRule(JoinRules? newJoinRules) async {
|
||||||
|
if (newJoinRules == null) return;
|
||||||
|
setState(() {
|
||||||
|
joinRulesLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await room.setJoinRules(newJoinRules);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().w('Unable to change join rules', e, s);
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
e.toLocalizedString(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
joinRulesLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHistoryVisibility(HistoryVisibility? historyVisibility) async {
|
||||||
|
if (historyVisibility == null) return;
|
||||||
|
setState(() {
|
||||||
|
historyVisibilityLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await room.setHistoryVisibility(historyVisibility);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().w('Unable to change history visibility', e, s);
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
e.toLocalizedString(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
historyVisibilityLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGuestAccess(GuestAccess? guestAccess) async {
|
||||||
|
if (guestAccess == null) return;
|
||||||
|
setState(() {
|
||||||
|
guestAccessLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await room.setGuestAccess(guestAccess);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().w('Unable to change guest access', e, s);
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
e.toLocalizedString(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
guestAccessLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateRoomAction() async {
|
||||||
|
final roomVersion = room
|
||||||
|
.getState(EventTypes.RoomCreate)!
|
||||||
|
.content
|
||||||
|
.tryGet<String>('room_version');
|
||||||
|
final capabilitiesResult = await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => room.client.getCapabilities(),
|
||||||
|
);
|
||||||
|
final capabilities = capabilitiesResult.result;
|
||||||
|
if (capabilities == null) return;
|
||||||
|
final newVersion = await showConfirmationDialog<String>(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context)!.replaceRoomWithNewerVersion,
|
||||||
|
actions: capabilities.mRoomVersions!.available.entries
|
||||||
|
.where((r) => r.key != roomVersion)
|
||||||
|
.map(
|
||||||
|
(version) => AlertDialogAction(
|
||||||
|
key: version.key,
|
||||||
|
label:
|
||||||
|
'${version.key} (${version.value.toString().split('.').last})',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
if (newVersion == null ||
|
||||||
|
OkCancelResult.cancel ==
|
||||||
|
await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
okLabel: L10n.of(context)!.yes,
|
||||||
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
|
title: L10n.of(context)!.areYouSure,
|
||||||
|
message: L10n.of(context)!.roomUpgradeDescription,
|
||||||
|
isDestructiveAction: true,
|
||||||
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => room.client.upgradeRoom(room.id, newVersion),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCanonicalAlias() async {
|
||||||
|
final input = await showTextInputDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context)!.editRoomAliases,
|
||||||
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
|
okLabel: L10n.of(context)!.ok,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
prefixText: '#',
|
||||||
|
suffixText: room.client.userID!.domain!,
|
||||||
|
initialText: room.canonicalAlias.localpart,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final newAliasLocalpart = input?.singleOrNull?.trim();
|
||||||
|
if (newAliasLocalpart == null || newAliasLocalpart.isEmpty) return;
|
||||||
|
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => room.setCanonicalAlias(
|
||||||
|
'#$newAliasLocalpart:${room.client.userID!.domain!}',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChatVisibilityOnDirectory(bool? visibility) async {
|
||||||
|
if (visibility == null) return;
|
||||||
|
setState(() {
|
||||||
|
visibilityLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await room.client.setRoomVisibilityOnDirectory(
|
||||||
|
room.id,
|
||||||
|
visibility: visibility == true ? Visibility.public : Visibility.private,
|
||||||
|
);
|
||||||
|
setState(() {});
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().w('Unable to change visibility', e, s);
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
e.toLocalizedString(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
visibilityLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ChatAccessSettingsPageView(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,172 @@
|
|||||||
|
import 'package:flutter/material.dart' hide Visibility;
|
||||||
|
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/pages/chat_access_settings/chat_access_settings_controller.dart';
|
||||||
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
|
|
||||||
|
class ChatAccessSettingsPageView extends StatelessWidget {
|
||||||
|
final ChatAccessSettingsController controller;
|
||||||
|
const ChatAccessSettingsPageView(this.controller, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final room = controller.room;
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: const Center(child: BackButton()),
|
||||||
|
title: Text(L10n.of(context)!.accessAndVisibility),
|
||||||
|
),
|
||||||
|
body: MaxWidthBody(
|
||||||
|
child: StreamBuilder<Object>(
|
||||||
|
stream: room.onUpdate.stream,
|
||||||
|
builder: (context, snapshot) => Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context)!.visibilityOfTheChatHistory,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
for (final historyVisibility in HistoryVisibility.values)
|
||||||
|
RadioListTile<HistoryVisibility>.adaptive(
|
||||||
|
title: Text(
|
||||||
|
historyVisibility
|
||||||
|
.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||||
|
),
|
||||||
|
value: historyVisibility,
|
||||||
|
groupValue: room.historyVisibility,
|
||||||
|
onChanged: controller.historyVisibilityLoading ||
|
||||||
|
!room.canChangeHistoryVisibility
|
||||||
|
? null
|
||||||
|
: controller.setHistoryVisibility,
|
||||||
|
),
|
||||||
|
Divider(color: Theme.of(context).dividerColor),
|
||||||
|
ListTile(
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context)!.whoIsAllowedToJoinThisGroup,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
for (final joinRule in JoinRules.values)
|
||||||
|
RadioListTile<JoinRules>.adaptive(
|
||||||
|
title: Text(
|
||||||
|
joinRule
|
||||||
|
.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||||
|
),
|
||||||
|
value: joinRule,
|
||||||
|
groupValue: room.joinRules,
|
||||||
|
onChanged:
|
||||||
|
controller.joinRulesLoading || !room.canChangeJoinRules
|
||||||
|
? null
|
||||||
|
: controller.setJoinRule,
|
||||||
|
),
|
||||||
|
Divider(color: Theme.of(context).dividerColor),
|
||||||
|
if ({JoinRules.public, JoinRules.knock}
|
||||||
|
.contains(room.joinRules)) ...[
|
||||||
|
ListTile(
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context)!.areGuestsAllowedToJoin,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
for (final guestAccess in GuestAccess.values)
|
||||||
|
RadioListTile<GuestAccess>.adaptive(
|
||||||
|
title: Text(
|
||||||
|
guestAccess
|
||||||
|
.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||||
|
),
|
||||||
|
value: guestAccess,
|
||||||
|
groupValue: room.guestAccess,
|
||||||
|
onChanged: controller.guestAccessLoading ||
|
||||||
|
!room.canChangeGuestAccess
|
||||||
|
? null
|
||||||
|
: controller.setGuestAccess,
|
||||||
|
),
|
||||||
|
Divider(color: Theme.of(context).dividerColor),
|
||||||
|
FutureBuilder(
|
||||||
|
future: room.client.getRoomVisibilityOnDirectory(room.id),
|
||||||
|
builder: (context, snapshot) => SwitchListTile.adaptive(
|
||||||
|
value: snapshot.data == Visibility.public,
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context)!.chatCanBeDiscoveredViaSearchOnServer(
|
||||||
|
room.client.userID!.domain!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: controller.setChatVisibilityOnDirectory,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context)!.publicLink),
|
||||||
|
subtitle: room.canonicalAlias.isEmpty
|
||||||
|
? Text(
|
||||||
|
L10n.of(context)!.noPublicLinkHasBeenCreatedYet,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
'https://matrix.to/#/${room.canonicalAlias}',
|
||||||
|
style: TextStyle(
|
||||||
|
decoration: TextDecoration.underline,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: room.canChangeStateEvent(EventTypes.RoomCanonicalAlias)
|
||||||
|
? controller.setCanonicalAlias
|
||||||
|
: null,
|
||||||
|
trailing: room.canonicalAlias.isEmpty
|
||||||
|
? const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
|
child: Icon(Icons.add),
|
||||||
|
)
|
||||||
|
: IconButton(
|
||||||
|
icon: Icon(Icons.adaptive.share_outlined),
|
||||||
|
onPressed: () => FluffyShare.share(room.id, context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context)!.globalChatId),
|
||||||
|
subtitle: SelectableText(room.id),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.copy_outlined),
|
||||||
|
onPressed: () => FluffyShare.share(room.id, context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context)!.roomVersion),
|
||||||
|
subtitle: SelectableText(
|
||||||
|
room
|
||||||
|
.getState(EventTypes.RoomCreate)!
|
||||||
|
.content
|
||||||
|
.tryGet<String>('room_version') ??
|
||||||
|
'Unknown',
|
||||||
|
),
|
||||||
|
trailing: room.canSendEvent(EventTypes.RoomTombstone)
|
||||||
|
? IconButton(
|
||||||
|
icon: const Icon(Icons.upgrade_outlined),
|
||||||
|
onPressed: controller.updateRoomAction,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue