Remove canIAddSpaceChild

This commit is contained in:
Kelrap 2024-07-22 10:39:46 -04:00
parent 8cdd9c3b2d
commit 9ed7507353
5 changed files with 14 additions and 36 deletions

View file

@ -131,7 +131,7 @@ extension ChildrenAndParentsRoomExtension on Room {
spaceMode = child?.isSpace ?? spaceMode;
// get the bool for adding chats to spaces
final bool canAddChild = _canIAddSpaceChild(child, spaceMode: spaceMode);
final bool canAddChild = child?.isRoomAdmin ?? true;
if (!spaceMode) return canAddChild;
// if adding space to a space, check if the child is an ancestor

View file

@ -291,12 +291,6 @@ extension PangeaRoom on Room {
bool get canDelete => _canDelete;
/// Determines whether user has permission to add child room to this
/// Can add child if, and only if, is admin of child
bool canIAddSpaceChild(Room? room, {bool spaceMode = false}) {
return _canIAddSpaceChild(room, spaceMode: spaceMode);
}
bool get canIAddSpaceParents => _canIAddSpaceParents;
bool pangeaCanSendEvent(String eventType) => _pangeaCanSendEvent(eventType);

View file

@ -68,19 +68,17 @@ extension AnalyticsRoomExtension on Room {
}
if (spaceChildren.any((sc) => sc.roomId == analyticsRoom.id)) return;
if (canIAddSpaceChild(null)) {
try {
await setSpaceChild(analyticsRoom.id);
} catch (err) {
debugPrint(
"Failed to add analytics room ${analyticsRoom.id} for student to space $id",
);
Sentry.addBreadcrumb(
Breadcrumb(
message: "Failed to add analytics room to space $id",
),
);
}
try {
await setSpaceChild(analyticsRoom.id);
} catch (err) {
debugPrint(
"Failed to add analytics room ${analyticsRoom.id} for student to space $id",
);
Sentry.addBreadcrumb(
Breadcrumb(
message: "Failed to add analytics room to space $id",
),
);
}
}

View file

@ -78,24 +78,10 @@ extension UserPermissionsRoomExtension on Room {
bool get _canDelete => isSpaceAdmin;
bool _canIAddSpaceChild(Room? room, {bool spaceMode = false}) {
if (!isSpace) {
ErrorHandler.logError(
m: "should not call canIAddSpaceChildren on non-space room. Room id: $id",
data: toJson(),
s: StackTrace.current,
);
return false;
}
// Can add child if, and only if, admin of child
return room?.isRoomAdmin ?? true;
}
bool get _canIAddSpaceParents =>
_isRoomAdmin || pangeaCanSendEvent(EventTypes.SpaceParent);
//overriding the default canSendEvent to check power levels
// Overriding the default canSendEvent to check power levels
bool _pangeaCanSendEvent(String eventType) {
final powerLevelsMap = getState(EventTypes.RoomPowerLevels)?.content;
if (powerLevelsMap == null) return 0 <= ownPowerLevel;

View file

@ -79,7 +79,7 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
if (widget.activeSpaceId != null) {
final activeSpace =
Matrix.of(context).client.getRoomById(widget.activeSpaceId!);
if (activeSpace != null && activeSpace.canIAddSpaceChild(null)) {
if (activeSpace != null) {
parent = activeSpace;
} else {
ErrorHandler.logError(