2020-01-02 22:31:39 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-11-14 10:08:13 +01:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2021-01-16 12:46:38 +01:00
|
|
|
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2020-12-25 09:58:34 +01:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'matrix.dart';
|
|
|
|
|
2020-01-02 22:31:39 +01:00
|
|
|
class ChatSettingsPopupMenu extends StatefulWidget {
|
2020-01-01 19:10:13 +01:00
|
|
|
final Room room;
|
|
|
|
final bool displayChatDetails;
|
|
|
|
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key})
|
|
|
|
: super(key: key);
|
|
|
|
|
2020-01-02 22:31:39 +01:00
|
|
|
@override
|
|
|
|
_ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|
|
|
StreamSubscription notificationChangeSub;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
notificationChangeSub?.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-02 22:31:39 +01:00
|
|
|
notificationChangeSub ??= Matrix.of(context)
|
|
|
|
.client
|
2020-06-10 10:07:01 +02:00
|
|
|
.onAccountData
|
2020-01-02 22:31:39 +01:00
|
|
|
.stream
|
2020-06-10 10:07:01 +02:00
|
|
|
.where((u) => u.type == 'm.push_rules')
|
2020-01-02 22:31:39 +01:00
|
|
|
.listen(
|
|
|
|
(u) => setState(() => null),
|
|
|
|
);
|
2020-05-13 15:58:59 +02:00
|
|
|
var items = <PopupMenuEntry<String>>[
|
2020-01-02 22:31:39 +01:00
|
|
|
widget.room.pushRuleState == PushRuleState.notify
|
2020-01-20 13:46:39 +01:00
|
|
|
? PopupMenuItem<String>(
|
2020-05-13 15:58:59 +02:00
|
|
|
value: 'mute',
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).muteChat),
|
2020-01-01 19:10:13 +01:00
|
|
|
)
|
2020-01-20 13:46:39 +01:00
|
|
|
: PopupMenuItem<String>(
|
2020-05-13 15:58:59 +02:00
|
|
|
value: 'unmute',
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).unmuteChat),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem<String>(
|
2020-05-13 15:58:59 +02:00
|
|
|
value: 'leave',
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).leave),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
];
|
2020-01-02 22:31:39 +01:00
|
|
|
if (widget.displayChatDetails) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.insert(
|
|
|
|
0,
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem<String>(
|
2020-05-13 15:58:59 +02:00
|
|
|
value: 'details',
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).chatDetails),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
return PopupMenuButton(
|
|
|
|
onSelected: (String choice) async {
|
|
|
|
switch (choice) {
|
2020-05-13 15:58:59 +02:00
|
|
|
case 'leave':
|
2020-11-14 10:08:13 +01:00
|
|
|
var confirmed = await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context).areYouSure,
|
|
|
|
);
|
|
|
|
if (confirmed == OkCancelResult.ok) {
|
2020-12-25 09:58:34 +01:00
|
|
|
final success = await showFutureLoadingDialog(
|
|
|
|
context: context, future: () => widget.room.leave());
|
|
|
|
if (success.error == null) {
|
2021-01-16 12:46:38 +01:00
|
|
|
await AdaptivePageLayout.of(context)
|
|
|
|
.pushNamedAndRemoveAllOthers('/');
|
2020-02-16 11:36:18 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
2020-05-13 15:58:59 +02:00
|
|
|
case 'mute':
|
2020-12-25 09:58:34 +01:00
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () =>
|
|
|
|
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
2020-05-13 15:58:59 +02:00
|
|
|
case 'unmute':
|
2020-12-25 09:58:34 +01:00
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () =>
|
|
|
|
widget.room.setPushRuleState(PushRuleState.notify));
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
2020-05-13 15:58:59 +02:00
|
|
|
case 'details':
|
2021-01-16 14:24:52 +01:00
|
|
|
if (AdaptivePageLayout.of(context).viewDataStack.length < 3) {
|
|
|
|
await AdaptivePageLayout.of(context)
|
|
|
|
.pushNamed('/rooms/${widget.room.id}/details');
|
|
|
|
}
|
2021-01-16 12:46:38 +01:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemBuilder: (BuildContext context) => items,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|