gate invite behind PL check
This commit is contained in:
parent
f33865962b
commit
a7a21f4d1a
1 changed files with 74 additions and 63 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue