pre-fill new space settings with the settings from the last updated space
This commit is contained in:
parent
294d5a2e66
commit
8fbba108bf
5 changed files with 117 additions and 59 deletions
|
|
@ -1,18 +1,19 @@
|
|||
// Flutter imports:
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_class_and_invite.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart';
|
||||
import 'package:fluffychat/pangea/widgets/space/class_settings.dart';
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'new_space.dart';
|
||||
|
||||
class NewSpaceView extends StatelessWidget {
|
||||
|
|
@ -84,6 +85,8 @@ class NewSpaceView extends StatelessWidget {
|
|||
key: controller.classSettingsKey,
|
||||
roomId: null,
|
||||
startOpen: true,
|
||||
initialSettings:
|
||||
Matrix.of(context).client.lastUpdatedClassSettings,
|
||||
),
|
||||
if (!controller.newClassMode)
|
||||
AddToSpaceToggles(
|
||||
|
|
@ -97,6 +100,7 @@ class NewSpaceView extends StatelessWidget {
|
|||
key: controller.rulesEditorKey,
|
||||
roomId: null,
|
||||
startOpen: false,
|
||||
initialRules: Matrix.of(context).client.lastUpdatedRoomRules,
|
||||
),
|
||||
const SizedBox(height: 45),
|
||||
// SwitchListTile.adaptive(
|
||||
|
|
|
|||
|
|
@ -1,47 +1,55 @@
|
|||
// Dart imports:
|
||||
import 'dart:developer';
|
||||
|
||||
// Flutter imports:
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
// Flutter imports:
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../utils/p_store.dart';
|
||||
|
||||
extension PangeaClient on Client {
|
||||
List<Room> get classes => rooms.where((e) => e.isPangeaClass).toList();
|
||||
|
||||
List<Room> get classesImTeaching => rooms
|
||||
.where((e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin)
|
||||
.where(
|
||||
(e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Room> get classesAndExchangesImTeaching => rooms
|
||||
.where((e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin)
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Room> get classesImIn => rooms
|
||||
.where((e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin)
|
||||
.where(
|
||||
(e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Room> get classesAndExchangesImStudyingIn => rooms
|
||||
.where((e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin)
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Room> get classesAndExchangesImIn =>
|
||||
|
|
@ -104,8 +112,10 @@ extension PangeaClient on Client {
|
|||
debugger(when: kDebugMode);
|
||||
analyticsRoom
|
||||
.join()
|
||||
.onError((error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace))
|
||||
.onError(
|
||||
(error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace),
|
||||
)
|
||||
.then((value) => analyticsRoom.postLoad());
|
||||
return analyticsRoom;
|
||||
}
|
||||
|
|
@ -116,14 +126,14 @@ extension PangeaClient on Client {
|
|||
final String roomID = await createRoom(
|
||||
creationContent: {
|
||||
'type': PangeaRoomTypes.analytics,
|
||||
ModelKey.langCode: langCode
|
||||
ModelKey.langCode: langCode,
|
||||
},
|
||||
name: "$userID $langCode Analytics",
|
||||
topic: "This room stores learning analytics for $userID.",
|
||||
invite: [
|
||||
...(await myTeachers).map((e) => e.id).toList(),
|
||||
...(await myTeachers).map((e) => e.id),
|
||||
// BotName.localBot,
|
||||
BotName.byEnvironment
|
||||
BotName.byEnvironment,
|
||||
],
|
||||
visibility: Visibility.private,
|
||||
roomAliasName: "${userID!.localpart}_${langCode}_analytics",
|
||||
|
|
@ -146,4 +156,21 @@ extension PangeaClient on Client {
|
|||
);
|
||||
return getRoomById(roomId)!;
|
||||
}
|
||||
|
||||
PangeaRoomRules? get lastUpdatedRoomRules => classesAndExchangesImTeaching
|
||||
.where((space) => space.rulesUpdatedAt != null)
|
||||
.sorted(
|
||||
(a, b) => b.rulesUpdatedAt!.compareTo(a.rulesUpdatedAt!),
|
||||
)
|
||||
.firstOrNull
|
||||
?.pangeaRoomRules;
|
||||
|
||||
ClassSettingsModel? get lastUpdatedClassSettings => classesImTeaching
|
||||
.where((space) => space.classSettingsUpdatedAt != null)
|
||||
.sorted(
|
||||
(a, b) =>
|
||||
b.classSettingsUpdatedAt!.compareTo(a.classSettingsUpdatedAt!),
|
||||
)
|
||||
.firstOrNull
|
||||
?.classSettings;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
// Flutter imports:
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix/src/utils/space_child.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
|
|
@ -19,6 +10,14 @@ import 'package:fluffychat/pangea/models/class_model.dart';
|
|||
import 'package:fluffychat/pangea/models/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
// Flutter imports:
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// Package imports:
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix/src/utils/space_child.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
import '../constants/pangea_event_types.dart';
|
||||
import '../enum/construct_type_enum.dart';
|
||||
|
|
@ -82,6 +81,8 @@ extension PangeaRoom on Room {
|
|||
|
||||
String? get creatorId => getState(EventTypes.RoomCreate)?.senderId;
|
||||
|
||||
DateTime? get creationTime => getState(EventTypes.RoomCreate)?.originServerTs;
|
||||
|
||||
ClassSettingsModel? get firstLanguageSettings =>
|
||||
classSettings ??
|
||||
firstParentWithState(PangeaEventTypes.classSettings)?.classSettings;
|
||||
|
|
@ -756,8 +757,7 @@ extension PangeaRoom on Room {
|
|||
}
|
||||
final toAdd = [
|
||||
...getParticipants([Membership.invite, Membership.join])
|
||||
.map((e) => e.id)
|
||||
.toList(),
|
||||
.map((e) => e.id),
|
||||
BotName.byEnvironment,
|
||||
];
|
||||
for (final teacher in await client.myTeachers) {
|
||||
|
|
@ -986,4 +986,14 @@ extension PangeaRoom on Room {
|
|||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
DateTime? get classSettingsUpdatedAt {
|
||||
if (!isSpace) return null;
|
||||
return languageSettingsStateEvent?.originServerTs ?? creationTime;
|
||||
}
|
||||
|
||||
DateTime? get rulesUpdatedAt {
|
||||
if (!isSpace) return null;
|
||||
return pangeaRoomRulesStateEvent?.originServerTs ?? creationTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
// Flutter imports:
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import '../../../../config/app_config.dart';
|
||||
import '../../../../widgets/matrix.dart';
|
||||
import '../../../constants/pangea_event_types.dart';
|
||||
|
|
@ -17,10 +16,15 @@ class RoomRulesEditor extends StatefulWidget {
|
|||
final String? roomId;
|
||||
final bool startOpen;
|
||||
final bool showAdd;
|
||||
final PangeaRoomRules? initialRules;
|
||||
|
||||
const RoomRulesEditor(
|
||||
{Key? key, this.roomId, this.startOpen = true, this.showAdd = false})
|
||||
: super(key: key);
|
||||
const RoomRulesEditor({
|
||||
super.key,
|
||||
this.roomId,
|
||||
this.startOpen = true,
|
||||
this.showAdd = false,
|
||||
this.initialRules,
|
||||
});
|
||||
|
||||
@override
|
||||
RoomRulesState createState() => RoomRulesState();
|
||||
|
|
@ -43,7 +47,7 @@ class RoomRulesState extends State<RoomRulesEditor> {
|
|||
? Matrix.of(context).client.getRoomById(widget.roomId!)
|
||||
: null;
|
||||
|
||||
rules = room?.pangeaRoomRules ?? PangeaRoomRules();
|
||||
rules = room?.pangeaRoomRules ?? widget.initialRules ?? PangeaRoomRules();
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
|
@ -161,14 +165,18 @@ class RoomRulesState extends State<RoomRulesEditor> {
|
|||
onChanged: (value) {
|
||||
updatePermission(() {
|
||||
rules.setLanguageToolSetting(
|
||||
setting, value.toInt());
|
||||
setting,
|
||||
value.toInt(),
|
||||
);
|
||||
});
|
||||
},
|
||||
divisions: 2,
|
||||
max: 2,
|
||||
min: 0,
|
||||
label: rules.languageToolPermissionsText(
|
||||
context, setting),
|
||||
context,
|
||||
setting,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
// Dart imports:
|
||||
import 'dart:developer';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
// Flutter imports:
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import '../../../widgets/matrix.dart';
|
||||
import '../../constants/language_keys.dart';
|
||||
import '../../constants/language_level_type.dart';
|
||||
|
|
@ -28,9 +27,14 @@ import '../user_settings/p_question_container.dart';
|
|||
class ClassSettings extends StatefulWidget {
|
||||
final String? roomId;
|
||||
final bool startOpen;
|
||||
final ClassSettingsModel? initialSettings;
|
||||
|
||||
const ClassSettings({Key? key, this.roomId, this.startOpen = false})
|
||||
: super(key: key);
|
||||
const ClassSettings({
|
||||
super.key,
|
||||
this.roomId,
|
||||
this.startOpen = false,
|
||||
this.initialSettings,
|
||||
});
|
||||
|
||||
@override
|
||||
ClassSettingsState createState() => ClassSettingsState();
|
||||
|
|
@ -54,7 +58,8 @@ class ClassSettingsState extends State<ClassSettings> {
|
|||
? Matrix.of(context).client.getRoomById(widget.roomId!)
|
||||
: null;
|
||||
|
||||
classSettings = room?.classSettings ?? ClassSettingsModel();
|
||||
classSettings =
|
||||
room?.classSettings ?? widget.initialSettings ?? ClassSettingsModel();
|
||||
|
||||
isOpen = widget.startOpen;
|
||||
|
||||
|
|
@ -139,8 +144,8 @@ class ClassSettingsState extends State<ClassSettings> {
|
|||
child: Column(
|
||||
children: [
|
||||
PQuestionContainer(
|
||||
title:
|
||||
L10n.of(context)!.selectClassRoomDominantLanguage),
|
||||
title: L10n.of(context)!.selectClassRoomDominantLanguage,
|
||||
),
|
||||
PLanguageDropdown(
|
||||
onChange: (p0) => updatePermission(() {
|
||||
classSettings.dominantLanguage = p0.langCode;
|
||||
|
|
@ -153,7 +158,8 @@ class ClassSettingsState extends State<ClassSettings> {
|
|||
showMultilingual: true,
|
||||
),
|
||||
PQuestionContainer(
|
||||
title: L10n.of(context)!.selectTargetLanguage),
|
||||
title: L10n.of(context)!.selectTargetLanguage,
|
||||
),
|
||||
PLanguageDropdown(
|
||||
onChange: (p0) => updatePermission(() {
|
||||
classSettings.targetLanguage = p0.langCode;
|
||||
|
|
@ -165,7 +171,8 @@ class ClassSettingsState extends State<ClassSettings> {
|
|||
languages: pangeaController.pLanguageStore.targetOptions,
|
||||
),
|
||||
PQuestionContainer(
|
||||
title: L10n.of(context)!.whatIsYourClassLanguageLevel),
|
||||
title: L10n.of(context)!.whatIsYourClassLanguageLevel,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Container(
|
||||
|
|
@ -210,7 +217,9 @@ class ClassSettingsState extends State<ClassSettings> {
|
|||
value: levelOption,
|
||||
child: Text(
|
||||
LanguageLevelTextPicker.languageLevelText(
|
||||
context, levelOption),
|
||||
context,
|
||||
levelOption,
|
||||
),
|
||||
style: const TextStyle().copyWith(
|
||||
color: Theme.of(context)
|
||||
.textTheme
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue