fluffychat/lib/widgets/chat_settings_popup_menu.dart
ggurdin 49e586a7ad
Fluffychat merge (#1685)
chore: Merge upstream changes

---------

Signed-off-by: Krille <c.kussowski@famedly.com>
Co-authored-by: krille-chan <christian-kussowski@posteo.de>
Co-authored-by: Krille <c.kussowski@famedly.com>
Co-authored-by: Linerly <linerly@proton.me>
Co-authored-by: Priit Jõerüüt <hwlate@joeruut.com>
Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org>
Co-authored-by: fadelkon <fadelkon@posteo.net>
Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com>
Co-authored-by: Edgars Andersons <Edgars+Weblate@gaitenis.id.lv>
Co-authored-by: josé m <correoxm@disroot.org>
Co-authored-by: Bezruchenko Simon <worcposj44@gmail.com>
Co-authored-by: Christian <christian-pauly@posteo.de>
Co-authored-by: - <hitekex@yandex.ru>
Co-authored-by: Angelo Schirinzi <Odi-3@users.noreply.hosted.weblate.org>
Co-authored-by: xabirequejo <xabi.rn@gmail.com>
Co-authored-by: Piotr Orzechowski <piotr@orzechowski.tech>
Co-authored-by: Rex_sa <rex.sa@pm.me>
Co-authored-by: Tewuzij <tenajeza@outlook.com>
Co-authored-by: goknarbahceli <goknarbahceli@proton.me>
Co-authored-by: தமிழ்நேரம் <anishprabu.t@gmail.com>
Co-authored-by: Erin <erin@erindesu.cz>
Co-authored-by: EpicKiwi <me@epickiwi.fr>
Co-authored-by: Christian Tietze <me@christiantietze.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-02-03 12:36:46 -05:00

166 lines
5.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'matrix.dart';
enum ChatPopupMenuActions { details, mute, unmute, leave, search }
class ChatSettingsPopupMenu extends StatefulWidget {
final Room room;
final bool displayChatDetails;
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {super.key});
@override
ChatSettingsPopupMenuState createState() => ChatSettingsPopupMenuState();
}
class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
StreamSubscription? notificationChangeSub;
@override
void dispose() {
notificationChangeSub?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
notificationChangeSub ??= Matrix.of(context)
.client
.onSync
.stream
.where(
(syncUpdate) =>
syncUpdate.accountData?.any(
(accountData) => accountData.type == 'm.push_rules',
) ??
false,
)
.listen(
(u) => setState(() {}),
);
return Stack(
alignment: Alignment.center,
children: [
const SizedBox.shrink(),
PopupMenuButton<ChatPopupMenuActions>(
onSelected: (choice) async {
switch (choice) {
case ChatPopupMenuActions.leave:
final confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).areYouSure,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
message: L10n.of(context).archiveRoomDescription,
isDestructive: true,
);
if (confirmed == OkCancelResult.ok) {
final success = await showFutureLoadingDialog(
context: context,
future: () => widget.room.leave(),
);
if (success.error == null) {
context.go('/rooms');
}
}
break;
case ChatPopupMenuActions.mute:
await showFutureLoadingDialog(
context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.mentionsOnly),
);
break;
case ChatPopupMenuActions.unmute:
await showFutureLoadingDialog(
context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.notify),
);
break;
case ChatPopupMenuActions.details:
_showChatDetails();
break;
case ChatPopupMenuActions.search:
context.go('/rooms/${widget.room.id}/search');
break;
}
},
itemBuilder: (BuildContext context) => [
if (widget.displayChatDetails)
PopupMenuItem<ChatPopupMenuActions>(
value: ChatPopupMenuActions.details,
child: Row(
children: [
const Icon(Icons.info_outline_rounded),
const SizedBox(width: 12),
Text(L10n.of(context).chatDetails),
],
),
),
if (widget.room.pushRuleState == PushRuleState.notify)
PopupMenuItem<ChatPopupMenuActions>(
value: ChatPopupMenuActions.mute,
child: Row(
children: [
const Icon(Icons.notifications_off_outlined),
const SizedBox(width: 12),
Text(L10n.of(context).muteChat),
],
),
)
else
PopupMenuItem<ChatPopupMenuActions>(
value: ChatPopupMenuActions.unmute,
child: Row(
children: [
const Icon(Icons.notifications_on_outlined),
const SizedBox(width: 12),
Text(L10n.of(context).unmuteChat),
],
),
),
PopupMenuItem<ChatPopupMenuActions>(
value: ChatPopupMenuActions.search,
child: Row(
children: [
const Icon(Icons.search_outlined),
const SizedBox(width: 12),
Text(L10n.of(context).search),
],
),
),
PopupMenuItem<ChatPopupMenuActions>(
value: ChatPopupMenuActions.leave,
child: Row(
children: [
const Icon(Icons.delete_outlined),
const SizedBox(width: 12),
Text(L10n.of(context).leave),
],
),
),
],
),
],
);
}
void _showChatDetails() {
if (GoRouterState.of(context).uri.path.endsWith('/details')) {
context.go('/rooms/${widget.room.id}');
} else {
context.go('/rooms/${widget.room.id}/details');
}
}
}