fix: use chat view's context when leaving activity via header button

This commit is contained in:
ggurdin 2025-12-04 14:56:49 -05:00
parent 0c99ab3098
commit 836ace6196
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
4 changed files with 37 additions and 34 deletions

View file

@ -2305,6 +2305,36 @@ class ChatController extends State<ChatPageWithRoom>
);
}
}
Future<void> onLeave() async {
final parentSpaceId = room.courseParent?.id;
final confirmed = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).areYouSure,
message: L10n.of(context).leaveRoomDescription,
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
isDestructive: true,
);
if (confirmed != OkCancelResult.ok) return;
final result = await showFutureLoadingDialog(
context: context,
future: widget.room.leave,
);
if (result.isError) return;
final r = Matrix.of(context).client.getRoomById(widget.room.id);
if (r != null && r.membership != Membership.leave) {
await Matrix.of(context).client.waitForRoomInSync(
widget.room.id,
leave: true,
);
}
context.go(
parentSpaceId != null ? '/rooms/spaces/$parentSpaceId' : '/rooms',
);
}
// Pangea#
late final ValueNotifier<bool> _displayChatDetailsColumn;

View file

@ -147,7 +147,10 @@ class ChatView extends StatelessWidget {
if (controller.room.showActivityChatUI) {
return [
ActivityMenuButton(controller: controller),
ActivitySessionPopupMenu(controller.room),
ActivitySessionPopupMenu(
controller.room,
onLeave: controller.onLeave,
),
];
}

View file

@ -6,15 +6,14 @@ import 'package:matrix/matrix.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/pages/chat_details/chat_download_provider.dart';
import 'package:fluffychat/pangea/activity_sessions/activity_room_extension.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
enum ActivityPopupMenuActions { invite, leave, download }
class ActivitySessionPopupMenu extends StatefulWidget {
final Room room;
final VoidCallback onLeave;
const ActivitySessionPopupMenu(this.room, {super.key});
const ActivitySessionPopupMenu(this.room, {required this.onLeave, super.key});
@override
ActivitySessionPopupMenuState createState() =>
@ -30,28 +29,7 @@ class ActivitySessionPopupMenuState extends State<ActivitySessionPopupMenu>
onSelected: (choice) async {
switch (choice) {
case ActivityPopupMenuActions.leave:
final parentSpaceId = widget.room.courseParent?.id;
final router = GoRouter.of(context);
final confirmed = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).areYouSure,
message: L10n.of(context).leaveRoomDescription,
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
isDestructive: true,
);
if (confirmed != OkCancelResult.ok) return;
final result = await showFutureLoadingDialog(
context: context,
future: () => widget.room.leave(),
);
if (result.error == null) {
router.go(
parentSpaceId != null
? '/rooms/spaces/$parentSpaceId'
: '/rooms',
);
}
widget.onLeave();
break;
case ActivityPopupMenuActions.invite:
context.go(

View file

@ -57,14 +57,6 @@ class PutAnalyticsController {
}
void initialize() {
final Room? analyticsRoom = _client.analyticsRoomLocal(
_pangeaController.languageController.userL2!,
);
if (analyticsRoom != null) {
savedActivitiesNotifier.value = analyticsRoom.activityRoomIds;
}
_languageStream ??= _pangeaController.userController.languageStream.stream
.listen(_onUpdateLanguages);
_refreshAnalyticsIfOutdated();