Add failed attempt to fix all room names

This commit is contained in:
Brandon Presley 2023-12-30 15:16:42 +13:00
parent 6ca8f646b2
commit 1aa73bbd7e

View File

@ -28,6 +28,22 @@ class _RoomsPageState extends State<RoomsPage> {
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
}
void fixNames(Client client) async {
final rooms = client.rooms
.where((element) =>
element.getLocalizedDisplayname().contains("Group with"))
.toList();
for (final room in rooms) {
print("Setting power level to 100...");
final result = await room.setPower(client.userID!, 100);
print("Result=$result");
print("Fixing ${room.getLocalizedDisplayname()}...");
await room.setName(
room.getLocalizedDisplayname().replaceAll(RegExp("Group with"), ""));
}
print("Fixed all.");
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -81,12 +97,21 @@ class _RoomsPageState extends State<RoomsPage> {
padding: const EdgeInsets.all(8.0),
child: Center(child: Consumer<ZenithClientProvider>(
builder: (context, provider, child) {
print(provider.client.rooms
.where((element) =>
element.getLocalizedDisplayname().contains("Group with"))
.length);
provider.client.onRoomState.stream.listen((event) {
setState(() {
loadingRooms = false;
});
});
return ElevatedButton(
onPressed: () => fixNames(provider.client),
child: const Text("Fix names"));
if (provider.client.rooms.isEmpty)
return const CircularProgressIndicator();
else