You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
Dart
72 lines
2.1 KiB
Dart
|
1 year ago
|
part of "pangea_room_extension.dart";
|
||
|
2 years ago
|
|
||
|
1 year ago
|
extension UserPermissionsRoomExtension on Room {
|
||
|
1 year ago
|
// If there are no other admins, and at least one non-admin, return true
|
||
|
|
Future<bool> _isOnlyAdmin() async {
|
||
|
|
if (!isRoomAdmin) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
final List<User> participants = await requestParticipants();
|
||
|
|
|
||
|
|
return ((participants
|
||
|
|
.where(
|
||
|
|
(e) =>
|
||
|
10 months ago
|
e.powerLevel == SpaceConstants.powerLevelOfAdmin &&
|
||
|
1 year ago
|
e.id != BotName.byEnvironment,
|
||
|
|
)
|
||
|
|
.toList()
|
||
|
|
.length) ==
|
||
|
|
1) &&
|
||
|
|
(participants
|
||
|
|
.where(
|
||
|
|
(e) =>
|
||
|
10 months ago
|
e.powerLevel < SpaceConstants.powerLevelOfAdmin &&
|
||
|
1 year ago
|
e.id != BotName.byEnvironment,
|
||
|
|
)
|
||
|
|
.toList())
|
||
|
|
.isNotEmpty;
|
||
|
|
}
|
||
|
|
|
||
|
2 years ago
|
bool _isMadeByUser(String userId) =>
|
||
|
|
getState(EventTypes.RoomCreate)?.senderId == userId;
|
||
|
|
|
||
|
|
//if the user is an admin of the room or any immediate parent of the room
|
||
|
|
//Question: check parents of parents?
|
||
|
|
//check logic
|
||
|
|
bool get _isSpaceAdmin {
|
||
|
|
if (isSpace) return _isRoomAdmin;
|
||
|
|
|
||
|
|
for (final parent in pangeaSpaceParents) {
|
||
|
|
if (parent._isRoomAdmin) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (final parent in pangeaSpaceParents) {
|
||
|
|
for (final parent2 in parent.pangeaSpaceParents) {
|
||
|
|
if (parent2._isRoomAdmin) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool _isUserRoomAdmin(String userId) => getParticipants().any(
|
||
|
|
(e) =>
|
||
|
10 months ago
|
e.id == userId && e.powerLevel == SpaceConstants.powerLevelOfAdmin,
|
||
|
2 years ago
|
);
|
||
|
|
|
||
|
10 months ago
|
bool get _isRoomAdmin => ownPowerLevel == SpaceConstants.powerLevelOfAdmin;
|
||
|
2 years ago
|
|
||
|
1 year ago
|
// Overriding the default canSendEvent to check power levels
|
||
|
2 years ago
|
bool _pangeaCanSendEvent(String eventType) {
|
||
|
|
final powerLevelsMap = getState(EventTypes.RoomPowerLevels)?.content;
|
||
|
|
if (powerLevelsMap == null) return 0 <= ownPowerLevel;
|
||
|
|
final pl = powerLevelsMap
|
||
|
|
.tryGetMap<String, dynamic>('events')
|
||
|
|
?.tryGet<int>(eventType) ??
|
||
|
|
100;
|
||
|
|
return ownPowerLevel >= pl;
|
||
|
|
}
|
||
|
|
}
|