2020-01-02 21:31:39 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-10-06 19:59:36 +00:00
|
|
|
import 'package:furrychat/utils/app_route.dart';
|
|
|
|
import 'package:furrychat/views/chat_details.dart';
|
|
|
|
import 'package:furrychat/views/chat_list.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-04-08 15:43:07 +00:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2020-02-16 10:36:18 +00:00
|
|
|
import 'dialogs/simple_dialogs.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'matrix.dart';
|
|
|
|
|
2020-01-02 21:31:39 +00:00
|
|
|
class ChatSettingsPopupMenu extends StatefulWidget {
|
2020-01-01 18:10:13 +00:00
|
|
|
final Room room;
|
|
|
|
final bool displayChatDetails;
|
|
|
|
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key})
|
|
|
|
: super(key: key);
|
|
|
|
|
2020-01-02 21:31:39 +00:00
|
|
|
@override
|
|
|
|
_ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|
|
|
StreamSubscription notificationChangeSub;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
notificationChangeSub?.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-04-08 15:43:07 +00:00
|
|
|
void startCallAction(BuildContext context) async {
|
|
|
|
final url =
|
|
|
|
'${Matrix.of(context).jitsiInstance}${Uri.encodeComponent(widget.room.id.localpart)}';
|
2020-04-27 11:36:39 +00:00
|
|
|
final success = await SimpleDialogs(context)
|
2020-04-08 15:43:07 +00:00
|
|
|
.tryRequestWithLoadingDialog(widget.room.sendEvent({
|
|
|
|
'msgtype': Matrix.callNamespace,
|
|
|
|
'body': url,
|
|
|
|
}));
|
|
|
|
if (success == false) return;
|
|
|
|
await launch(url);
|
|
|
|
}
|
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-02 21:31:39 +00:00
|
|
|
notificationChangeSub ??= Matrix.of(context)
|
|
|
|
.client
|
2020-06-10 08:07:01 +00:00
|
|
|
.onAccountData
|
2020-01-02 21:31:39 +00:00
|
|
|
.stream
|
2020-06-10 08:07:01 +00:00
|
|
|
.where((u) => u.type == 'm.push_rules')
|
2020-01-02 21:31:39 +00:00
|
|
|
.listen(
|
|
|
|
(u) => setState(() => null),
|
|
|
|
);
|
2020-05-13 13:58:59 +00:00
|
|
|
var items = <PopupMenuEntry<String>>[
|
2020-01-02 21:31:39 +00:00
|
|
|
widget.room.pushRuleState == PushRuleState.notify
|
2020-01-20 12:46:39 +00:00
|
|
|
? PopupMenuItem<String>(
|
2020-05-13 13:58:59 +00:00
|
|
|
value: 'mute',
|
2020-05-07 05:52:40 +00:00
|
|
|
child: Text(L10n.of(context).muteChat),
|
2020-01-01 18:10:13 +00:00
|
|
|
)
|
2020-01-20 12:46:39 +00:00
|
|
|
: PopupMenuItem<String>(
|
2020-05-13 13:58:59 +00:00
|
|
|
value: 'unmute',
|
2020-05-07 05:52:40 +00:00
|
|
|
child: Text(L10n.of(context).unmuteChat),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
2020-04-08 15:43:07 +00:00
|
|
|
PopupMenuItem<String>(
|
2020-05-13 13:58:59 +00:00
|
|
|
value: 'call',
|
2020-05-07 05:52:40 +00:00
|
|
|
child: Text(L10n.of(context).videoCall),
|
2020-04-08 15:43:07 +00:00
|
|
|
),
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem<String>(
|
2020-05-13 13:58:59 +00:00
|
|
|
value: 'leave',
|
2020-05-07 05:52:40 +00:00
|
|
|
child: Text(L10n.of(context).leave),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
];
|
2020-01-02 21:31:39 +00:00
|
|
|
if (widget.displayChatDetails) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.insert(
|
|
|
|
0,
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem<String>(
|
2020-05-13 13:58:59 +00:00
|
|
|
value: 'details',
|
2020-05-07 05:52:40 +00:00
|
|
|
child: Text(L10n.of(context).chatDetails),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
return PopupMenuButton(
|
|
|
|
onSelected: (String choice) async {
|
|
|
|
switch (choice) {
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'leave':
|
|
|
|
var confirmed = await SimpleDialogs(context).askConfirmation();
|
2020-02-16 10:36:18 +00:00
|
|
|
if (confirmed) {
|
2020-04-27 11:36:39 +00:00
|
|
|
final success = await SimpleDialogs(context)
|
2020-02-16 10:36:18 +00:00
|
|
|
.tryRequestWithLoadingDialog(widget.room.leave());
|
|
|
|
if (success != false) {
|
|
|
|
await Navigator.of(context).pushAndRemoveUntil(
|
|
|
|
AppRoute.defaultRoute(context, ChatListView()),
|
|
|
|
(Route r) => false);
|
|
|
|
}
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'mute':
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-01-02 21:31:39 +00:00
|
|
|
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'unmute':
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-01-02 21:31:39 +00:00
|
|
|
widget.room.setPushRuleState(PushRuleState.notify));
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'call':
|
2020-04-08 15:43:07 +00:00
|
|
|
startCallAction(context);
|
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'details':
|
2020-01-02 21:31:39 +00:00
|
|
|
await Navigator.of(context).push(
|
2020-01-01 18:10:13 +00:00
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-01-02 21:31:39 +00:00
|
|
|
ChatDetails(widget.room),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemBuilder: (BuildContext context) => items,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|