bulkUpdateParticipantPermissions function
Updates multiple participants' permission levels in bulk. Only hosts (islevel === "2") can update permissions. Processes in batches (default max 50 at a time).
Example:
await bulkUpdateParticipantPermissions(BulkUpdateParticipantPermissionsOptions(
socket: socket,
participants: [participant1, participant2],
newLevel: "0",
member: "currentUser",
islevel: "2",
roomName: "room123",
showAlert: (alert) => print(alert.message),
maxBatchSize: 50,
));
Implementation
Future<void> bulkUpdateParticipantPermissions(
BulkUpdateParticipantPermissionsOptions options) async {
// Only hosts can update permissions
if (options.islevel != "2") {
options.showAlert?.call(
message: "Only the host can update participant permissions",
type: "danger",
duration: 3000,
);
return;
}
// Filter out hosts and participants already at the target level
final eligibleParticipants = options.participants
.where((p) => p.islevel != "2" && p.islevel != options.newLevel)
.toList();
if (eligibleParticipants.isEmpty) {
options.showAlert?.call(
message: "No participants to update",
type: "info",
duration: 3000,
);
return;
}
// Limit to maxBatchSize
final batch = eligibleParticipants.take(options.maxBatchSize).toList();
final completer = Completer<void>();
options.socket.emitWithAck("bulkUpdateParticipantPermissions", {
'updates': batch
.map((p) => {
'participantId': p.id,
'participantName': p.name,
'newLevel': options.newLevel,
})
.toList(),
'roomName': options.roomName,
}, ack: (response) {
if (response == null || response['success'] != true) {
final reason = response?['reason'] ?? 'Unknown error';
debugPrint('bulkUpdateParticipantPermissions failed: $reason');
options.showAlert?.call(
message: reason,
type: "danger",
duration: 3000,
);
} else if (eligibleParticipants.length > options.maxBatchSize) {
options.showAlert?.call(
message:
"Updated ${batch.length} participants. ${eligibleParticipants.length - options.maxBatchSize} remaining.",
type: "info",
duration: 3000,
);
}
completer.complete();
});
return completer.future;
}