add power level check before inviting bot to space and setting power level
This commit is contained in:
parent
3c1d29d037
commit
b25e10ba76
2 changed files with 21 additions and 1 deletions
|
|
@ -233,6 +233,10 @@ class NewSpaceController extends State<NewSpace> {
|
|||
GoogleAnalytics.createClass(room.name, room.classCode);
|
||||
try {
|
||||
await room.invite(BotName.byEnvironment);
|
||||
await room.setPower(
|
||||
BotName.byEnvironment,
|
||||
ClassDefaultValues.powerLevelOfAdmin,
|
||||
);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to invite pangea bot to space ${room.id}",
|
||||
|
|
|
|||
|
|
@ -218,6 +218,10 @@ class PangeaController {
|
|||
final List<Room> spaces =
|
||||
matrixState.client.rooms.where((room) => room.isSpace).toList();
|
||||
for (final Room space in spaces) {
|
||||
if (space.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin ||
|
||||
!space.canInvite) {
|
||||
continue;
|
||||
}
|
||||
List<User> participants;
|
||||
try {
|
||||
participants = await space.requestParticipants();
|
||||
|
|
@ -228,7 +232,7 @@ class PangeaController {
|
|||
continue;
|
||||
}
|
||||
final List<String> userIds = participants.map((user) => user.id).toList();
|
||||
if (space.canInvite && !userIds.contains(BotName.byEnvironment)) {
|
||||
if (!userIds.contains(BotName.byEnvironment)) {
|
||||
try {
|
||||
await space.invite(BotName.byEnvironment);
|
||||
await space.setPower(
|
||||
|
|
@ -240,6 +244,18 @@ class PangeaController {
|
|||
e: "Failed to invite pangea bot to space ${space.id}",
|
||||
);
|
||||
}
|
||||
} else if (space.getPowerLevelByUserId(BotName.byEnvironment) <
|
||||
ClassDefaultValues.powerLevelOfAdmin) {
|
||||
try {
|
||||
await space.setPower(
|
||||
BotName.byEnvironment,
|
||||
ClassDefaultValues.powerLevelOfAdmin,
|
||||
);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to reset power level for pangea bot in space ${space.id}",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue