|
|
|
|
@ -1,17 +1,26 @@
|
|
|
|
|
// Package imports:
|
|
|
|
|
// Project imports:
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
|
|
|
|
|
// Project imports:
|
|
|
|
|
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
|
|
|
|
import 'package:fluffychat/pangea/utils/join_all_space_chats.dart';
|
|
|
|
|
Future<void> lockRoom(Room room, Client client) async {
|
|
|
|
|
room.isSpace ? await lockSpace(room, client) : await lockChat(room, client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> unlockChat(Room room, Client client) async {
|
|
|
|
|
Future<void> unlockRoom(Room room, Client client) async {
|
|
|
|
|
room.isSpace
|
|
|
|
|
? await unlockSpace(room, client)
|
|
|
|
|
: await unlockChat(room, client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> lockChat(Room room, Client client) async {
|
|
|
|
|
if (!room.canChangePowerLevel) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final Map<String, dynamic> powerLevelsContent = Map<String, dynamic>.from(
|
|
|
|
|
room.getState(EventTypes.RoomPowerLevels)!.content,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
powerLevelsContent['events_default'] = 0;
|
|
|
|
|
powerLevelsContent['events'][EventTypes.spaceChild] = 0;
|
|
|
|
|
powerLevelsContent['events_default'] = 100;
|
|
|
|
|
powerLevelsContent['events'][EventTypes.spaceChild] = 100;
|
|
|
|
|
|
|
|
|
|
await room.client.setRoomStateWithKey(
|
|
|
|
|
room.id,
|
|
|
|
|
@ -21,12 +30,16 @@ Future<void> unlockChat(Room room, Client client) async {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> lockChat(Room room, Client client) async {
|
|
|
|
|
Future<void> unlockChat(Room room, Client client) async {
|
|
|
|
|
if (!room.canChangePowerLevel) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final Map<String, dynamic> powerLevelsContent = Map<String, dynamic>.from(
|
|
|
|
|
room.getState(EventTypes.RoomPowerLevels)!.content,
|
|
|
|
|
);
|
|
|
|
|
powerLevelsContent['events_default'] = 100;
|
|
|
|
|
powerLevelsContent['events'][EventTypes.spaceChild] = 100;
|
|
|
|
|
|
|
|
|
|
powerLevelsContent['events_default'] = 0;
|
|
|
|
|
powerLevelsContent['events'][EventTypes.spaceChild] = 0;
|
|
|
|
|
|
|
|
|
|
await room.client.setRoomStateWithKey(
|
|
|
|
|
room.id,
|
|
|
|
|
@ -37,30 +50,33 @@ Future<void> lockChat(Room room, Client client) async {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> lockSpace(Room space, Client client) async {
|
|
|
|
|
final List<Room> children = await joinAllSpaceChats(space, client);
|
|
|
|
|
for (final Room child in children) {
|
|
|
|
|
await lockChat(child, client);
|
|
|
|
|
for (final spaceChild in space.spaceChildren) {
|
|
|
|
|
Room? child = client.getRoomById(spaceChild.roomId!);
|
|
|
|
|
if (child == null) {
|
|
|
|
|
try {
|
|
|
|
|
await client.joinRoom(spaceChild.roomId!);
|
|
|
|
|
await client.waitForRoomInSync(spaceChild.roomId!, join: true);
|
|
|
|
|
child = client.getRoomById(spaceChild.roomId!);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
await client.leaveRoom(spaceChild.roomId!);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (child == null) continue;
|
|
|
|
|
child.isSpace
|
|
|
|
|
? await lockSpace(child, client)
|
|
|
|
|
: await lockChat(child, client);
|
|
|
|
|
}
|
|
|
|
|
await lockChat(space, client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> unlockSpace(Room space, Client client) async {
|
|
|
|
|
final List<Room?> children = space.spaceChildren
|
|
|
|
|
.map((child) => client.getRoomById(child.roomId!))
|
|
|
|
|
.toList();
|
|
|
|
|
for (final Room? child in children) {
|
|
|
|
|
if (child != null) {
|
|
|
|
|
await unlockChat(child, client);
|
|
|
|
|
}
|
|
|
|
|
for (final spaceChild in space.spaceChildren) {
|
|
|
|
|
final Room? child = client.getRoomById(spaceChild.roomId!);
|
|
|
|
|
if (child == null) continue;
|
|
|
|
|
child.isSpace
|
|
|
|
|
? await unlockSpace(child, client)
|
|
|
|
|
: await unlockChat(child, client);
|
|
|
|
|
}
|
|
|
|
|
await unlockChat(space, client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> toggleLockRoom(Room? room, Client client) async {
|
|
|
|
|
if (room == null || !room.isRoomAdmin) return;
|
|
|
|
|
if (!room.isSpace) {
|
|
|
|
|
room.locked ? await unlockChat(room, client) : await lockChat(room, client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
room.locked ? await unlockSpace(room, client) : await lockSpace(room, client);
|
|
|
|
|
}
|
|
|
|
|
|