design: New chat access settings
This commit is contained in:
parent
cbdea13772
commit
c300220773
11 changed files with 499 additions and 355 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
|
@ -8,7 +7,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart' as matrix;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_details/chat_details_view.dart';
|
||||
|
|
@ -71,116 +69,6 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||
}
|
||||
}
|
||||
|
||||
void editAliases() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!);
|
||||
|
||||
final aliasesResult = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room!.client.getLocalAliases(room.id),
|
||||
);
|
||||
|
||||
final aliases = aliasesResult.result;
|
||||
|
||||
if (aliases == null) return;
|
||||
final adminMode = room!.canSendEvent(EventTypes.RoomCanonicalAlias);
|
||||
if (aliases.isEmpty && (room.canonicalAlias.isNotEmpty)) {
|
||||
aliases.add(room.canonicalAlias);
|
||||
}
|
||||
if (aliases.isEmpty && adminMode) {
|
||||
return setAliasAction();
|
||||
}
|
||||
final select = await showConfirmationDialog(
|
||||
context: context,
|
||||
title: L10n.of(context)!.editRoomAliases,
|
||||
actions: [
|
||||
if (adminMode)
|
||||
AlertDialogAction(label: L10n.of(context)!.create, key: 'new'),
|
||||
...aliases.map((alias) => AlertDialogAction(key: alias, label: alias)),
|
||||
],
|
||||
);
|
||||
if (select == null) return;
|
||||
if (select == 'new') {
|
||||
return setAliasAction();
|
||||
}
|
||||
final option = await showConfirmationDialog<AliasActions>(
|
||||
context: context,
|
||||
title: select,
|
||||
actions: [
|
||||
AlertDialogAction(
|
||||
label: L10n.of(context)!.copyToClipboard,
|
||||
key: AliasActions.copy,
|
||||
isDefaultAction: true,
|
||||
),
|
||||
if (adminMode) ...{
|
||||
AlertDialogAction(
|
||||
label: L10n.of(context)!.setAsCanonicalAlias,
|
||||
key: AliasActions.setCanonical,
|
||||
isDestructiveAction: true,
|
||||
),
|
||||
AlertDialogAction(
|
||||
label: L10n.of(context)!.delete,
|
||||
key: AliasActions.delete,
|
||||
isDestructiveAction: true,
|
||||
),
|
||||
},
|
||||
],
|
||||
);
|
||||
if (option == null) return;
|
||||
switch (option) {
|
||||
case AliasActions.copy:
|
||||
await Clipboard.setData(ClipboardData(text: select));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.copiedToClipboard)),
|
||||
);
|
||||
break;
|
||||
case AliasActions.delete:
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.client.deleteRoomAlias(select),
|
||||
);
|
||||
break;
|
||||
case AliasActions.setCanonical:
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.client.setRoomStateWithKey(
|
||||
room.id,
|
||||
EventTypes.RoomCanonicalAlias,
|
||||
'',
|
||||
{
|
||||
'alias': select,
|
||||
},
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setAliasAction() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final domain = room.client.userID!.domain;
|
||||
|
||||
final input = await showTextInputDialog(
|
||||
context: context,
|
||||
title: L10n.of(context)!.setInvitationLink,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
textFields: [
|
||||
DialogTextField(
|
||||
prefixText: '#',
|
||||
suffixText: domain,
|
||||
hintText: L10n.of(context)!.alias,
|
||||
initialText: room.canonicalAlias.localpart,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (input == null) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
room.client.setRoomAlias('#${input.single}:${domain!}', room.id),
|
||||
);
|
||||
}
|
||||
|
||||
void setTopicAction() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final input = await showTextInputDialog(
|
||||
|
|
@ -211,91 +99,6 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||
}
|
||||
}
|
||||
|
||||
void setGuestAccess() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final currentGuestAccess = room.guestAccess;
|
||||
final newGuestAccess = await showConfirmationDialog<GuestAccess>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.areGuestsAllowedToJoin,
|
||||
actions: GuestAccess.values
|
||||
.map(
|
||||
(guestAccess) => AlertDialogAction(
|
||||
key: guestAccess,
|
||||
label: guestAccess
|
||||
.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||
isDefaultAction: guestAccess == currentGuestAccess,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
if (newGuestAccess == null || newGuestAccess == currentGuestAccess) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.setGuestAccess(newGuestAccess),
|
||||
);
|
||||
}
|
||||
|
||||
void setHistoryVisibility() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final currentHistoryVisibility = room.historyVisibility;
|
||||
final newHistoryVisibility =
|
||||
await showConfirmationDialog<HistoryVisibility>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.visibilityOfTheChatHistory,
|
||||
actions: HistoryVisibility.values
|
||||
.map(
|
||||
(visibility) => AlertDialogAction(
|
||||
key: visibility,
|
||||
label: visibility
|
||||
.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||
isDefaultAction: visibility == currentHistoryVisibility,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
if (newHistoryVisibility == null ||
|
||||
newHistoryVisibility == currentHistoryVisibility) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.setHistoryVisibility(newHistoryVisibility),
|
||||
);
|
||||
}
|
||||
|
||||
void setJoinRules() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final currentJoinRule = room.joinRules;
|
||||
final newJoinRule = await showConfirmationDialog<JoinRules>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.whoIsAllowedToJoinThisGroup,
|
||||
actions: JoinRules.values
|
||||
.map(
|
||||
(joinRule) => AlertDialogAction(
|
||||
key: joinRule,
|
||||
label:
|
||||
joinRule.getLocalizedString(MatrixLocals(L10n.of(context)!)),
|
||||
isDefaultAction: joinRule == currentJoinRule,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
if (newJoinRule == null || newJoinRule == currentJoinRule) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await room.setJoinRules(newJoinRule);
|
||||
room.client.setRoomVisibilityOnDirectory(
|
||||
roomId!,
|
||||
visibility: {
|
||||
JoinRules.public,
|
||||
JoinRules.knock,
|
||||
}.contains(newJoinRule)
|
||||
? matrix.Visibility.public
|
||||
: matrix.Visibility.private,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void goToEmoteSettings() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
// okay, we need to test if there are any emote state events other than the default one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue