From a7a21f4d1a9968a65210c407c6337405d798c65c Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Wed, 2 Dec 2026 16:08:49 -0500 Subject: [PATCH] gate invite behind PL check --- lib/widgets/rooms/room_menu_button.dart | 143 +++++++++++++----------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/lib/widgets/rooms/room_menu_button.dart b/lib/widgets/rooms/room_menu_button.dart index 4bfa840..47d4d42 100644 --- a/lib/widgets/rooms/room_menu_button.dart +++ b/lib/widgets/rooms/room_menu_button.dart @@ -7,6 +7,7 @@ import "package:flutter/services.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:nexus/controllers/account_data.dart"; import "package:nexus/controllers/client.dart"; +import "package:nexus/controllers/power_level.dart"; import "package:nexus/models/room_notification_level.dart"; import "package:nexus/controllers/room_settings_sections.dart"; import "package:nexus/widgets/settings/settings_layout.dart"; @@ -100,75 +101,85 @@ final class const RoomMenuButton( title: Text("Copy Link"), ), ), - PopupMenuItem( - onTap: () => context.showAdaptiveSheet( - (context) => HookBuilder( - builder: (context) { - final userIdController = useTextEditingController(); - final reasonController = useTextEditingController(); - final text = useValueListenable(userIdController).text.trim(); - final valid = text.isValidUserId; - - void submit() { - if (!valid) return; - Navigator.of(context).pop(); - final reason = reasonController.text.trim(); - client - .setMembership( - .new( - userId: text, - roomId: room!.metadata!.id, - action: .invite, - reason: reason.isEmpty ? null : reason, - ), - ) - .onError(showError); - } - - return SheetLayout( - title: Text("Invite User"), - actions: [ - TextButton( - onPressed: Navigator.of(context).pop, - child: Text("Cancel"), - ), - TextButton( - onPressed: valid ? submit : null, - child: Text("Invite"), - ), - ], - children: [ - TextField( - controller: userIdController, - autofocus: true, - keyboardType: .emailAddress, - onSubmitted: (_) => submit(), - decoration: .new( - labelText: "User ID", - hintText: "@user:example.com", - errorText: text.isEmpty || valid - ? null - : "Enter a valid user ID", - ), - ), - TextField( - controller: reasonController, - textCapitalization: .sentences, - onSubmitted: (_) => submit(), - decoration: const .new( - labelText: "Invite reason (optional)", - ), - ), - ], - ); - }, + if (ref.read( + PowerLevelController.provider( + .membershipAction( + action: .invite, + roomId: room!.metadata!.id, + targetUser: "", ), ), - child: ListTile( - leading: Icon(Icons.person_add), - title: Text("Invite"), + )) + PopupMenuItem( + onTap: () => context.showAdaptiveSheet( + (context) => HookBuilder( + builder: (context) { + final userIdController = useTextEditingController(); + final reasonController = useTextEditingController(); + final text = useValueListenable(userIdController).text + .trim(); + final valid = text.isValidUserId; + + void submit() { + if (!valid) return; + Navigator.of(context).pop(); + final reason = reasonController.text.trim(); + client + .setMembership( + .new( + userId: text, + roomId: room!.metadata!.id, + action: .invite, + reason: reason.isEmpty ? null : reason, + ), + ) + .onError(showError); + } + + return SheetLayout( + title: Text("Invite User"), + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text("Cancel"), + ), + TextButton( + onPressed: valid ? submit : null, + child: Text("Invite"), + ), + ], + children: [ + TextField( + controller: userIdController, + autofocus: true, + keyboardType: .emailAddress, + onSubmitted: (_) => submit(), + decoration: .new( + labelText: "User ID", + hintText: "@user:example.com", + errorText: text.isEmpty || valid + ? null + : "Enter a valid user ID", + ), + ), + TextField( + controller: reasonController, + textCapitalization: .sentences, + onSubmitted: (_) => submit(), + decoration: const .new( + labelText: "Invite reason (optional)", + ), + ), + ], + ); + }, + ), + ), + child: ListTile( + leading: Icon(Icons.person_add), + title: Text("Invite"), + ), ), - ), PopupMenuItem( onTap: () => context.showAdaptiveSheet( (_) => RoomProfileSheet(room!.metadata!.id),