You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/widgets/chat_settings_popup_menu.dart

111 lines
3.4 KiB
Dart

5 years ago
import 'dart:async';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
5 years ago
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
5 years ago
import 'package:future_loading_dialog/future_loading_dialog.dart';
5 years ago
import 'matrix.dart';
5 years ago
class ChatSettingsPopupMenu extends StatefulWidget {
5 years ago
final Room room;
final bool displayChatDetails;
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key})
: super(key: key);
5 years ago
@override
_ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState();
}
class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
StreamSubscription notificationChangeSub;
@override
void dispose() {
notificationChangeSub?.cancel();
super.dispose();
}
5 years ago
@override
Widget build(BuildContext context) {
5 years ago
notificationChangeSub ??= Matrix.of(context)
.client
5 years ago
.onAccountData
5 years ago
.stream
5 years ago
.where((u) => u.type == 'm.push_rules')
5 years ago
.listen(
(u) => setState(() => null),
);
final items = <PopupMenuEntry<String>>[
5 years ago
widget.room.pushRuleState == PushRuleState.notify
? PopupMenuItem<String>(
5 years ago
value: 'mute',
5 years ago
child: Text(L10n.of(context).muteChat),
5 years ago
)
: PopupMenuItem<String>(
5 years ago
value: 'unmute',
5 years ago
child: Text(L10n.of(context).unmuteChat),
5 years ago
),
PopupMenuItem<String>(
5 years ago
value: 'leave',
5 years ago
child: Text(L10n.of(context).leave),
5 years ago
),
];
5 years ago
if (widget.displayChatDetails) {
5 years ago
items.insert(
0,
PopupMenuItem<String>(
5 years ago
value: 'details',
5 years ago
child: Text(L10n.of(context).chatDetails),
5 years ago
),
);
5 years ago
}
5 years ago
return PopupMenuButton(
onSelected: (String choice) async {
switch (choice) {
5 years ago
case 'leave':
final confirmed = await showOkCancelAlertDialog(
context: context,
useRootNavigator: false,
title: L10n.of(context).areYouSure,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
);
if (confirmed == OkCancelResult.ok) {
final success = await showFutureLoadingDialog(
context: context, future: () => widget.room.leave());
if (success.error == null) {
await AdaptivePageLayout.of(context)
.pushNamedAndRemoveAllOthers('/');
}
}
5 years ago
break;
5 years ago
case 'mute':
await showFutureLoadingDialog(
context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.mentionsOnly));
5 years ago
break;
5 years ago
case 'unmute':
await showFutureLoadingDialog(
context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.notify));
5 years ago
break;
5 years ago
case 'details':
if (!AdaptivePageLayout.of(context).columnMode(context) ||
AdaptivePageLayout.of(context).viewDataStack.length < 3) {
await AdaptivePageLayout.of(context)
.pushNamed('/rooms/${widget.room.id}/details');
}
5 years ago
break;
}
},
itemBuilder: (BuildContext context) => items,
);
}
}