Skip to content

Commit 8af20b6

Browse files
authored
Merge pull request #54 from pangeachat/rules-migration
fix for room rules migration
2 parents 60c2708 + b1abad5 commit 8af20b6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/pages/chat_details/chat_details.dart

+6
Original file line numberDiff line numberDiff line change
@@ -425,5 +425,11 @@ class ChatDetailsController extends State<ChatDetails> {
425425
bool showEditNameIcon = false;
426426
void hoverEditNameIcon(bool hovering) =>
427427
setState(() => showEditNameIcon = !showEditNameIcon);
428+
429+
@override
430+
void initState() {
431+
super.initState();
432+
MatrixState.pangeaController.classController.addMissingRoomRules(roomId);
433+
}
428434
// Pangea#
429435
}

lib/pangea/controllers/class_controller.dart

+22
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'dart:developer';
33

44
import 'package:collection/collection.dart';
55
import 'package:fluffychat/pangea/constants/local.key.dart';
6+
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
67
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
78
import 'package:fluffychat/pangea/extensions/client_extension.dart';
89
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
10+
import 'package:fluffychat/pangea/models/class_model.dart';
911
import 'package:fluffychat/pangea/utils/class_code.dart';
1012
import 'package:fluffychat/pangea/utils/error_handler.dart';
1113
import 'package:flutter/foundation.dart';
@@ -156,4 +158,24 @@ class ClassController extends BaseController {
156158
// BE - check class code and if class code is correct, invite student to room
157159
// FE - look for invite from room and automatically accept
158160
}
161+
162+
Future<void> addMissingRoomRules(String? roomId) async {
163+
if (roomId == null) return;
164+
final Room? room = _pangeaController.matrixState.client.getRoomById(roomId);
165+
if (room == null) return;
166+
167+
if (room.classSettings != null && room.pangeaRoomRules == null) {
168+
try {
169+
await _pangeaController.matrixState.client.setRoomStateWithKey(
170+
roomId,
171+
PangeaEventTypes.rules,
172+
'',
173+
PangeaRoomRules().toJson(),
174+
);
175+
} catch (err, stack) {
176+
debugger(when: kDebugMode);
177+
ErrorHandler.logError(e: err, s: stack);
178+
}
179+
}
180+
}
159181
}

0 commit comments

Comments
 (0)