merge main
This commit is contained in:
commit
bdeb3d3b8f
84 changed files with 2623 additions and 1995 deletions
|
|
@ -1463,7 +1463,7 @@
|
|||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"pleaseClickOnLink": "Please click on the link in the email and then proceed.",
|
||||
"pleaseClickOnLink": "Please click on the link in the email and then proceed. In rare cases, the email can be sent to spam or take up to 5 minutes to arrive.",
|
||||
"@pleaseClickOnLink": {
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
|
|
@ -2123,7 +2123,7 @@
|
|||
"placeholders": {}
|
||||
},
|
||||
"writeAMessage": "Write a message…",
|
||||
"writeAMessageFlag": "Write a message in {l1flag} or {l2flag}…",
|
||||
"writeAMessageFlag": "Write a message in {l1flag} or {l2flag}",
|
||||
"@writeAMessageFlag": {
|
||||
"type": "text",
|
||||
"placeholders": {
|
||||
|
|
@ -3609,7 +3609,7 @@
|
|||
"zmCountryDisplayName": "Zambia",
|
||||
"zwCountryDisplayName": "Zimbabwe",
|
||||
"pay": "Pay",
|
||||
"allPrivateChats": "All private chats in space (including with Pangea Bot)",
|
||||
"allPrivateChats": "Direct chats",
|
||||
"unknownPrivateChat": "Unknown private chat",
|
||||
"copyClassCodeDesc": "Students who are already in the app can 'Join class or exchange' via the main menu.",
|
||||
"addToClass": "Add exchange to class",
|
||||
|
|
@ -3681,24 +3681,8 @@
|
|||
"lockSpace": "Lock Space",
|
||||
"lockChat": "Lock Chat",
|
||||
"archiveSpace": "Archive Space",
|
||||
"suggestTo": "Suggest to {spaceName}",
|
||||
"@suggestTo": {
|
||||
"placeholders": {
|
||||
"spaceName": {}
|
||||
}
|
||||
},
|
||||
"suggestChatDesc": "Suggested chats will appear in the chat list for {spaceName}",
|
||||
"@suggestToDesc": {
|
||||
"placeholders": {
|
||||
"spaceName": {}
|
||||
}
|
||||
},
|
||||
"suggestExchangeDesc": "Suggested exchanges will appear in the chat list for {spaceName}",
|
||||
"@suggestToExchangeDesc": {
|
||||
"placeholders": {
|
||||
"spaceName": {}
|
||||
}
|
||||
},
|
||||
"suggestToChat": "Suggest this chat",
|
||||
"suggestToChatDesc": "Suggested chats will appear in chat lists",
|
||||
"acceptSelection": "Accept Correction",
|
||||
"acceptSelectionAnyway": "Use this anyway",
|
||||
"makingActivity": "Making activity",
|
||||
|
|
|
|||
|
|
@ -1205,7 +1205,7 @@
|
|||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"pleaseClickOnLink": "Haga clic en el enlace del correo electrónico y luego continúe.",
|
||||
"pleaseClickOnLink": "Haga clic en el enlace del correo electrónico y luego continúe. En casos excepcionales, el correo electrónico puede enviarse a spam o tardar hasta 5 minutos en llegar.",
|
||||
"@pleaseClickOnLink": {
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
|
|
@ -4274,7 +4274,7 @@
|
|||
"zwCountryDisplayName": "Zimbabue",
|
||||
"downloadXLSXFile": "Descargar archivo Excel",
|
||||
"unknownPrivateChat": "Chat Privado Desconocido",
|
||||
"allPrivateChats": "Todos los chats privados (incluso con bots) en clase",
|
||||
"allPrivateChats": "Chats privado",
|
||||
"chatHasBeenAddedToThisSpace": "Se ha añadido el chat a este espacio",
|
||||
"classes": "Clases",
|
||||
"spaceIsPublic": "El espacio es público",
|
||||
|
|
@ -4590,7 +4590,7 @@
|
|||
"autoPlayDesc": "Cuando está activado, el audio de texto a voz de los mensajes se reproducirá automáticamente cuando se seleccione.",
|
||||
"presenceStyle": "Presencia:",
|
||||
"presencesToggle": "Mostrar mensajes de estado de otros usuarios",
|
||||
"writeAMessageFlag": "Escribe un mensaje en {l1flag} o {l2flag}...",
|
||||
"writeAMessageFlag": "Escribe un mensaje en {l1flag} o {l2flag}",
|
||||
"@writeAMessageFlag": {
|
||||
"type": "text",
|
||||
"placeholders": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/pages/archive/archive_view.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
|||
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/enum/use_type.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import 'package:fluffychat/pages/chat/events/message.dart';
|
|||
import 'package:fluffychat/pages/chat/seen_by_row.dart';
|
||||
import 'package:fluffychat/pages/chat/typing_indicators.dart';
|
||||
import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/locked_chat_message.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||
|
|
@ -81,7 +81,7 @@ class ChatEventList extends StatelessWidget {
|
|||
|
||||
// #Pangea
|
||||
if (i == 1) {
|
||||
return (controller.room.locked) && !controller.room.isRoomAdmin
|
||||
return (controller.room.isLocked) && !controller.room.isRoomAdmin
|
||||
? const LockedChatMessage()
|
||||
: const SizedBox.shrink();
|
||||
}
|
||||
|
|
@ -114,13 +114,12 @@ class ChatEventList extends StatelessWidget {
|
|||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
i--;
|
||||
|
||||
// The message at this index:
|
||||
// #Pangea
|
||||
// final event = events[i];
|
||||
final event = events[i - 1];
|
||||
// i--;
|
||||
i = i - 2;
|
||||
// Pangea#
|
||||
|
||||
final event = events[i];
|
||||
final animateIn = animateInEventIndex != null &&
|
||||
controller.timeline!.events.length > animateInEventIndex &&
|
||||
event == controller.timeline!.events[animateInEventIndex];
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import 'package:fluffychat/pages/chat/reply_display.dart';
|
|||
import 'package:fluffychat/pangea/choreographer/widgets/has_error_button.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/language_permissions_warning_buttons.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/start_igc_button.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_analytics/measure_able.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
||||
|
|
@ -43,11 +43,15 @@ class ChatView extends StatelessWidget {
|
|||
tooltip: L10n.of(context)!.edit,
|
||||
onPressed: controller.editSelectedEventAction,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy_outlined),
|
||||
tooltip: L10n.of(context)!.copy,
|
||||
onPressed: controller.copyEventsAction,
|
||||
),
|
||||
// #Pangea
|
||||
if (controller.selectedEvents.length == 1 &&
|
||||
controller.selectedEvents.single.messageType == MessageTypes.Text)
|
||||
// Pangea#
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy_outlined),
|
||||
tooltip: L10n.of(context)!.copy,
|
||||
onPressed: controller.copyEventsAction,
|
||||
),
|
||||
if (controller.canSaveSelectedEvent)
|
||||
// Use builder context to correctly position the share dialog on iPad
|
||||
Builder(
|
||||
|
|
@ -117,8 +121,10 @@ class ChatView extends StatelessWidget {
|
|||
// #Pangea
|
||||
} else {
|
||||
return [
|
||||
ChatSettingsPopupMenu(controller.room,
|
||||
(!controller.room.isDirectChat && !controller.room.isArchived)),
|
||||
ChatSettingsPopupMenu(
|
||||
controller.room,
|
||||
(!controller.room.isDirectChat && !controller.room.isArchived),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,9 +344,6 @@ class MessageContent extends StatelessWidget {
|
|||
MatrixLocals(L10n.of(context)!),
|
||||
hideReply: true,
|
||||
);
|
||||
toolbarController?.toolbar?.textSelection.setMessageText(
|
||||
messageText,
|
||||
);
|
||||
return SelectableLinkify(
|
||||
onSelectionChanged: (selection, cause) {
|
||||
if (cause == SelectionChangedCause.longPress &&
|
||||
|
|
@ -363,8 +360,7 @@ class MessageContent extends StatelessWidget {
|
|||
.onTextSelection(selection);
|
||||
},
|
||||
onTap: () => toolbarController?.showToolbar(context),
|
||||
text: toolbarController?.toolbar?.textSelection.messageText ??
|
||||
messageText,
|
||||
text: messageText,
|
||||
contextMenuBuilder: (context, state) =>
|
||||
(toolbarController?.highlighted ?? false)
|
||||
? const SizedBox.shrink()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
||||
import 'package:fluffychat/pages/chat_details/participant_list_item.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/class_name_header.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_description_button.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_details_toggle_add_students_tile.dart';
|
||||
|
|
@ -585,12 +585,12 @@ class ChatDetailsView extends StatelessWidget {
|
|||
Theme.of(context).scaffoldBackgroundColor,
|
||||
foregroundColor: iconColor,
|
||||
child: Icon(
|
||||
room.locked
|
||||
room.isLocked
|
||||
? Icons.lock_outlined
|
||||
: Icons.no_encryption_outlined,
|
||||
),
|
||||
),
|
||||
value: room.locked,
|
||||
value: room.isLocked,
|
||||
onChanged: (value) => showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => value
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import 'package:fluffychat/config/themes.dart';
|
|||
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/add_to_space.dart';
|
||||
import 'package:fluffychat/pangea/utils/chat_list_handle_space_tap.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/get_chat_list_item_subtitle.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/room_status_extension.dart';
|
||||
|
|
@ -256,7 +256,7 @@ class ChatListItem extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(width: 8),
|
||||
// #Pangea
|
||||
if (room.locked)
|
||||
if (room.isLocked)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 4.0),
|
||||
child: Icon(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'package:fluffychat/config/app_config.dart';
|
|||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/pages/chat_list/navi_rail_item.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/chat_list_handle_space_tap.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/class_code.dart';
|
||||
import 'package:fluffychat/pangea/utils/find_conversation_partner_dialog.dart';
|
||||
import 'package:fluffychat/pangea/utils/logout.dart';
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/pages/chat_list/search_title.dart';
|
|||
import 'package:fluffychat/pages/chat_list/utils/on_chat_tap.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/sync_update_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/archive_space.dart';
|
||||
import 'package:fluffychat/pangea/utils/chat_list_handle_space_tap.dart';
|
||||
|
|
@ -603,7 +603,7 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
subtitle: Row(
|
||||
children: [
|
||||
spaceSubtitle(rootSpace),
|
||||
if (rootSpace.locked)
|
||||
if (rootSpace.isLocked)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 4.0),
|
||||
child: Icon(
|
||||
|
|
|
|||
|
|
@ -191,7 +191,10 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = isLoggingIn = false;
|
||||
// #Pangea
|
||||
// isLoading = isLoggingIn = false;
|
||||
isLoggingIn = false;
|
||||
// Pangea#
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,14 @@ class HomeserverPickerView extends StatelessWidget {
|
|||
// Pangea#
|
||||
Expanded(
|
||||
child: controller.isLoading
|
||||
? const Center(child: CircularProgressIndicator.adaptive())
|
||||
// #Pangea
|
||||
// ? const Center(child: CircularProgressIndicator.adaptive())
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
|
||||
),
|
||||
)
|
||||
// Pangea#
|
||||
: ListView(
|
||||
children: [
|
||||
if (errorText != null) ...[
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'dart:async';
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/pages/invitation_selection/invitation_selection_view.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
|
@ -159,6 +159,8 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
future: () async {
|
||||
if (mode == InvitationSelectionMode.admin) {
|
||||
await inviteTeacherAction(room, id);
|
||||
} else {
|
||||
await room.invite(id);
|
||||
}
|
||||
},
|
||||
// Pangea#
|
||||
|
|
@ -176,22 +178,6 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
Future<void> inviteTeacherAction(Room room, String id) async {
|
||||
await room.invite(id);
|
||||
await room.setPower(id, ClassDefaultValues.powerLevelOfAdmin);
|
||||
if (room.isSpace) {
|
||||
for (final spaceChild in room.spaceChildren) {
|
||||
if (spaceChild.roomId == null) continue;
|
||||
final spaceChildRoom =
|
||||
Matrix.of(context).client.getRoomById(spaceChild.roomId!);
|
||||
if (spaceChildRoom != null &&
|
||||
!(await spaceChildRoom.isBotDM) &&
|
||||
!spaceChildRoom.isDirectChat) {
|
||||
await spaceChildRoom.invite(id);
|
||||
await spaceChildRoom.setPower(
|
||||
id,
|
||||
ClassDefaultValues.powerLevelOfAdmin,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
|||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class InvitationSelectionView extends StatelessWidget {
|
||||
|
|
@ -31,7 +32,14 @@ class InvitationSelectionView extends StatelessWidget {
|
|||
// Pangea#
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const Center(child: BackButton()),
|
||||
// #Pangea
|
||||
// leading: const Center(child: BackButton()),
|
||||
leading: Center(
|
||||
child: BackButton(
|
||||
onPressed: () => context.go("/rooms/${controller.roomId}/details"),
|
||||
),
|
||||
),
|
||||
// Pangea#
|
||||
titleSpacing: 0,
|
||||
title: Text(L10n.of(context)!.inviteContact),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -120,7 +120,9 @@ class LoginController extends State<Login> {
|
|||
return setState(() => loading = false);
|
||||
}
|
||||
|
||||
if (mounted) setState(() => loading = false);
|
||||
// #Pangea
|
||||
// if (mounted) setState(() => loading = false);
|
||||
// Pangea#
|
||||
}
|
||||
|
||||
Timer? _coolDown;
|
||||
|
|
|
|||
|
|
@ -130,9 +130,7 @@ class NewGroupController extends State<NewGroup> {
|
|||
powerLevelContentOverride:
|
||||
await ClassChatPowerLevels.powerLevelOverrideForClassChat(
|
||||
context,
|
||||
addToSpaceKey.currentState!.parents
|
||||
.map((suggestionStatus) => suggestionStatus.room)
|
||||
.toList(),
|
||||
addToSpaceKey.currentState!.parents,
|
||||
),
|
||||
invite: [
|
||||
if (addConversationBotKey.currentState?.addBot ?? false)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class NewGroupView extends StatelessWidget {
|
|||
Expanded(
|
||||
child: TextField(
|
||||
// #Pangea
|
||||
maxLength: 32,
|
||||
maxLength: 64,
|
||||
// Pangea#
|
||||
controller: controller.nameController,
|
||||
autocorrect: false,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import 'package:file_picker/file_picker.dart';
|
|||
import 'package:fluffychat/pages/new_space/new_space_view.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/class_chat_power_levels.dart';
|
||||
|
|
@ -176,9 +176,7 @@ class NewSpaceController extends State<NewSpace> {
|
|||
powerLevelContentOverride: addToSpaceKey.currentState != null
|
||||
? await ClassChatPowerLevels.powerLevelOverrideForClassChat(
|
||||
context,
|
||||
addToSpaceKey.currentState!.parents
|
||||
.map((suggestionStatus) => suggestionStatus.room)
|
||||
.toList(),
|
||||
addToSpaceKey.currentState!.parents,
|
||||
)
|
||||
: null,
|
||||
// initialState: [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.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';
|
||||
|
|
@ -96,7 +96,7 @@ class NewSpaceView extends StatelessWidget {
|
|||
Expanded(
|
||||
child: TextField(
|
||||
// #Pangea
|
||||
maxLength: 32,
|
||||
maxLength: 64,
|
||||
// Pangea#
|
||||
controller: controller.nameController,
|
||||
autocorrect: false,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
|||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/enum/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/models/it_step.dart';
|
||||
import 'package:fluffychat/pangea/models/representation_content_model.dart';
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import '../../../widgets/matrix.dart';
|
||||
import '../../models/language_detection_model.dart';
|
||||
import '../../models/span_card_model.dart';
|
||||
import '../../repo/span_data_repo.dart';
|
||||
|
|
@ -237,7 +236,8 @@ class IgcController {
|
|||
|
||||
clear() {
|
||||
igcTextData = null;
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
// Not sure why this is here
|
||||
// MatrixState.pAnyState.closeOverlay();
|
||||
}
|
||||
|
||||
bool get canSendMessage {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class ITController {
|
|||
String? sourceText;
|
||||
List<ITStep> completedITSteps = [];
|
||||
CurrentITStep? currentITStep;
|
||||
CurrentITStep? nextITStep;
|
||||
GoldRouteTracker goldRouteTracker = GoldRouteTracker.defaultTracker;
|
||||
List<int> payLoadIds = [];
|
||||
|
||||
|
|
@ -42,6 +43,7 @@ class ITController {
|
|||
sourceText = null;
|
||||
completedITSteps = [];
|
||||
currentITStep = null;
|
||||
nextITStep = null;
|
||||
goldRouteTracker = GoldRouteTracker.defaultTracker;
|
||||
payLoadIds = [];
|
||||
|
||||
|
|
@ -130,36 +132,75 @@ class ITController {
|
|||
);
|
||||
}
|
||||
|
||||
currentITStep = null;
|
||||
if (nextITStep == null) {
|
||||
currentITStep = null;
|
||||
|
||||
final ITResponseModel res = await _customInputTranslation(currentText);
|
||||
// final ITResponseModel res = await (useCustomInput ||
|
||||
// currentText.isEmpty ||
|
||||
// translationId == null ||
|
||||
// completedITSteps.last.chosenContinuance?.indexSavedByServer ==
|
||||
// null
|
||||
// ? _customInputTranslation(currentText)
|
||||
// : _systemChoiceTranslation(translationId));
|
||||
final ITResponseModel res = await _customInputTranslation(currentText);
|
||||
// final ITResponseModel res = await (useCustomInput ||
|
||||
// currentText.isEmpty ||
|
||||
// translationId == null ||
|
||||
// completedITSteps.last.chosenContinuance?.indexSavedByServer ==
|
||||
// null
|
||||
// ? _customInputTranslation(currentText)
|
||||
// : _systemChoiceTranslation(translationId));
|
||||
|
||||
if (res.goldContinuances != null && res.goldContinuances!.isNotEmpty) {
|
||||
goldRouteTracker = GoldRouteTracker(
|
||||
res.goldContinuances!,
|
||||
sourceText!,
|
||||
if (res.goldContinuances != null && res.goldContinuances!.isNotEmpty) {
|
||||
goldRouteTracker = GoldRouteTracker(
|
||||
res.goldContinuances!,
|
||||
sourceText!,
|
||||
);
|
||||
}
|
||||
|
||||
currentITStep = CurrentITStep(
|
||||
sourceText: sourceText!,
|
||||
currentText: currentText,
|
||||
responseModel: res,
|
||||
storedGoldContinuances: goldRouteTracker.continuances,
|
||||
);
|
||||
|
||||
_addPayloadId(res);
|
||||
} else {
|
||||
currentITStep = nextITStep;
|
||||
nextITStep = null;
|
||||
}
|
||||
|
||||
currentITStep = CurrentITStep(
|
||||
sourceText: sourceText!,
|
||||
currentText: currentText,
|
||||
responseModel: res,
|
||||
storedGoldContinuances: goldRouteTracker.continuances,
|
||||
);
|
||||
|
||||
_addPayloadId(res);
|
||||
|
||||
if (isTranslationDone) {
|
||||
choreographer.altTranslator.setTranslationFeedback();
|
||||
choreographer.getLanguageHelp(true);
|
||||
} else {
|
||||
getNextTranslationData();
|
||||
}
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
if (e is! http.Response) {
|
||||
ErrorHandler.logError(e: e, s: s);
|
||||
}
|
||||
choreographer.errorService.setErrorAndLock(
|
||||
ChoreoError(type: ChoreoErrorType.unknown, raw: e),
|
||||
);
|
||||
} finally {
|
||||
choreographer.stopLoading();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void>getNextTranslationData() async {
|
||||
try {
|
||||
if (completedITSteps.length < goldRouteTracker.continuances.length) {
|
||||
final String currentText = choreographer.currentText;
|
||||
final String nextText =
|
||||
goldRouteTracker.continuances[completedITSteps.length].text;
|
||||
|
||||
final ITResponseModel res =
|
||||
await _customInputTranslation(currentText + nextText);
|
||||
|
||||
nextITStep = CurrentITStep(
|
||||
sourceText: sourceText!,
|
||||
currentText: nextText,
|
||||
responseModel: res,
|
||||
storedGoldContinuances: goldRouteTracker.continuances,
|
||||
);
|
||||
} else {
|
||||
nextITStep = null;
|
||||
}
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import 'dart:developer';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../utils/bot_style.dart';
|
||||
import 'it_shimmer.dart';
|
||||
|
|
@ -56,10 +58,12 @@ class Choice {
|
|||
Choice({
|
||||
this.color,
|
||||
required this.text,
|
||||
this.isGold = false,
|
||||
});
|
||||
|
||||
final Color? color;
|
||||
final String text;
|
||||
final bool isGold;
|
||||
}
|
||||
|
||||
class ChoiceItem extends StatelessWidget {
|
||||
|
|
@ -86,45 +90,50 @@ class ChoiceItem extends StatelessWidget {
|
|||
waitDuration: onLongPress != null
|
||||
? const Duration(milliseconds: 500)
|
||||
: const Duration(days: 1),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(2),
|
||||
padding: EdgeInsets.zero,
|
||||
decoration: isSelected
|
||||
? BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
border: Border.all(
|
||||
color: entry.value.color ?? theme.colorScheme.primary,
|
||||
style: BorderStyle.solid,
|
||||
width: 2.0,
|
||||
child: ChoiceAnimationWidget(
|
||||
key: ValueKey(entry.value.text),
|
||||
selected: entry.value.color != null,
|
||||
isGold: entry.value.isGold,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(2),
|
||||
padding: EdgeInsets.zero,
|
||||
decoration: isSelected
|
||||
? BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
border: Border.all(
|
||||
color: entry.value.color ?? theme.colorScheme.primary,
|
||||
style: BorderStyle.solid,
|
||||
width: 2.0,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
child: TextButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(
|
||||
const EdgeInsets.symmetric(horizontal: 7),
|
||||
),
|
||||
//if index is selected, then give the background a slight primary color
|
||||
backgroundColor: MaterialStateProperty.all<Color>(
|
||||
entry.value.color != null
|
||||
? entry.value.color!.withOpacity(0.2)
|
||||
: theme.colorScheme.primary.withOpacity(0.1),
|
||||
),
|
||||
textStyle: MaterialStateProperty.all(
|
||||
BotStyle.text(context),
|
||||
),
|
||||
shape: MaterialStateProperty.all(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
child: TextButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(
|
||||
const EdgeInsets.symmetric(horizontal: 7),
|
||||
),
|
||||
//if index is selected, then give the background a slight primary color
|
||||
backgroundColor: MaterialStateProperty.all<Color>(
|
||||
entry.value.color != null
|
||||
? entry.value.color!.withOpacity(0.2)
|
||||
: theme.colorScheme.primary.withOpacity(0.1),
|
||||
),
|
||||
textStyle: MaterialStateProperty.all(
|
||||
BotStyle.text(context),
|
||||
),
|
||||
shape: MaterialStateProperty.all(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
),
|
||||
onLongPress:
|
||||
onLongPress != null ? () => onLongPress!(entry.key) : null,
|
||||
onPressed: () => onPressed(entry.key),
|
||||
child: Text(
|
||||
entry.value.text,
|
||||
style: BotStyle.text(context),
|
||||
onLongPress:
|
||||
onLongPress != null ? () => onLongPress!(entry.key) : null,
|
||||
onPressed: () => onPressed(entry.key),
|
||||
child: Text(
|
||||
entry.value.text,
|
||||
style: BotStyle.text(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -135,3 +144,110 @@ class ChoiceItem extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChoiceAnimationWidget extends StatefulWidget {
|
||||
final Widget child;
|
||||
final bool selected;
|
||||
final bool isGold;
|
||||
|
||||
const ChoiceAnimationWidget({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.selected,
|
||||
this.isGold = false,
|
||||
});
|
||||
|
||||
@override
|
||||
ChoiceAnimationWidgetState createState() => ChoiceAnimationWidgetState();
|
||||
}
|
||||
|
||||
class ChoiceAnimationWidgetState extends State<ChoiceAnimationWidget>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
late final Animation<double> _animation;
|
||||
bool animationPlayed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_animation = widget.isGold
|
||||
? Tween<double>(begin: 1.0, end: 1.2).animate(_controller)
|
||||
: TweenSequence<double>([
|
||||
TweenSequenceItem<double>(
|
||||
tween: Tween<double>(begin: 0, end: -8 * pi / 180),
|
||||
weight: 1.0,
|
||||
),
|
||||
TweenSequenceItem<double>(
|
||||
tween: Tween<double>(begin: -8 * pi / 180, end: 16 * pi / 180),
|
||||
weight: 2.0,
|
||||
),
|
||||
TweenSequenceItem<double>(
|
||||
tween: Tween<double>(begin: 16 * pi / 180, end: 0),
|
||||
weight: 1.0,
|
||||
),
|
||||
]).animate(_controller);
|
||||
|
||||
if (widget.selected && !animationPlayed) {
|
||||
_controller.forward();
|
||||
animationPlayed = true;
|
||||
setState(() {});
|
||||
}
|
||||
_controller.addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
_controller.reverse();
|
||||
} else if (status == AnimationStatus.dismissed) {
|
||||
_controller.stop();
|
||||
_controller.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChoiceAnimationWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.selected && !animationPlayed) {
|
||||
_controller.forward();
|
||||
animationPlayed = true;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.isGold
|
||||
? AnimatedBuilder(
|
||||
key: UniqueKey(),
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return Transform.scale(
|
||||
scale: _animation.value,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: widget.child,
|
||||
)
|
||||
: AnimatedBuilder(
|
||||
key: UniqueKey(),
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return Transform.rotate(
|
||||
angle: _animation.value,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,7 +280,11 @@ class ITChoices extends StatelessWidget {
|
|||
originalSpan: "dummy",
|
||||
choices: controller.currentITStep!.continuances.map((e) {
|
||||
try {
|
||||
return Choice(text: e.text.trim(), color: e.color);
|
||||
return Choice(
|
||||
text: e.text.trim(),
|
||||
color: e.color,
|
||||
isGold: e.description == "best",
|
||||
);
|
||||
} catch (e) {
|
||||
debugger(when: kDebugMode);
|
||||
return Choice(text: "error", color: Colors.red);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import 'package:collection/collection.dart';
|
|||
import 'package:fluffychat/pangea/constants/local.key.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/class_code.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
@ -34,9 +34,10 @@ class ClassController extends BaseController {
|
|||
Future<void> fixClassPowerLevels() async {
|
||||
try {
|
||||
final List<Future<void>> classFixes = [];
|
||||
for (final room in (await _pangeaController
|
||||
.matrixState.client.classesAndExchangesImTeaching)) {
|
||||
classFixes.add(room.setClassPowerlLevels());
|
||||
final teacherSpaces = await _pangeaController
|
||||
.matrixState.client.classesAndExchangesImTeaching;
|
||||
for (final room in teacherSpaces) {
|
||||
classFixes.add(room.setClassPowerLevels());
|
||||
}
|
||||
await Future.wait(classFixes);
|
||||
} catch (err, stack) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'dart:developer';
|
|||
import 'package:fluffychat/pangea/constants/language_keys.dart';
|
||||
import 'package:fluffychat/pangea/controllers/language_list_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/models/language_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../constants/class_default_values.dart';
|
||||
import '../extensions/client_extension.dart';
|
||||
import '../extensions/pangea_room_extension.dart';
|
||||
import '../extensions/client_extension/client_extension.dart';
|
||||
import '../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import '../matrix_event_wrappers/construct_analytics_event.dart';
|
||||
import '../models/chart_analytics_model.dart';
|
||||
import '../models/student_analytics_event.dart';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/representation_content_model.dart';
|
||||
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
|
||||
import 'package:fluffychat/pangea/repo/tokens_repo.dart';
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ import 'dart:developer';
|
|||
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/construct_analytics_event.dart';
|
||||
import 'package:fluffychat/pangea/models/student_analytics_summary_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../extensions/client_extension.dart';
|
||||
import '../extensions/pangea_room_extension.dart';
|
||||
import '../extensions/client_extension/client_extension.dart';
|
||||
import '../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import '../models/constructs_analytics_model.dart';
|
||||
import '../models/student_analytics_event.dart';
|
||||
|
||||
|
|
@ -111,4 +112,48 @@ class MyAnalyticsController {
|
|||
ErrorHandler.logError(e: err, s: s);
|
||||
}
|
||||
}
|
||||
|
||||
// used to aggregate ConstructEvents, from multiple senders (students) with the same lemma
|
||||
List<AggregateConstructUses> aggregateConstructData(
|
||||
List<ConstructEvent> constructs,
|
||||
) {
|
||||
final Map<String, List<ConstructEvent>> lemmasToConstructs = {};
|
||||
for (final construct in constructs) {
|
||||
lemmasToConstructs[construct.content.lemma] ??= [];
|
||||
lemmasToConstructs[construct.content.lemma]!.add(construct);
|
||||
}
|
||||
|
||||
final List<AggregateConstructUses> aggregatedConstructs = [];
|
||||
for (final lemmaToConstructs in lemmasToConstructs.entries) {
|
||||
final List<ConstructEvent> lemmaConstructs = lemmaToConstructs.value;
|
||||
final AggregateConstructUses aggregatedData = AggregateConstructUses(
|
||||
constructs: lemmaConstructs,
|
||||
);
|
||||
aggregatedConstructs.add(aggregatedData);
|
||||
}
|
||||
return aggregatedConstructs;
|
||||
}
|
||||
}
|
||||
|
||||
class AggregateConstructUses {
|
||||
final List<ConstructEvent> _constructs;
|
||||
|
||||
AggregateConstructUses({required List<ConstructEvent> constructs})
|
||||
: _constructs = constructs;
|
||||
|
||||
String get lemma {
|
||||
assert(
|
||||
_constructs.isNotEmpty &&
|
||||
_constructs.every(
|
||||
(construct) =>
|
||||
construct.content.lemma == _constructs.first.content.lemma,
|
||||
),
|
||||
);
|
||||
return _constructs.first.content.lemma;
|
||||
}
|
||||
|
||||
List<OneConstructUse> get uses => _constructs
|
||||
.map((construct) => construct.content.uses)
|
||||
.expand((element) => element)
|
||||
.toList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
|||
import 'package:fluffychat/pangea/controllers/text_to_speech_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/user_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/word_net_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/guard/p_vguard.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:fluffychat/pangea/constants/age_limits.dart';
|
|||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/models/user_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/p_extension.dart';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import '../extensions/pangea_room_extension.dart';
|
||||
import '../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import '../models/class_model.dart';
|
||||
|
||||
class RoomRulesEditController {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'dart:convert';
|
|||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/representation_content_model.dart';
|
||||
import 'package:fluffychat/pangea/models/speech_to_text_models.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
|
|||
|
|
@ -1,336 +0,0 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
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';
|
||||
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,
|
||||
)
|
||||
.toList();
|
||||
|
||||
Future<List<Room>> get classesAndExchangesImTeaching async {
|
||||
final allSpaces = rooms.where((room) => room.isSpace);
|
||||
for (final Room space in allSpaces) {
|
||||
if (space.getState(EventTypes.RoomPowerLevels) == null) {
|
||||
await space.postLoad();
|
||||
}
|
||||
}
|
||||
|
||||
final spaces = rooms
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
return spaces;
|
||||
}
|
||||
|
||||
List<Room> get classesImIn => rooms
|
||||
.where(
|
||||
(e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
Future<List<Room>> get classesAndExchangesImStudyingIn async {
|
||||
for (final Room space in rooms.where((room) => room.isSpace)) {
|
||||
if (space.getState(EventTypes.RoomPowerLevels) == null) {
|
||||
await space.postLoad();
|
||||
}
|
||||
}
|
||||
|
||||
final spaces = rooms
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
return spaces;
|
||||
}
|
||||
|
||||
List<Room> get classesAndExchangesImIn =>
|
||||
rooms.where((e) => e.isPangeaClass || e.isExchange).toList();
|
||||
|
||||
Future<List<String>> get teacherRoomIds async {
|
||||
final List<String> adminRoomIds = [];
|
||||
for (final Room adminSpace in (await classesAndExchangesImTeaching)) {
|
||||
adminRoomIds.add(adminSpace.id);
|
||||
final children = adminSpace.childrenAndGrandChildren;
|
||||
final List<String> adminSpaceRooms = children
|
||||
.where((e) => e.roomId != null)
|
||||
.map((e) => e.roomId!)
|
||||
.toList();
|
||||
adminRoomIds.addAll(adminSpaceRooms);
|
||||
}
|
||||
return adminRoomIds;
|
||||
}
|
||||
|
||||
Future<List<User>> get myTeachers async {
|
||||
final List<User> teachers = [];
|
||||
for (final classRoom in classesAndExchangesImIn) {
|
||||
for (final teacher in await classRoom.teachers) {
|
||||
// If person requesting list of teachers is a teacher in another classroom, don't add them to the list
|
||||
if (!teachers.any((e) => e.id == teacher.id) && userID != teacher.id) {
|
||||
teachers.add(teacher);
|
||||
}
|
||||
}
|
||||
}
|
||||
return teachers;
|
||||
}
|
||||
|
||||
Future<void> updateMyLearningAnalyticsForAllClassesImIn([
|
||||
PLocalStore? storageService,
|
||||
]) async {
|
||||
try {
|
||||
final List<Future<void>> updateFutures = [];
|
||||
for (final classRoom in classesAndExchangesImIn) {
|
||||
updateFutures
|
||||
.add(classRoom.updateMyLearningAnalyticsForClass(storageService));
|
||||
}
|
||||
await Future.wait(updateFutures);
|
||||
} catch (err, s) {
|
||||
if (kDebugMode) rethrow;
|
||||
// debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
}
|
||||
}
|
||||
|
||||
// get analytics room matching targetlanguage
|
||||
// if not present, create it and invite teachers of that language
|
||||
// set description to let people know what the hell it is
|
||||
Future<Room> getMyAnalyticsRoom(String langCode) async {
|
||||
await roomsLoading;
|
||||
// ensure room state events (room create,
|
||||
// to check for analytics type) are loaded
|
||||
for (final room in rooms) {
|
||||
if (room.partial) await room.postLoad();
|
||||
}
|
||||
|
||||
final Room? analyticsRoom = analyticsRoomLocal(langCode);
|
||||
|
||||
if (analyticsRoom != null) return analyticsRoom;
|
||||
|
||||
return _makeAnalyticsRoom(langCode);
|
||||
}
|
||||
|
||||
//note: if langCode is null and user has >1 analyticsRooms then this could
|
||||
//return the wrong one. this is to account for when an exchange might not
|
||||
//be in a class.
|
||||
Room? analyticsRoomLocal(String? langCode, [String? userIdParam]) {
|
||||
final Room? analyticsRoom = rooms.firstWhereOrNull((e) {
|
||||
return e.isAnalyticsRoom &&
|
||||
e.isAnalyticsRoomOfUser(userIdParam ?? userID!) &&
|
||||
(langCode != null ? e.isMadeForLang(langCode) : true);
|
||||
});
|
||||
if (analyticsRoom != null &&
|
||||
analyticsRoom.membership == Membership.invite) {
|
||||
debugger(when: kDebugMode);
|
||||
analyticsRoom
|
||||
.join()
|
||||
.onError(
|
||||
(error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace),
|
||||
)
|
||||
.then((value) => analyticsRoom.postLoad());
|
||||
return analyticsRoom;
|
||||
}
|
||||
return analyticsRoom;
|
||||
}
|
||||
|
||||
Future<Room> _makeAnalyticsRoom(String langCode) async {
|
||||
final String roomID = await createRoom(
|
||||
creationContent: {
|
||||
'type': PangeaRoomTypes.analytics,
|
||||
ModelKey.langCode: langCode,
|
||||
},
|
||||
name: "$userID $langCode Analytics",
|
||||
topic: "This room stores learning analytics for $userID.",
|
||||
invite: [
|
||||
...(await myTeachers).map((e) => e.id),
|
||||
// BotName.localBot,
|
||||
BotName.byEnvironment,
|
||||
],
|
||||
);
|
||||
if (getRoomById(roomID) == null) {
|
||||
// Wait for room actually appears in sync
|
||||
await waitForRoomInSync(roomID, join: true);
|
||||
}
|
||||
|
||||
final Room? analyticsRoom = getRoomById(roomID);
|
||||
|
||||
// add this analytics room to all spaces so teachers can join them
|
||||
// via the space hierarchy
|
||||
await analyticsRoom?.addAnalyticsRoomToSpaces();
|
||||
|
||||
// and invite all teachers to new analytics room
|
||||
await analyticsRoom?.inviteTeachersToAnalyticsRoom();
|
||||
return getRoomById(roomID)!;
|
||||
}
|
||||
|
||||
Future<Room> getReportsDM(User teacher, Room space) async {
|
||||
final String roomId = await teacher.startDirectChat(
|
||||
enableEncryption: false,
|
||||
);
|
||||
space.setSpaceChild(
|
||||
roomId,
|
||||
suggested: false,
|
||||
);
|
||||
return getRoomById(roomId)!;
|
||||
}
|
||||
|
||||
Future<PangeaRoomRules?> get lastUpdatedRoomRules async =>
|
||||
(await 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;
|
||||
|
||||
Future<bool> get hasBotDM async {
|
||||
final List<Room> chats = rooms
|
||||
.where((room) => !room.isSpace && room.membership == Membership.join)
|
||||
.toList();
|
||||
|
||||
for (final Room chat in chats) {
|
||||
if (await chat.isBotDM) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<List<String>> getEditHistory(
|
||||
String roomId,
|
||||
String eventId,
|
||||
) async {
|
||||
final Room? room = getRoomById(roomId);
|
||||
final Event? editEvent = await room?.getEventById(eventId);
|
||||
final String? edittedEventId =
|
||||
editEvent?.content.tryGetMap('m.relates_to')?['event_id'];
|
||||
if (edittedEventId == null) return [];
|
||||
|
||||
final Event? originalEvent = await room!.getEventById(edittedEventId);
|
||||
if (originalEvent == null) return [];
|
||||
|
||||
final Timeline timeline = await room.getTimeline();
|
||||
final List<Event> editEvents = originalEvent
|
||||
.aggregatedEvents(
|
||||
timeline,
|
||||
RelationshipTypes.edit,
|
||||
)
|
||||
.sorted(
|
||||
(a, b) => b.originServerTs.compareTo(a.originServerTs),
|
||||
)
|
||||
.toList();
|
||||
editEvents.add(originalEvent);
|
||||
return editEvents.slice(1).map((e) => e.eventId).toList();
|
||||
}
|
||||
|
||||
// Get all my analytics rooms
|
||||
List<Room> get allMyAnalyticsRooms => rooms
|
||||
.where(
|
||||
(e) => e.isAnalyticsRoomOfUser(userID!),
|
||||
)
|
||||
.toList();
|
||||
|
||||
// migration function to change analytics rooms' vsibility to public
|
||||
// so they will appear in the space hierarchy
|
||||
Future<void> updateAnalyticsRoomVisibility() async {
|
||||
final List<Future> makePublicFutures = [];
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
final visability = await getRoomVisibilityOnDirectory(room.id);
|
||||
if (visability != Visibility.public) {
|
||||
await setRoomVisibilityOnDirectory(
|
||||
room.id,
|
||||
visibility: Visibility.public,
|
||||
);
|
||||
}
|
||||
}
|
||||
await Future.wait(makePublicFutures);
|
||||
}
|
||||
|
||||
// Add all the users' analytics room to all the spaces the student studies in
|
||||
// So teachers can join them via space hierarchy
|
||||
// Will not always work, as there may be spaces where students don't have permission to add chats
|
||||
// But allows teachers to join analytics rooms without being invited
|
||||
Future<void> addAnalyticsRoomsToAllSpaces() async {
|
||||
final List<Future> addFutures = [];
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
addFutures.add(room.addAnalyticsRoomToSpaces());
|
||||
}
|
||||
await Future.wait(addFutures);
|
||||
}
|
||||
|
||||
// Invite teachers to all my analytics room
|
||||
// Handles case when students cannot add analytics room to space(s)
|
||||
// So teacher is still able to get analytics data for this student
|
||||
Future<void> inviteAllTeachersToAllAnalyticsRooms() async {
|
||||
final List<Future> inviteFutures = [];
|
||||
for (final Room analyticsRoom in allMyAnalyticsRooms) {
|
||||
inviteFutures.add(analyticsRoom.inviteTeachersToAnalyticsRoom());
|
||||
}
|
||||
await Future.wait(inviteFutures);
|
||||
}
|
||||
|
||||
// Join all analytics rooms in all spaces
|
||||
// Allows teachers to join analytics rooms without being invited
|
||||
Future<void> joinAnalyticsRoomsInAllSpaces() async {
|
||||
final List<Future> joinFutures = [];
|
||||
for (final Room space in (await classesAndExchangesImTeaching)) {
|
||||
joinFutures.add(space.joinAnalyticsRoomsInSpace());
|
||||
}
|
||||
await Future.wait(joinFutures);
|
||||
}
|
||||
|
||||
// Join invited analytics rooms
|
||||
// Checks for invites to any student analytics rooms
|
||||
// Handles case of analytics rooms that can't be added to some space(s)
|
||||
Future<void> joinInvitedAnalyticsRooms() async {
|
||||
for (final Room room in rooms) {
|
||||
if (room.membership == Membership.invite && room.isAnalyticsRoom) {
|
||||
try {
|
||||
await room.join();
|
||||
} catch (err) {
|
||||
debugPrint("Failed to join analytics room ${room.id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to join all relevant analytics rooms
|
||||
// and set up those rooms to be joined by relevant teachers
|
||||
Future<void> migrateAnalyticsRooms() async {
|
||||
await updateAnalyticsRoomVisibility();
|
||||
await addAnalyticsRoomsToAllSpaces();
|
||||
await inviteAllTeachersToAllAnalyticsRooms();
|
||||
await joinInvitedAnalyticsRooms();
|
||||
await joinAnalyticsRoomsInAllSpaces();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
part of "client_extension.dart";
|
||||
|
||||
extension ClassesAndExchangesClientExtension 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,
|
||||
)
|
||||
.toList();
|
||||
|
||||
Future<List<Room>> get _classesAndExchangesImTeaching async {
|
||||
final allSpaces = rooms.where((room) => room.isSpace);
|
||||
for (final Room space in allSpaces) {
|
||||
if (space.getState(EventTypes.RoomPowerLevels) == null) {
|
||||
await space.postLoad();
|
||||
}
|
||||
}
|
||||
|
||||
final spaces = rooms
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
return spaces;
|
||||
}
|
||||
|
||||
List<Room> get _classesImIn => rooms
|
||||
.where(
|
||||
(e) =>
|
||||
e.isPangeaClass &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
|
||||
Future<List<Room>> get _classesAndExchangesImStudyingIn async {
|
||||
for (final Room space in rooms.where((room) => room.isSpace)) {
|
||||
if (space.getState(EventTypes.RoomPowerLevels) == null) {
|
||||
await space.postLoad();
|
||||
}
|
||||
}
|
||||
|
||||
final spaces = rooms
|
||||
.where(
|
||||
(e) =>
|
||||
(e.isPangeaClass || e.isExchange) &&
|
||||
e.ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin,
|
||||
)
|
||||
.toList();
|
||||
return spaces;
|
||||
}
|
||||
|
||||
List<Room> get _classesAndExchangesImIn =>
|
||||
rooms.where((e) => e.isPangeaClass || e.isExchange).toList();
|
||||
|
||||
Future<PangeaRoomRules?> get _lastUpdatedRoomRules async =>
|
||||
(await _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;
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
part of "client_extension.dart";
|
||||
|
||||
extension AnalyticsClientExtension on Client {
|
||||
// get analytics room matching targetlanguage
|
||||
// if not present, create it and invite teachers of that language
|
||||
// set description to let people know what the hell it is
|
||||
Future<Room> _getMyAnalyticsRoom(String langCode) async {
|
||||
await roomsLoading;
|
||||
// ensure room state events (room create,
|
||||
// to check for analytics type) are loaded
|
||||
for (final room in rooms) {
|
||||
if (room.partial) await room.postLoad();
|
||||
}
|
||||
|
||||
final Room? analyticsRoom = analyticsRoomLocal(langCode);
|
||||
|
||||
if (analyticsRoom != null) return analyticsRoom;
|
||||
|
||||
return _makeAnalyticsRoom(langCode);
|
||||
}
|
||||
|
||||
//note: if langCode is null and user has >1 analyticsRooms then this could
|
||||
//return the wrong one. this is to account for when an exchange might not
|
||||
//be in a class.
|
||||
Room? _analyticsRoomLocal(String? langCode, [String? userIdParam]) {
|
||||
final Room? analyticsRoom = rooms.firstWhereOrNull((e) {
|
||||
return e.isAnalyticsRoom &&
|
||||
e.isAnalyticsRoomOfUser(userIdParam ?? userID!) &&
|
||||
(langCode != null ? e.isMadeForLang(langCode) : true);
|
||||
});
|
||||
if (analyticsRoom != null &&
|
||||
analyticsRoom.membership == Membership.invite) {
|
||||
debugger(when: kDebugMode);
|
||||
analyticsRoom
|
||||
.join()
|
||||
.onError(
|
||||
(error, stackTrace) =>
|
||||
ErrorHandler.logError(e: error, s: stackTrace),
|
||||
)
|
||||
.then((value) => analyticsRoom.postLoad());
|
||||
return analyticsRoom;
|
||||
}
|
||||
return analyticsRoom;
|
||||
}
|
||||
|
||||
Future<Room> _makeAnalyticsRoom(String langCode) async {
|
||||
final String roomID = await createRoom(
|
||||
creationContent: {
|
||||
'type': PangeaRoomTypes.analytics,
|
||||
ModelKey.langCode: langCode,
|
||||
},
|
||||
name: "$userID $langCode Analytics",
|
||||
topic: "This room stores learning analytics for $userID.",
|
||||
invite: [
|
||||
...(await myTeachers).map((e) => e.id),
|
||||
// BotName.localBot,
|
||||
BotName.byEnvironment,
|
||||
],
|
||||
);
|
||||
if (getRoomById(roomID) == null) {
|
||||
// Wait for room actually appears in sync
|
||||
await waitForRoomInSync(roomID, join: true);
|
||||
}
|
||||
|
||||
final Room? analyticsRoom = getRoomById(roomID);
|
||||
|
||||
// add this analytics room to all spaces so teachers can join them
|
||||
// via the space hierarchy
|
||||
await analyticsRoom?.addAnalyticsRoomToSpaces();
|
||||
|
||||
// and invite all teachers to new analytics room
|
||||
await analyticsRoom?.inviteTeachersToAnalyticsRoom();
|
||||
return getRoomById(roomID)!;
|
||||
}
|
||||
|
||||
// Get all my analytics rooms
|
||||
List<Room> get _allMyAnalyticsRooms => rooms
|
||||
.where(
|
||||
(e) => e.isAnalyticsRoomOfUser(userID!),
|
||||
)
|
||||
.toList();
|
||||
|
||||
// migration function to change analytics rooms' vsibility to public
|
||||
// so they will appear in the space hierarchy
|
||||
Future<void> _updateAnalyticsRoomVisibility() async {
|
||||
final List<Future> makePublicFutures = [];
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
final visability = await getRoomVisibilityOnDirectory(room.id);
|
||||
if (visability != Visibility.public) {
|
||||
await setRoomVisibilityOnDirectory(
|
||||
room.id,
|
||||
visibility: Visibility.public,
|
||||
);
|
||||
}
|
||||
}
|
||||
await Future.wait(makePublicFutures);
|
||||
}
|
||||
|
||||
Future<void> _updateMyLearningAnalyticsForAllClassesImIn([
|
||||
PLocalStore? storageService,
|
||||
]) async {
|
||||
try {
|
||||
final List<Future<void>> updateFutures = [];
|
||||
for (final classRoom in classesAndExchangesImIn) {
|
||||
updateFutures
|
||||
.add(classRoom.updateMyLearningAnalyticsForClass(storageService));
|
||||
}
|
||||
await Future.wait(updateFutures);
|
||||
} catch (err, s) {
|
||||
if (kDebugMode) rethrow;
|
||||
// debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all the users' analytics room to all the spaces the student studies in
|
||||
// So teachers can join them via space hierarchy
|
||||
// Will not always work, as there may be spaces where students don't have permission to add chats
|
||||
// But allows teachers to join analytics rooms without being invited
|
||||
Future<void> _addAnalyticsRoomsToAllSpaces() async {
|
||||
final List<Future> addFutures = [];
|
||||
for (final Room room in allMyAnalyticsRooms) {
|
||||
addFutures.add(room.addAnalyticsRoomToSpaces());
|
||||
}
|
||||
await Future.wait(addFutures);
|
||||
}
|
||||
|
||||
// Invite teachers to all my analytics room
|
||||
// Handles case when students cannot add analytics room to space(s)
|
||||
// So teacher is still able to get analytics data for this student
|
||||
Future<void> _inviteAllTeachersToAllAnalyticsRooms() async {
|
||||
final List<Future> inviteFutures = [];
|
||||
for (final Room analyticsRoom in allMyAnalyticsRooms) {
|
||||
inviteFutures.add(analyticsRoom.inviteTeachersToAnalyticsRoom());
|
||||
}
|
||||
await Future.wait(inviteFutures);
|
||||
}
|
||||
|
||||
// Join all analytics rooms in all spaces
|
||||
// Allows teachers to join analytics rooms without being invited
|
||||
Future<void> _joinAnalyticsRoomsInAllSpaces() async {
|
||||
final List<Future> joinFutures = [];
|
||||
for (final Room space in (await _classesAndExchangesImTeaching)) {
|
||||
joinFutures.add(space.joinAnalyticsRoomsInSpace());
|
||||
}
|
||||
await Future.wait(joinFutures);
|
||||
}
|
||||
|
||||
// Join invited analytics rooms
|
||||
// Checks for invites to any student analytics rooms
|
||||
// Handles case of analytics rooms that can't be added to some space(s)
|
||||
Future<void> _joinInvitedAnalyticsRooms() async {
|
||||
for (final Room room in rooms) {
|
||||
if (room.membership == Membership.invite && room.isAnalyticsRoom) {
|
||||
try {
|
||||
await room.join();
|
||||
} catch (err) {
|
||||
debugPrint("Failed to join analytics room ${room.id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to join all relevant analytics rooms
|
||||
// and set up those rooms to be joined by relevant teachers
|
||||
Future<void> _migrateAnalyticsRooms() async {
|
||||
await _updateAnalyticsRoomVisibility();
|
||||
await _addAnalyticsRoomsToAllSpaces();
|
||||
await _inviteAllTeachersToAllAnalyticsRooms();
|
||||
await _joinInvitedAnalyticsRooms();
|
||||
await _joinAnalyticsRoomsInAllSpaces();
|
||||
}
|
||||
}
|
||||
90
lib/pangea/extensions/client_extension/client_extension.dart
Normal file
90
lib/pangea/extensions/client_extension/client_extension.dart
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
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/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';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../utils/p_store.dart';
|
||||
|
||||
part "classes_and_exchanges_extension.dart";
|
||||
part "client_analytics_extension.dart";
|
||||
part "general_info_extension.dart";
|
||||
|
||||
extension PangeaClient on Client {
|
||||
// analytics
|
||||
|
||||
Future<Room> getMyAnalyticsRoom(String langCode) async =>
|
||||
await _getMyAnalyticsRoom(langCode);
|
||||
|
||||
Room? analyticsRoomLocal(String? langCode, [String? userIdParam]) =>
|
||||
_analyticsRoomLocal(langCode, userIdParam);
|
||||
|
||||
List<Room> get allMyAnalyticsRooms => _allMyAnalyticsRooms;
|
||||
|
||||
Future<void> updateAnalyticsRoomVisibility() async =>
|
||||
await _updateAnalyticsRoomVisibility();
|
||||
|
||||
Future<void> updateMyLearningAnalyticsForAllClassesImIn([
|
||||
PLocalStore? storageService,
|
||||
]) async =>
|
||||
await _updateMyLearningAnalyticsForAllClassesImIn(storageService);
|
||||
|
||||
Future<void> addAnalyticsRoomsToAllSpaces() async =>
|
||||
await _addAnalyticsRoomsToAllSpaces();
|
||||
|
||||
Future<void> inviteAllTeachersToAllAnalyticsRooms() async =>
|
||||
await _inviteAllTeachersToAllAnalyticsRooms();
|
||||
|
||||
Future<void> joinAnalyticsRoomsInAllSpaces() async =>
|
||||
await _joinAnalyticsRoomsInAllSpaces();
|
||||
|
||||
Future<void> joinInvitedAnalyticsRooms() async =>
|
||||
await _joinInvitedAnalyticsRooms();
|
||||
|
||||
Future<void> migrateAnalyticsRooms() async => await _migrateAnalyticsRooms();
|
||||
|
||||
// classes_and_exchanges
|
||||
|
||||
List<Room> get classes => _classes;
|
||||
|
||||
List<Room> get classesImTeaching => _classesImTeaching;
|
||||
|
||||
Future<List<Room>> get classesAndExchangesImTeaching async =>
|
||||
await _classesAndExchangesImTeaching;
|
||||
|
||||
List<Room> get classesImIn => _classesImIn;
|
||||
|
||||
Future<List<Room>> get classesAndExchangesImStudyingIn async =>
|
||||
await _classesAndExchangesImStudyingIn;
|
||||
|
||||
List<Room> get classesAndExchangesImIn => _classesAndExchangesImIn;
|
||||
|
||||
Future<PangeaRoomRules?> get lastUpdatedRoomRules async =>
|
||||
await _lastUpdatedRoomRules;
|
||||
|
||||
ClassSettingsModel? get lastUpdatedClassSettings => _lastUpdatedClassSettings;
|
||||
|
||||
// general_info
|
||||
|
||||
Future<List<String>> get teacherRoomIds async => await _teacherRoomIds;
|
||||
|
||||
Future<List<User>> get myTeachers async => await _myTeachers;
|
||||
|
||||
Future<Room> getReportsDM(User teacher, Room space) async =>
|
||||
await _getReportsDM(teacher, space);
|
||||
|
||||
Future<bool> get hasBotDM async => await _hasBotDM;
|
||||
|
||||
Future<List<String>> getEditHistory(
|
||||
String roomId,
|
||||
String eventId,
|
||||
) async =>
|
||||
await _getEditHistory(roomId, eventId);
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
part of "client_extension.dart";
|
||||
|
||||
extension GeneralInfoClientExtension on Client {
|
||||
Future<List<String>> get _teacherRoomIds async {
|
||||
final List<String> adminRoomIds = [];
|
||||
for (final Room adminSpace in (await _classesAndExchangesImTeaching)) {
|
||||
adminRoomIds.add(adminSpace.id);
|
||||
final children = adminSpace.childrenAndGrandChildren;
|
||||
final List<String> adminSpaceRooms = children
|
||||
.where((e) => e.roomId != null)
|
||||
.map((e) => e.roomId!)
|
||||
.toList();
|
||||
adminRoomIds.addAll(adminSpaceRooms);
|
||||
}
|
||||
return adminRoomIds;
|
||||
}
|
||||
|
||||
Future<List<User>> get _myTeachers async {
|
||||
final List<User> teachers = [];
|
||||
for (final classRoom in classesAndExchangesImIn) {
|
||||
for (final teacher in await classRoom.teachers) {
|
||||
// If person requesting list of teachers is a teacher in another classroom, don't add them to the list
|
||||
if (!teachers.any((e) => e.id == teacher.id) && userID != teacher.id) {
|
||||
teachers.add(teacher);
|
||||
}
|
||||
}
|
||||
}
|
||||
return teachers;
|
||||
}
|
||||
|
||||
Future<Room> _getReportsDM(User teacher, Room space) async {
|
||||
final String roomId = await teacher.startDirectChat(
|
||||
enableEncryption: false,
|
||||
);
|
||||
space.setSpaceChild(
|
||||
roomId,
|
||||
suggested: false,
|
||||
);
|
||||
return getRoomById(roomId)!;
|
||||
}
|
||||
|
||||
Future<bool> get _hasBotDM async {
|
||||
final List<Room> chats = rooms
|
||||
.where((room) => !room.isSpace && room.membership == Membership.join)
|
||||
.toList();
|
||||
|
||||
for (final Room chat in chats) {
|
||||
if (await chat.isBotDM) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<List<String>> _getEditHistory(
|
||||
String roomId,
|
||||
String eventId,
|
||||
) async {
|
||||
final Room? room = getRoomById(roomId);
|
||||
final Event? editEvent = await room?.getEventById(eventId);
|
||||
final String? edittedEventId =
|
||||
editEvent?.content.tryGetMap('m.relates_to')?['event_id'];
|
||||
if (edittedEventId == null) return [];
|
||||
|
||||
final Event? originalEvent = await room!.getEventById(edittedEventId);
|
||||
if (originalEvent == null) return [];
|
||||
|
||||
final Timeline timeline = await room.getTimeline();
|
||||
final List<Event> editEvents = originalEvent
|
||||
.aggregatedEvents(
|
||||
timeline,
|
||||
RelationshipTypes.edit,
|
||||
)
|
||||
.sorted(
|
||||
(a, b) => b.originServerTs.compareTo(a.originServerTs),
|
||||
)
|
||||
.toList();
|
||||
editEvents.add(originalEvent);
|
||||
return editEvents.slice(1).map((e) => e.eventId).toList();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,148 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension ChildrenAndParentsRoomExtension on Room {
|
||||
//note this only will return rooms that the user has joined or been invited to
|
||||
List<Room> get _joinedChildren {
|
||||
if (!isSpace) return [];
|
||||
return spaceChildren
|
||||
.where((child) => child.roomId != null)
|
||||
.map(
|
||||
(child) => client.getRoomById(child.roomId!),
|
||||
)
|
||||
.where((child) => child != null)
|
||||
.cast<Room>()
|
||||
.where(
|
||||
(child) => child.membership == Membership.join,
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<String> get _joinedChildrenRoomIds =>
|
||||
joinedChildren.map((child) => child.id).toList();
|
||||
|
||||
List<SpaceChild> get _childrenAndGrandChildren {
|
||||
if (!isSpace) return [];
|
||||
final List<SpaceChild> kids = [];
|
||||
for (final child in spaceChildren) {
|
||||
kids.add(child);
|
||||
if (child.roomId != null) {
|
||||
final Room? childRoom = client.getRoomById(child.roomId!);
|
||||
if (childRoom != null && childRoom.isSpace) {
|
||||
kids.addAll(childRoom.spaceChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
return kids.where((element) => element.roomId != null).toList();
|
||||
}
|
||||
|
||||
//this assumes that a user has been invited to all group chats in a space
|
||||
//it is a janky workaround for determining whether a spacechild is a direct chat
|
||||
//since the spaceChild object doesn't contain this info. this info is only accessible
|
||||
//when the user has joined or been invited to the room. direct chats included in
|
||||
//a space show up in spaceChildren but the user has not been invited to them.
|
||||
List<String> get _childrenAndGrandChildrenDirectChatIds {
|
||||
final List<String> nonDirectChatRoomIds = childrenAndGrandChildren
|
||||
.where((child) => child.roomId != null)
|
||||
.map((e) => client.getRoomById(e.roomId!))
|
||||
.where((r) => r != null && !r.isDirectChat)
|
||||
.map((e) => e!.id)
|
||||
.toList();
|
||||
|
||||
return childrenAndGrandChildren
|
||||
.where(
|
||||
(child) =>
|
||||
child.roomId != null &&
|
||||
!nonDirectChatRoomIds.contains(child.roomId),
|
||||
)
|
||||
.map((e) => e.roomId)
|
||||
.cast<String>()
|
||||
.toList();
|
||||
|
||||
// return childrenAndGrandChildren
|
||||
// .where((element) => element.roomId != null)
|
||||
// .where(
|
||||
// (child) {
|
||||
// final room = client.getRoomById(child.roomId!);
|
||||
// return room == null || room.isDirectChat;
|
||||
// },
|
||||
// )
|
||||
// .map((e) => e.roomId)
|
||||
// .cast<String>()
|
||||
// .toList();
|
||||
}
|
||||
|
||||
Future<List<Room>> _getChildRooms() async {
|
||||
final List<Room> children = [];
|
||||
for (final child in spaceChildren) {
|
||||
if (child.roomId == null) continue;
|
||||
final Room? room = client.getRoomById(child.roomId!);
|
||||
if (room != null) {
|
||||
children.add(room);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
Future<void> _joinSpaceChild(String roomID) async {
|
||||
final Room? child = client.getRoomById(roomID);
|
||||
if (child == null) {
|
||||
await client.joinRoom(
|
||||
roomID,
|
||||
serverName: spaceChildren
|
||||
.firstWhereOrNull((child) => child.roomId == roomID)
|
||||
?.via,
|
||||
);
|
||||
if (client.getRoomById(roomID) == null) {
|
||||
await client.waitForRoomInSync(roomID, join: true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (![Membership.invite, Membership.join].contains(child.membership)) {
|
||||
final waitForRoom = client.waitForRoomInSync(
|
||||
roomID,
|
||||
join: true,
|
||||
);
|
||||
await child.join();
|
||||
await waitForRoom;
|
||||
}
|
||||
}
|
||||
|
||||
//resolve somehow if multiple rooms have the state?
|
||||
//check logic
|
||||
Room? _firstParentWithState(String stateType) {
|
||||
if (![PangeaEventTypes.classSettings, PangeaEventTypes.rules]
|
||||
.contains(stateType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
if (parent.getState(stateType) != null) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
final parentFirstRoom = parent.firstParentWithState(stateType);
|
||||
if (parentFirstRoom != null) return parentFirstRoom;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// find any parents and return the rooms
|
||||
List<Room> get _immediateClassParents => pangeaSpaceParents
|
||||
.where(
|
||||
(element) => element.isPangeaClass,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Room> get _pangeaSpaceParents => client.rooms
|
||||
.where(
|
||||
(r) => r.isSpace,
|
||||
)
|
||||
.where(
|
||||
(space) => space.spaceChildren.any(
|
||||
(room) => room.roomId == id,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension ClassAndExchangeSettingsRoomExtension on Room {
|
||||
DateTime? get _rulesUpdatedAt {
|
||||
if (!isSpace) return null;
|
||||
return pangeaRoomRulesStateEvent?.originServerTs ?? creationTime;
|
||||
}
|
||||
|
||||
String get _classCode {
|
||||
if (!isSpace) {
|
||||
for (final Room potentialClassRoom in pangeaSpaceParents) {
|
||||
if (potentialClassRoom.isPangeaClass) {
|
||||
return potentialClassRoom.classCode;
|
||||
}
|
||||
}
|
||||
return "Not in a class!";
|
||||
}
|
||||
|
||||
return canonicalAlias.replaceAll(":$domainString", "").replaceAll("#", "");
|
||||
}
|
||||
|
||||
void _checkClass() {
|
||||
if (!isSpace) {
|
||||
debugger(when: kDebugMode);
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(message: "calling room.students with non-class room"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<User> get _students {
|
||||
checkClass();
|
||||
return isSpace
|
||||
? getParticipants()
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel < ClassDefaultValues.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList()
|
||||
: getParticipants();
|
||||
}
|
||||
|
||||
Future<List<User>> get _teachers async {
|
||||
checkClass();
|
||||
final List<User> participants = await requestParticipants();
|
||||
return isSpace
|
||||
? participants
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel == ClassDefaultValues.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList()
|
||||
: participants;
|
||||
}
|
||||
|
||||
Future<void> _setClassPowerLevels() async {
|
||||
try {
|
||||
if (ownPowerLevel < ClassDefaultValues.powerLevelOfAdmin) {
|
||||
return;
|
||||
}
|
||||
final Event? currentPower = getState(EventTypes.RoomPowerLevels);
|
||||
final Map<String, dynamic>? currentPowerContent =
|
||||
currentPower?.content as Map<String, dynamic>?;
|
||||
if (currentPowerContent == null) {
|
||||
return;
|
||||
}
|
||||
if (!(currentPowerContent.containsKey("events"))) {
|
||||
currentPowerContent["events"] = {};
|
||||
}
|
||||
final spaceChildPower =
|
||||
currentPowerContent["events"][EventTypes.spaceChild];
|
||||
final studentAnalyticsPower =
|
||||
currentPowerContent[PangeaEventTypes.studentAnalyticsSummary];
|
||||
|
||||
if ((spaceChildPower == null || studentAnalyticsPower == null)) {
|
||||
currentPowerContent["events"][EventTypes.spaceChild] = 0;
|
||||
currentPowerContent["events"]
|
||||
[PangeaEventTypes.studentAnalyticsSummary] = 0;
|
||||
|
||||
await client.setRoomStateWithKey(
|
||||
id,
|
||||
EventTypes.RoomPowerLevels,
|
||||
currentPower?.stateKey ?? "",
|
||||
currentPowerContent,
|
||||
);
|
||||
}
|
||||
} catch (err, s) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: s, data: toJson());
|
||||
}
|
||||
}
|
||||
|
||||
DateTime? get _classSettingsUpdatedAt {
|
||||
if (!isSpace) return null;
|
||||
return languageSettingsStateEvent?.originServerTs ?? creationTime;
|
||||
}
|
||||
|
||||
/// the pangeaClass event is listed an importantStateEvent so, if event exists,
|
||||
/// it's already local. If it's an old class and doesn't, then the class_controller
|
||||
/// should automatically migrate during this same session, when the space is first loaded
|
||||
ClassSettingsModel? get _classSettings {
|
||||
try {
|
||||
if (!isSpace) {
|
||||
return null;
|
||||
}
|
||||
final Map<String, dynamic>? content = languageSettingsStateEvent?.content;
|
||||
if (content != null) {
|
||||
final ClassSettingsModel classSettings =
|
||||
ClassSettingsModel.fromJson(content);
|
||||
return classSettings;
|
||||
}
|
||||
return null;
|
||||
} catch (err, s) {
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "Error in classSettings",
|
||||
data: {"room": toJson()},
|
||||
),
|
||||
);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Event? get _languageSettingsStateEvent =>
|
||||
getState(PangeaEventTypes.classSettings);
|
||||
|
||||
Event? get _pangeaRoomRulesStateEvent => getState(PangeaEventTypes.rules);
|
||||
|
||||
ClassSettingsModel? get _firstLanguageSettings =>
|
||||
classSettings ??
|
||||
firstParentWithState(PangeaEventTypes.classSettings)?.classSettings;
|
||||
}
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension EventsRoomExtension on Room {
|
||||
Future<Event?> _sendPangeaEvent({
|
||||
required Map<String, dynamic> content,
|
||||
required String parentEventId,
|
||||
required String type,
|
||||
}) async {
|
||||
try {
|
||||
debugPrint("creating $type child for $parentEventId");
|
||||
Sentry.addBreadcrumb(Breadcrumb.fromJson(content));
|
||||
if (parentEventId.contains("web")) {
|
||||
debugger(when: kDebugMode);
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message:
|
||||
"sendPangeaEvent with likely invalid parentEventId $parentEventId",
|
||||
),
|
||||
);
|
||||
}
|
||||
final Map<String, dynamic> repContent = {
|
||||
// what is the functionality of m.reference?
|
||||
"m.relates_to": {"rel_type": type, "event_id": parentEventId},
|
||||
type: content,
|
||||
};
|
||||
|
||||
final String? newEventId = await sendEvent(repContent, type: type);
|
||||
|
||||
if (newEventId == null) {
|
||||
debugger(when: kDebugMode);
|
||||
return null;
|
||||
}
|
||||
|
||||
//PTODO - handle the frequent case of a null newEventId
|
||||
final Event? newEvent = await getEventById(newEventId);
|
||||
|
||||
if (newEvent == null) {
|
||||
debugger(when: kDebugMode);
|
||||
}
|
||||
|
||||
return newEvent;
|
||||
} catch (err, stack) {
|
||||
// debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
s: stack,
|
||||
data: {
|
||||
"type": type,
|
||||
"parentEventId": parentEventId,
|
||||
"content": content,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _pangeaSendTextEvent(
|
||||
String message, {
|
||||
String? txid,
|
||||
Event? inReplyTo,
|
||||
String? editEventId,
|
||||
bool parseMarkdown = true,
|
||||
bool parseCommands = false,
|
||||
String msgtype = MessageTypes.Text,
|
||||
String? threadRootEventId,
|
||||
String? threadLastEventId,
|
||||
PangeaRepresentation? originalSent,
|
||||
PangeaRepresentation? originalWritten,
|
||||
PangeaMessageTokens? tokensSent,
|
||||
PangeaMessageTokens? tokensWritten,
|
||||
ChoreoRecord? choreo,
|
||||
UseType? useType,
|
||||
}) {
|
||||
// if (parseCommands) {
|
||||
// return client.parseAndRunCommand(this, message,
|
||||
// inReplyTo: inReplyTo,
|
||||
// editEventId: editEventId,
|
||||
// txid: txid,
|
||||
// threadRootEventId: threadRootEventId,
|
||||
// threadLastEventId: threadLastEventId);
|
||||
// }
|
||||
final event = <String, dynamic>{
|
||||
'msgtype': msgtype,
|
||||
'body': message,
|
||||
ModelKey.choreoRecord: choreo?.toJson(),
|
||||
ModelKey.originalSent: originalSent?.toJson(),
|
||||
ModelKey.originalWritten: originalWritten?.toJson(),
|
||||
ModelKey.tokensSent: tokensSent?.toJson(),
|
||||
ModelKey.tokensWritten: tokensWritten?.toJson(),
|
||||
ModelKey.useType: useType?.string,
|
||||
};
|
||||
if (parseMarkdown) {
|
||||
final html = markdown(
|
||||
event['body'],
|
||||
getEmotePacks: () => getImagePacksFlat(ImagePackUsage.emoticon),
|
||||
getMention: getMention,
|
||||
);
|
||||
// if the decoded html is the same as the body, there is no need in sending a formatted message
|
||||
if (HtmlUnescape().convert(html.replaceAll(RegExp(r'<br />\n?'), '\n')) !=
|
||||
event['body']) {
|
||||
event['format'] = 'org.matrix.custom.html';
|
||||
event['formatted_body'] = html;
|
||||
}
|
||||
}
|
||||
return sendEvent(
|
||||
event,
|
||||
txid: txid,
|
||||
inReplyTo: inReplyTo,
|
||||
editEventId: editEventId,
|
||||
threadRootEventId: threadRootEventId,
|
||||
threadLastEventId: threadLastEventId,
|
||||
);
|
||||
}
|
||||
|
||||
/// update state event and return eventId
|
||||
Future<String> _updateStateEvent(Event stateEvent) {
|
||||
if (stateEvent.stateKey == null) {
|
||||
throw Exception("stateEvent.stateKey is null");
|
||||
}
|
||||
return client.setRoomStateWithKey(
|
||||
id,
|
||||
stateEvent.type,
|
||||
stateEvent.stateKey!,
|
||||
stateEvent.content,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<RecentMessageRecord>> get _messageListForAllChildChats async {
|
||||
try {
|
||||
if (!isSpace) return [];
|
||||
final List<Room> spaceChats = spaceChildren
|
||||
.where((e) => e.roomId != null)
|
||||
.map((e) => client.getRoomById(e.roomId!))
|
||||
.where((element) => element != null)
|
||||
.cast<Room>()
|
||||
.where((element) => !element.isSpace)
|
||||
.toList();
|
||||
|
||||
final List<Future<List<RecentMessageRecord>>> msgListFutures = [];
|
||||
for (final chat in spaceChats) {
|
||||
msgListFutures.add(chat._messageListForChat);
|
||||
}
|
||||
final List<List<RecentMessageRecord>> msgLists =
|
||||
await Future.wait(msgListFutures);
|
||||
|
||||
final List<RecentMessageRecord> joined = [];
|
||||
for (final msgList in msgLists) {
|
||||
joined.addAll(msgList);
|
||||
}
|
||||
return joined;
|
||||
} catch (err) {
|
||||
// debugger(when: kDebugMode);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<RecentMessageRecord>> get _messageListForChat async {
|
||||
try {
|
||||
int numberOfSearches = 0;
|
||||
|
||||
if (isSpace) {
|
||||
throw Exception(
|
||||
"In messageListForChat with room that is not a chat",
|
||||
);
|
||||
}
|
||||
final Timeline timeline = await getTimeline();
|
||||
|
||||
while (timeline.canRequestHistory && numberOfSearches < 50) {
|
||||
await timeline.requestHistory(historyCount: 100);
|
||||
numberOfSearches += 1;
|
||||
}
|
||||
if (timeline.canRequestHistory) {
|
||||
debugger(when: kDebugMode);
|
||||
}
|
||||
|
||||
final List<RecentMessageRecord> msgs = [];
|
||||
for (final event in timeline.events) {
|
||||
if (event.senderId == client.userID &&
|
||||
event.type == EventTypes.Message &&
|
||||
event.content['msgtype'] == MessageTypes.Text) {
|
||||
final PangeaMessageEvent pMsgEvent = PangeaMessageEvent(
|
||||
event: event,
|
||||
timeline: timeline,
|
||||
ownMessage: true,
|
||||
);
|
||||
msgs.add(
|
||||
RecentMessageRecord(
|
||||
eventId: event.eventId,
|
||||
chatId: id,
|
||||
useType: pMsgEvent.useType,
|
||||
time: event.originServerTs,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return msgs;
|
||||
} catch (err, s) {
|
||||
if (kDebugMode) rethrow;
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
ConstructEvent? _vocabEventLocal(String lemma) {
|
||||
if (!isAnalyticsRoom) throw Exception("not an analytics room");
|
||||
|
||||
final Event? matrixEvent = getState(PangeaEventTypes.vocab, lemma);
|
||||
|
||||
return matrixEvent != null ? ConstructEvent(event: matrixEvent) : null;
|
||||
}
|
||||
|
||||
Future<ConstructEvent> _vocabEvent(
|
||||
String lemma,
|
||||
ConstructType type, [
|
||||
bool makeIfNull = false,
|
||||
]) async {
|
||||
try {
|
||||
if (!isAnalyticsRoom) throw Exception("not an analytics room");
|
||||
|
||||
ConstructEvent? localEvent = _vocabEventLocal(lemma);
|
||||
|
||||
if (localEvent != null) return localEvent;
|
||||
|
||||
await postLoad();
|
||||
localEvent = _vocabEventLocal(lemma);
|
||||
|
||||
if (localEvent == null && isRoomOwner && makeIfNull) {
|
||||
final Event matrixEvent = await _createVocabEvent(lemma, type);
|
||||
localEvent = ConstructEvent(event: matrixEvent);
|
||||
}
|
||||
|
||||
return localEvent!;
|
||||
} catch (err) {
|
||||
debugger(when: kDebugMode);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<OneConstructUse>> _removeEditedLemmas(
|
||||
List<OneConstructUse> lemmaUses,
|
||||
) async {
|
||||
final List<String> removeUses = [];
|
||||
for (final use in lemmaUses) {
|
||||
if (use.msgId == null) continue;
|
||||
final List<String> removeIds = await client.getEditHistory(
|
||||
use.chatId,
|
||||
use.msgId!,
|
||||
);
|
||||
removeUses.addAll(removeIds);
|
||||
}
|
||||
lemmaUses.removeWhere((use) => removeUses.contains(use.msgId));
|
||||
final allEvents = await allConstructEvents;
|
||||
for (final constructEvent in allEvents) {
|
||||
await constructEvent.removeEdittedUses(removeUses, client);
|
||||
}
|
||||
return lemmaUses;
|
||||
}
|
||||
|
||||
Future<void> _saveConstructUsesSameLemma(
|
||||
String lemma,
|
||||
ConstructType type,
|
||||
List<OneConstructUse> lemmaUses, {
|
||||
bool isEdit = false,
|
||||
}) async {
|
||||
final ConstructEvent? localEvent = _vocabEventLocal(lemma);
|
||||
|
||||
if (isEdit) {
|
||||
lemmaUses = await removeEditedLemmas(lemmaUses);
|
||||
}
|
||||
|
||||
if (localEvent == null) {
|
||||
await client.setRoomStateWithKey(
|
||||
id,
|
||||
PangeaEventTypes.vocab,
|
||||
lemma,
|
||||
ConstructUses(lemma: lemma, type: type, uses: lemmaUses).toJson(),
|
||||
);
|
||||
} else {
|
||||
localEvent.addAll(lemmaUses);
|
||||
await updateStateEvent(localEvent.event);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ConstructEvent>> get _allConstructEvents async {
|
||||
await postLoad();
|
||||
return states[PangeaEventTypes.vocab]
|
||||
?.values
|
||||
.map((Event event) => ConstructEvent(event: event))
|
||||
.toList()
|
||||
.cast<ConstructEvent>() ??
|
||||
[];
|
||||
}
|
||||
|
||||
Future<Event> _createVocabEvent(String lemma, ConstructType type) async {
|
||||
try {
|
||||
if (!isRoomOwner) {
|
||||
throw Exception(
|
||||
"Tried to create vocab event in room where user is not owner",
|
||||
);
|
||||
}
|
||||
final String eventId = await client.setRoomStateWithKey(
|
||||
id,
|
||||
PangeaEventTypes.vocab,
|
||||
lemma,
|
||||
ConstructUses(lemma: lemma, type: type).toJson(),
|
||||
);
|
||||
final Event? event = await getEventById(eventId);
|
||||
|
||||
if (event == null) {
|
||||
debugger(when: kDebugMode);
|
||||
throw Exception(
|
||||
"null event after creation with eventId $eventId in _createVocabEvent",
|
||||
);
|
||||
}
|
||||
return event;
|
||||
} catch (err, stack) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: stack, data: powerLevels);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,286 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
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/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/models/bot_options_model.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import markdown.dart
|
||||
import 'package:html_unescape/html_unescape.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix/src/utils/markdown.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';
|
||||
import '../../enum/use_type.dart';
|
||||
import '../../matrix_event_wrappers/construct_analytics_event.dart';
|
||||
import '../../models/choreo_record.dart';
|
||||
import '../../models/constructs_analytics_model.dart';
|
||||
import '../../models/representation_content_model.dart';
|
||||
import '../../models/student_analytics_event.dart';
|
||||
import '../../models/student_analytics_summary_model.dart';
|
||||
import '../../utils/p_store.dart';
|
||||
import '../client_extension/client_extension.dart';
|
||||
|
||||
part "children_and_parents_extension.dart";
|
||||
part "class_and_exchange_settings_extension.dart";
|
||||
part "events_extension.dart";
|
||||
part "room_analytics_extension.dart";
|
||||
part "room_information_extension.dart";
|
||||
part "room_settings_extension.dart";
|
||||
part "user_permissions_extension.dart";
|
||||
|
||||
extension PangeaRoom on Room {
|
||||
// analytics
|
||||
|
||||
Future<void> joinAnalyticsRoomsInSpace() async =>
|
||||
await _joinAnalyticsRoomsInSpace();
|
||||
|
||||
Future<void> ensureAnalyticsRoomExists() async =>
|
||||
await _ensureAnalyticsRoomExists();
|
||||
|
||||
Future<void> addAnalyticsRoomToSpace(Room analyticsRoom) async =>
|
||||
await _addAnalyticsRoomToSpace(analyticsRoom);
|
||||
|
||||
Future<void> addAnalyticsRoomToSpaces() async =>
|
||||
await _addAnalyticsRoomToSpaces();
|
||||
|
||||
Future<void> addAnalyticsRoomsToSpace() async =>
|
||||
await _addAnalyticsRoomsToSpace();
|
||||
|
||||
Future<StudentAnalyticsEvent?> getStudentAnalytics(
|
||||
String studentId, {
|
||||
bool forcedUpdate = false,
|
||||
}) async =>
|
||||
await _getStudentAnalytics(studentId, forcedUpdate: forcedUpdate);
|
||||
|
||||
Future<List<StudentAnalyticsEvent?>> getClassAnalytics([
|
||||
List<String>? studentIds,
|
||||
]) async =>
|
||||
await _getClassAnalytics(
|
||||
studentIds,
|
||||
);
|
||||
|
||||
Future<void> updateMyLearningAnalyticsForClass([
|
||||
PLocalStore? storageService,
|
||||
]) async =>
|
||||
await _updateMyLearningAnalyticsForClass(
|
||||
storageService,
|
||||
);
|
||||
|
||||
Future<void> inviteSpaceTeachersToAnalyticsRoom(Room analyticsRoom) async =>
|
||||
await _inviteSpaceTeachersToAnalyticsRoom(analyticsRoom);
|
||||
|
||||
Future<void> inviteTeachersToAnalyticsRoom() async =>
|
||||
await _inviteTeachersToAnalyticsRoom();
|
||||
|
||||
// Invite teachers of 1 space to all users' analytics rooms
|
||||
Future<void> inviteSpaceTeachersToAnalyticsRooms() async =>
|
||||
await _inviteSpaceTeachersToAnalyticsRooms();
|
||||
|
||||
// children_and_parents
|
||||
|
||||
List<Room> get joinedChildren => _joinedChildren;
|
||||
|
||||
List<String> get joinedChildrenRoomIds => _joinedChildrenRoomIds;
|
||||
|
||||
List<SpaceChild> get childrenAndGrandChildren => _childrenAndGrandChildren;
|
||||
|
||||
List<String> get childrenAndGrandChildrenDirectChatIds =>
|
||||
_childrenAndGrandChildrenDirectChatIds;
|
||||
|
||||
Future<List<Room>> getChildRooms() async => await _getChildRooms();
|
||||
|
||||
Future<void> joinSpaceChild(String roomID) async =>
|
||||
await _joinSpaceChild(roomID);
|
||||
|
||||
Room? firstParentWithState(String stateType) =>
|
||||
_firstParentWithState(stateType);
|
||||
|
||||
List<Room> get immediateClassParents => _immediateClassParents;
|
||||
|
||||
List<Room> get pangeaSpaceParents => _pangeaSpaceParents;
|
||||
|
||||
// class_and_exchange_settings
|
||||
|
||||
DateTime? get rulesUpdatedAt => _rulesUpdatedAt;
|
||||
|
||||
String get classCode => _classCode;
|
||||
|
||||
void checkClass() => _checkClass();
|
||||
|
||||
List<User> get students => _students;
|
||||
|
||||
Future<List<User>> get teachers async => await _teachers;
|
||||
|
||||
Future<void> setClassPowerLevels() async => await _setClassPowerLevels();
|
||||
|
||||
DateTime? get classSettingsUpdatedAt => _classSettingsUpdatedAt;
|
||||
|
||||
ClassSettingsModel? get classSettings => _classSettings;
|
||||
|
||||
Event? get languageSettingsStateEvent => _languageSettingsStateEvent;
|
||||
|
||||
Event? get pangeaRoomRulesStateEvent => _pangeaRoomRulesStateEvent;
|
||||
|
||||
ClassSettingsModel? get firstLanguageSettings => _firstLanguageSettings;
|
||||
|
||||
// events
|
||||
|
||||
Future<Event?> sendPangeaEvent({
|
||||
required Map<String, dynamic> content,
|
||||
required String parentEventId,
|
||||
required String type,
|
||||
}) async =>
|
||||
await _sendPangeaEvent(
|
||||
content: content,
|
||||
parentEventId: parentEventId,
|
||||
type: type,
|
||||
);
|
||||
|
||||
Future<String?> pangeaSendTextEvent(
|
||||
String message, {
|
||||
String? txid,
|
||||
Event? inReplyTo,
|
||||
String? editEventId,
|
||||
bool parseMarkdown = true,
|
||||
bool parseCommands = false,
|
||||
String msgtype = MessageTypes.Text,
|
||||
String? threadRootEventId,
|
||||
String? threadLastEventId,
|
||||
PangeaRepresentation? originalSent,
|
||||
PangeaRepresentation? originalWritten,
|
||||
PangeaMessageTokens? tokensSent,
|
||||
PangeaMessageTokens? tokensWritten,
|
||||
ChoreoRecord? choreo,
|
||||
UseType? useType,
|
||||
}) =>
|
||||
_pangeaSendTextEvent(
|
||||
message,
|
||||
txid: txid,
|
||||
inReplyTo: inReplyTo,
|
||||
editEventId: editEventId,
|
||||
parseMarkdown: parseMarkdown,
|
||||
parseCommands: parseCommands,
|
||||
msgtype: msgtype,
|
||||
threadRootEventId: threadRootEventId,
|
||||
threadLastEventId: threadLastEventId,
|
||||
originalSent: originalSent,
|
||||
originalWritten: originalWritten,
|
||||
tokensSent: tokensSent,
|
||||
tokensWritten: tokensWritten,
|
||||
choreo: choreo,
|
||||
useType: useType,
|
||||
);
|
||||
|
||||
Future<String> updateStateEvent(Event stateEvent) =>
|
||||
_updateStateEvent(stateEvent);
|
||||
|
||||
Future<ConstructEvent> vocabEvent(
|
||||
String lemma,
|
||||
ConstructType type, [
|
||||
bool makeIfNull = false,
|
||||
]) =>
|
||||
_vocabEvent(lemma, type, makeIfNull);
|
||||
|
||||
Future<List<OneConstructUse>> removeEditedLemmas(
|
||||
List<OneConstructUse> lemmaUses,
|
||||
) async =>
|
||||
await _removeEditedLemmas(lemmaUses);
|
||||
|
||||
Future<void> saveConstructUsesSameLemma(
|
||||
String lemma,
|
||||
ConstructType type,
|
||||
List<OneConstructUse> lemmaUses, {
|
||||
bool isEdit = false,
|
||||
}) async =>
|
||||
await _saveConstructUsesSameLemma(lemma, type, lemmaUses, isEdit: isEdit);
|
||||
|
||||
Future<List<ConstructEvent>> get allConstructEvents async =>
|
||||
await _allConstructEvents;
|
||||
|
||||
// room_information
|
||||
|
||||
DateTime? get creationTime => _creationTime;
|
||||
|
||||
String? get creatorId => _creatorId;
|
||||
|
||||
String get domainString => _domainString;
|
||||
|
||||
bool isChild(String roomId) => _isChild(roomId);
|
||||
|
||||
bool isFirstOrSecondChild(String roomId) => _isFirstOrSecondChild(roomId);
|
||||
|
||||
bool get isExchange => _isExchange;
|
||||
|
||||
bool get isDirectChatWithoutMe => _isDirectChatWithoutMe;
|
||||
|
||||
bool isMadeForLang(String langCode) => _isMadeForLang(langCode);
|
||||
|
||||
Future<bool> get isBotRoom async => await _isBotRoom;
|
||||
|
||||
Future<bool> get isBotDM async => await _isBotDM;
|
||||
|
||||
bool get isLocked => _isLocked;
|
||||
|
||||
bool get isPangeaClass => _isPangeaClass;
|
||||
|
||||
bool isAnalyticsRoomOfUser(String userId) => _isAnalyticsRoomOfUser(userId);
|
||||
|
||||
bool get isAnalyticsRoom => _isAnalyticsRoom;
|
||||
|
||||
// room_settings
|
||||
|
||||
PangeaRoomRules? get pangeaRoomRules => _pangeaRoomRules;
|
||||
|
||||
PangeaRoomRules? get firstRules => _firstRules;
|
||||
|
||||
IconData? get roomTypeIcon => _roomTypeIcon;
|
||||
|
||||
Text nameAndRoomTypeIcon([TextStyle? textStyle]) =>
|
||||
_nameAndRoomTypeIcon(textStyle);
|
||||
|
||||
BotOptionsModel? get botOptions => _botOptions;
|
||||
|
||||
Future<void> setSuggested(bool suggested) async =>
|
||||
await _setSuggested(suggested);
|
||||
|
||||
Future<bool> isSuggested() async => await _isSuggested();
|
||||
|
||||
// user_permissions
|
||||
|
||||
bool isMadeByUser(String userId) => _isMadeByUser(userId);
|
||||
|
||||
bool get isSpaceAdmin => _isSpaceAdmin;
|
||||
|
||||
bool isUserRoomAdmin(String userId) => _isUserRoomAdmin(userId);
|
||||
|
||||
bool isUserSpaceAdmin(String userId) => _isUserSpaceAdmin(userId);
|
||||
|
||||
bool get isRoomOwner => _isRoomOwner;
|
||||
|
||||
bool get isRoomAdmin => _isRoomAdmin;
|
||||
|
||||
bool get showClassEditOptions => _showClassEditOptions;
|
||||
|
||||
bool get canDelete => _canDelete;
|
||||
|
||||
bool canIAddSpaceChild(Room? room) => _canIAddSpaceChild(room);
|
||||
|
||||
bool get canIAddSpaceParents => _canIAddSpaceParents;
|
||||
|
||||
bool pangeaCanSendEvent(String eventType) => _pangeaCanSendEvent(eventType);
|
||||
|
||||
int? get eventsDefaultPowerLevel => _eventsDefaultPowerLevel;
|
||||
}
|
||||
|
|
@ -0,0 +1,376 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension AnalyticsRoomExtension on Room {
|
||||
// Join analytics rooms in space
|
||||
// Allows teachers to join analytics rooms without being invited
|
||||
Future<void> _joinAnalyticsRoomsInSpace() async {
|
||||
if (!isSpace) {
|
||||
debugPrint("joinAnalyticsRoomsInSpace called on non-space room");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "joinAnalyticsRoomsInSpace called on non-space room",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// added delay because without it power levels don't load and user is not
|
||||
// recognized as admin
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
await postLoad();
|
||||
|
||||
if (!isRoomAdmin) {
|
||||
debugPrint("joinAnalyticsRoomsInSpace called by non-admin");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "joinAnalyticsRoomsInSpace called by non-admin",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final spaceHierarchy = await client.getSpaceHierarchy(
|
||||
id,
|
||||
maxDepth: 1,
|
||||
);
|
||||
|
||||
final List<String> analyticsRoomIds = spaceHierarchy.rooms
|
||||
.where(
|
||||
(r) => r.roomType == PangeaRoomTypes.analytics,
|
||||
)
|
||||
.map((r) => r.roomId)
|
||||
.toList();
|
||||
|
||||
for (final String roomID in analyticsRoomIds) {
|
||||
try {
|
||||
await joinSpaceChild(roomID);
|
||||
} catch (err, s) {
|
||||
debugPrint("Failed to join analytics room $roomID in space $id");
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
m: "Failed to join analytics room $roomID in space $id",
|
||||
s: s,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if analytics room exists for a given language code
|
||||
// and if not, create it
|
||||
Future<void> _ensureAnalyticsRoomExists() async {
|
||||
await postLoad();
|
||||
if (firstLanguageSettings?.targetLanguage == null) return;
|
||||
await client.getMyAnalyticsRoom(firstLanguageSettings!.targetLanguage);
|
||||
}
|
||||
|
||||
// add 1 analytics room to 1 space
|
||||
Future<void> _addAnalyticsRoomToSpace(Room analyticsRoom) async {
|
||||
if (!isSpace) {
|
||||
debugPrint("addAnalyticsRoomToSpace called on non-space room");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "addAnalyticsRoomToSpace called on non-space room",
|
||||
),
|
||||
);
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
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",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add analytics room to all spaces the user is a student in (1 analytics room to all spaces)
|
||||
// So teachers can join them via space hierarchy
|
||||
// Will not always work, as there may be spaces where students don't have permission to add chats
|
||||
// But allows teachers to join analytics rooms without being invited
|
||||
Future<void> _addAnalyticsRoomToSpaces() async {
|
||||
if (!isAnalyticsRoomOfUser(client.userID!)) {
|
||||
debugPrint("addAnalyticsRoomToSpaces called on non-analytics room");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "addAnalyticsRoomToSpaces called on non-analytics room",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Room space in (await client.classesAndExchangesImStudyingIn)) {
|
||||
if (space.spaceChildren.any((sc) => sc.roomId == id)) continue;
|
||||
await space.addAnalyticsRoomToSpace(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all analytics rooms to space
|
||||
// Similar to addAnalyticsRoomToSpaces, but all analytics room to 1 space
|
||||
Future<void> _addAnalyticsRoomsToSpace() async {
|
||||
await postLoad();
|
||||
final List<Room> allMyAnalyticsRooms = client.allMyAnalyticsRooms;
|
||||
for (final Room analyticsRoom in allMyAnalyticsRooms) {
|
||||
await addAnalyticsRoomToSpace(analyticsRoom);
|
||||
}
|
||||
}
|
||||
|
||||
StudentAnalyticsEvent? _getStudentAnalyticsLocal(String studentId) {
|
||||
if (!isSpace) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(
|
||||
m: "calling getStudentAnalyticsLocal on non-space room",
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
final Event? matrixEvent = getState(
|
||||
PangeaEventTypes.studentAnalyticsSummary,
|
||||
studentId,
|
||||
);
|
||||
|
||||
return matrixEvent != null
|
||||
? StudentAnalyticsEvent(event: matrixEvent)
|
||||
: null;
|
||||
}
|
||||
|
||||
Future<StudentAnalyticsEvent?> _getStudentAnalytics(
|
||||
String studentId, {
|
||||
bool forcedUpdate = false,
|
||||
}) async {
|
||||
try {
|
||||
if (!isSpace) {
|
||||
debugger(when: kDebugMode);
|
||||
throw Exception("calling getStudentAnalyticsLocal on non-space room");
|
||||
}
|
||||
StudentAnalyticsEvent? localEvent = _getStudentAnalyticsLocal(studentId);
|
||||
|
||||
if (localEvent == null) {
|
||||
await postLoad();
|
||||
localEvent = _getStudentAnalyticsLocal(studentId);
|
||||
}
|
||||
|
||||
if (studentId == client.userID && localEvent == null) {
|
||||
final Event? matrixEvent = await _createStudentAnalyticsEvent();
|
||||
if (matrixEvent != null) {
|
||||
localEvent = StudentAnalyticsEvent(event: matrixEvent);
|
||||
}
|
||||
}
|
||||
|
||||
return localEvent;
|
||||
} catch (err) {
|
||||
debugger(when: kDebugMode);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// if [studentIds] is null, returns all students
|
||||
Future<List<StudentAnalyticsEvent?>> _getClassAnalytics([
|
||||
List<String>? studentIds,
|
||||
]) async {
|
||||
await postLoad();
|
||||
await requestParticipants();
|
||||
final List<Future<StudentAnalyticsEvent?>> sassFutures = [];
|
||||
final List<String> filteredIds = students
|
||||
.where(
|
||||
(element) => studentIds == null || studentIds.contains(element.id),
|
||||
)
|
||||
.map((e) => e.id)
|
||||
.toList();
|
||||
for (final id in filteredIds) {
|
||||
sassFutures.add(
|
||||
getStudentAnalytics(
|
||||
id,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Future.wait(sassFutures);
|
||||
}
|
||||
|
||||
/// if [isSpace]
|
||||
/// for all child chats, call _getChatAnalyticsGlobal and merge results
|
||||
/// else
|
||||
/// get analytics from pangea chat server
|
||||
/// do any needed conversion work
|
||||
/// save RoomAnalytics object to PangeaEventTypes.analyticsSummary event
|
||||
Future<Event?> _createStudentAnalyticsEvent() async {
|
||||
try {
|
||||
await postLoad();
|
||||
if (!pangeaCanSendEvent(PangeaEventTypes.studentAnalyticsSummary)) {
|
||||
ErrorHandler.logError(
|
||||
m: "null powerLevels in createStudentAnalytics",
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
if (client.userID == null) {
|
||||
debugger(when: kDebugMode);
|
||||
throw Exception("null userId in createStudentAnalytics");
|
||||
}
|
||||
|
||||
final String eventId = await client.setRoomStateWithKey(
|
||||
id,
|
||||
PangeaEventTypes.studentAnalyticsSummary,
|
||||
client.userID!,
|
||||
StudentAnalyticsSummary(
|
||||
// studentId: client.userID!,
|
||||
lastUpdated: DateTime.now(),
|
||||
messages: [],
|
||||
).toJson(),
|
||||
);
|
||||
final Event? event = await getEventById(eventId);
|
||||
|
||||
if (event == null) {
|
||||
debugger(when: kDebugMode);
|
||||
throw Exception(
|
||||
"null event after creation with eventId $eventId in createStudentAnalytics",
|
||||
);
|
||||
}
|
||||
return event;
|
||||
} catch (err, stack) {
|
||||
ErrorHandler.logError(e: err, s: stack, data: powerLevels);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// for each chat in class
|
||||
/// get timeline back to january 15
|
||||
/// get messages
|
||||
/// discard timeline
|
||||
/// save messages to StudentAnalyticsSummary
|
||||
Future<void> _updateMyLearningAnalyticsForClass([
|
||||
PLocalStore? storageService,
|
||||
]) async {
|
||||
try {
|
||||
final String migratedAnalyticsKey =
|
||||
"MIGRATED_ANALYTICS_KEY${id.localpart}";
|
||||
|
||||
if (storageService?.read(
|
||||
migratedAnalyticsKey,
|
||||
local: true,
|
||||
) ??
|
||||
false) return;
|
||||
|
||||
if (!isPangeaClass && !isExchange) {
|
||||
throw Exception(
|
||||
"In updateMyLearningAnalyticsForClass with room that is not not a class",
|
||||
);
|
||||
}
|
||||
|
||||
if (client.userID == null) {
|
||||
debugger(when: kDebugMode);
|
||||
return;
|
||||
}
|
||||
|
||||
final StudentAnalyticsEvent? myAnalEvent =
|
||||
await getStudentAnalytics(client.userID!);
|
||||
|
||||
if (myAnalEvent == null) {
|
||||
debugPrint("null analytcs event for $id");
|
||||
if (pangeaCanSendEvent(PangeaEventTypes.studentAnalyticsSummary)) {
|
||||
// debugger(when: kDebugMode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final updateMessages = await _messageListForAllChildChats;
|
||||
updateMessages.removeWhere(
|
||||
(element) => myAnalEvent.content.messages.any(
|
||||
(e) => e.eventId == element.eventId,
|
||||
),
|
||||
);
|
||||
myAnalEvent.bulkUpdate(updateMessages);
|
||||
|
||||
await storageService?.save(
|
||||
migratedAnalyticsKey,
|
||||
true,
|
||||
local: true,
|
||||
);
|
||||
} catch (err, s) {
|
||||
if (kDebugMode) rethrow;
|
||||
// debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
}
|
||||
}
|
||||
|
||||
// invite teachers of 1 space to 1 analytics room
|
||||
Future<void> _inviteSpaceTeachersToAnalyticsRoom(Room analyticsRoom) async {
|
||||
if (!isSpace) {
|
||||
debugPrint(
|
||||
"inviteSpaceTeachersToAnalyticsRoom called on non-space room",
|
||||
);
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message:
|
||||
"inviteSpaceTeachersToAnalyticsRoom called on non-space room",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!analyticsRoom.participantListComplete) {
|
||||
await analyticsRoom.requestParticipants();
|
||||
}
|
||||
final List<User> participants = analyticsRoom.getParticipants();
|
||||
for (final User teacher in (await teachers)) {
|
||||
if (!participants.any((p) => p.id == teacher.id)) {
|
||||
try {
|
||||
await analyticsRoom.invite(teacher.id);
|
||||
} catch (err, s) {
|
||||
debugPrint(
|
||||
"Failed to invite teacher ${teacher.id} to analytics room ${analyticsRoom.id}",
|
||||
);
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
m: "Failed to invite teacher ${teacher.id} to analytics room ${analyticsRoom.id}",
|
||||
s: s,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Invite all teachers to 1 analytics room
|
||||
// Handles case when students cannot add analytics room to space
|
||||
// So teacher is still able to get analytics data for this student
|
||||
Future<void> _inviteTeachersToAnalyticsRoom() async {
|
||||
if (client.userID == null) {
|
||||
debugPrint("inviteTeachersToAnalyticsRoom called with null userId");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "inviteTeachersToAnalyticsRoom called with null userId",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAnalyticsRoomOfUser(client.userID!)) {
|
||||
debugPrint("inviteTeachersToAnalyticsRoom called on non-analytics room");
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "inviteTeachersToAnalyticsRoom called on non-analytics room",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Room space in (await client.classesAndExchangesImStudyingIn)) {
|
||||
await space.inviteSpaceTeachersToAnalyticsRoom(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Invite teachers of 1 space to all users' analytics rooms
|
||||
Future<void> _inviteSpaceTeachersToAnalyticsRooms() async {
|
||||
for (final Room analyticsRoom in client.allMyAnalyticsRooms) {
|
||||
await inviteSpaceTeachersToAnalyticsRoom(analyticsRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension RoomInformationRoomExtension on Room {
|
||||
DateTime? get _creationTime =>
|
||||
getState(EventTypes.RoomCreate)?.originServerTs;
|
||||
|
||||
String? get _creatorId => getState(EventTypes.RoomCreate)?.senderId;
|
||||
|
||||
String get _domainString =>
|
||||
AppConfig.defaultHomeserver.replaceAll("matrix.", "");
|
||||
|
||||
bool _isChild(String roomId) =>
|
||||
isSpace && spaceChildren.any((room) => room.roomId == roomId);
|
||||
|
||||
bool _isFirstOrSecondChild(String roomId) {
|
||||
return isSpace &&
|
||||
(spaceChildren.any((room) => room.roomId == roomId) ||
|
||||
spaceChildren
|
||||
.where((sc) => sc.roomId != null)
|
||||
.map((sc) => client.getRoomById(sc.roomId!))
|
||||
.any(
|
||||
(room) =>
|
||||
room != null &&
|
||||
room.isSpace &&
|
||||
room.spaceChildren.any((room) => room.roomId == roomId),
|
||||
));
|
||||
}
|
||||
|
||||
bool get _isExchange =>
|
||||
isSpace &&
|
||||
languageSettingsStateEvent == null &&
|
||||
pangeaRoomRulesStateEvent != null;
|
||||
|
||||
bool get _isDirectChatWithoutMe =>
|
||||
isDirectChat && !getParticipants().any((e) => e.id == client.userID);
|
||||
|
||||
bool _isMadeForLang(String langCode) {
|
||||
final creationContent = getState(EventTypes.RoomCreate)?.content;
|
||||
return creationContent?.tryGet<String>(ModelKey.langCode) == langCode ||
|
||||
creationContent?.tryGet<String>(ModelKey.oldLangCode) == langCode;
|
||||
}
|
||||
|
||||
Future<bool> get _isBotRoom async {
|
||||
final List<User> participants = await requestParticipants();
|
||||
return participants.any(
|
||||
(User user) => user.id == BotName.byEnvironment,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> get _isBotDM async =>
|
||||
(await isBotRoom) && getParticipants().length == 2;
|
||||
|
||||
bool get _isLocked {
|
||||
if (isDirectChat) return false;
|
||||
if (!isSpace) {
|
||||
if (eventsDefaultPowerLevel == null) return false;
|
||||
return (eventsDefaultPowerLevel ?? 0) >=
|
||||
ClassDefaultValues.powerLevelOfAdmin;
|
||||
}
|
||||
int joinedRooms = 0;
|
||||
for (final child in spaceChildren) {
|
||||
if (child.roomId == null) continue;
|
||||
final Room? room = client.getRoomById(child.roomId!);
|
||||
if (room?.isLocked == false) {
|
||||
return false;
|
||||
}
|
||||
if (room != null) {
|
||||
joinedRooms += 1;
|
||||
}
|
||||
}
|
||||
return joinedRooms > 0 ? true : false;
|
||||
}
|
||||
|
||||
bool get _isPangeaClass => isSpace && languageSettingsStateEvent != null;
|
||||
|
||||
bool _isAnalyticsRoomOfUser(String userId) =>
|
||||
isAnalyticsRoom && isMadeByUser(userId);
|
||||
|
||||
bool get _isAnalyticsRoom =>
|
||||
getState(EventTypes.RoomCreate)?.content.tryGet<String>('type') ==
|
||||
PangeaRoomTypes.analytics;
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension RoomSettingsRoomExtension on Room {
|
||||
PangeaRoomRules? get _pangeaRoomRules {
|
||||
try {
|
||||
final Map<String, dynamic>? content = pangeaRoomRulesStateEvent?.content;
|
||||
if (content != null) {
|
||||
final PangeaRoomRules roomRules = PangeaRoomRules.fromJson(content);
|
||||
return roomRules;
|
||||
}
|
||||
return null;
|
||||
} catch (err, s) {
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "Error in pangeaRoomRules",
|
||||
data: {"room": toJson()},
|
||||
),
|
||||
);
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
PangeaRoomRules? get _firstRules =>
|
||||
pangeaRoomRules ??
|
||||
firstParentWithState(PangeaEventTypes.rules)?.pangeaRoomRules;
|
||||
|
||||
IconData? get _roomTypeIcon {
|
||||
if (membership == Membership.invite) return Icons.add;
|
||||
if (isPangeaClass) return Icons.school;
|
||||
if (isExchange) return Icons.connecting_airports;
|
||||
if (isAnalyticsRoom) return Icons.analytics;
|
||||
if (isDirectChat) return Icons.forum;
|
||||
return Icons.group;
|
||||
}
|
||||
|
||||
Text _nameAndRoomTypeIcon([TextStyle? textStyle]) => Text.rich(
|
||||
style: textStyle,
|
||||
TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: Icon(roomTypeIcon),
|
||||
),
|
||||
TextSpan(
|
||||
text: ' $name',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
BotOptionsModel? get _botOptions {
|
||||
if (isSpace) return null;
|
||||
return BotOptionsModel.fromJson(
|
||||
getState(PangeaEventTypes.botOptions)?.content ?? {},
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _isSuggested() async {
|
||||
final List<Room> spaceParents = client.rooms
|
||||
.where(
|
||||
(room) =>
|
||||
room.isSpace &&
|
||||
room.spaceChildren.any(
|
||||
(sc) => sc.roomId == id,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
for (final parent in spaceParents) {
|
||||
final suggested = await _isSuggestedInSpace(parent);
|
||||
if (!suggested) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> _setSuggested(bool suggested) async {
|
||||
final List<Room> spaceParents = client.rooms
|
||||
.where(
|
||||
(room) =>
|
||||
room.isSpace &&
|
||||
room.spaceChildren.any(
|
||||
(sc) => sc.roomId == id,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
for (final parent in spaceParents) {
|
||||
await _setSuggestedInSpace(suggested, parent);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _isSuggestedInSpace(Room space) async {
|
||||
try {
|
||||
final Map<String, dynamic> resp =
|
||||
await client.getRoomStateWithKey(space.id, EventTypes.spaceChild, id);
|
||||
return resp.containsKey('suggested') ? resp['suggested'] as bool : true;
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to fetch suggestion status of room $id in space ${space.id}",
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setSuggestedInSpace(bool suggest, Room space) async {
|
||||
try {
|
||||
await space.setSpaceChild(id, suggested: suggest);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to set suggestion status of room $id in space ${space.id}",
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension UserPermissionsRoomExtension on Room {
|
||||
bool _isMadeByUser(String userId) =>
|
||||
getState(EventTypes.RoomCreate)?.senderId == userId;
|
||||
|
||||
//if the user is an admin of the room or any immediate parent of the room
|
||||
//Question: check parents of parents?
|
||||
//check logic
|
||||
bool get _isSpaceAdmin {
|
||||
if (isSpace) return _isRoomAdmin;
|
||||
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
if (parent._isRoomAdmin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
for (final parent2 in parent.pangeaSpaceParents) {
|
||||
if (parent2._isRoomAdmin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _isUserRoomAdmin(String userId) => getParticipants().any(
|
||||
(e) =>
|
||||
e.id == userId &&
|
||||
e.powerLevel == ClassDefaultValues.powerLevelOfAdmin,
|
||||
);
|
||||
|
||||
bool _isUserSpaceAdmin(String userId) {
|
||||
if (isSpace) return isUserRoomAdmin(userId);
|
||||
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
if (parent.isUserRoomAdmin(userId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get _isRoomOwner =>
|
||||
getState(EventTypes.RoomCreate)?.senderId == client.userID;
|
||||
|
||||
bool get _isRoomAdmin =>
|
||||
ownPowerLevel == ClassDefaultValues.powerLevelOfAdmin;
|
||||
|
||||
bool get _showClassEditOptions => isSpace && isRoomAdmin;
|
||||
|
||||
bool get _canDelete => isSpaceAdmin;
|
||||
|
||||
bool _canIAddSpaceChild(Room? room) {
|
||||
if (!isSpace) {
|
||||
ErrorHandler.logError(
|
||||
m: "should not call canIAddSpaceChildren on non-space room",
|
||||
data: toJson(),
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (room != null && !room._isRoomAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (!pangeaCanSendEvent(EventTypes.spaceChild) && !_isRoomAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (room == null) {
|
||||
return isRoomAdmin || (pangeaRoomRules?.isCreateRooms ?? false);
|
||||
}
|
||||
if (room.isExchange) {
|
||||
return isRoomAdmin;
|
||||
}
|
||||
if (!room.isSpace) {
|
||||
return pangeaRoomRules?.isCreateRooms ?? false;
|
||||
}
|
||||
if (room.isPangeaClass) {
|
||||
ErrorHandler.logError(
|
||||
m: "should not call canIAddSpaceChild with class",
|
||||
data: room.toJson(),
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get _canIAddSpaceParents =>
|
||||
_isRoomAdmin || pangeaCanSendEvent(EventTypes.spaceParent);
|
||||
|
||||
//overriding the default canSendEvent to check power levels
|
||||
bool _pangeaCanSendEvent(String eventType) {
|
||||
final powerLevelsMap = getState(EventTypes.RoomPowerLevels)?.content;
|
||||
if (powerLevelsMap == null) return 0 <= ownPowerLevel;
|
||||
final pl = powerLevelsMap
|
||||
.tryGetMap<String, dynamic>('events')
|
||||
?.tryGet<int>(eventType) ??
|
||||
100;
|
||||
return ownPowerLevel >= pl;
|
||||
}
|
||||
|
||||
int? get _eventsDefaultPowerLevel => getState(EventTypes.RoomPowerLevels)
|
||||
?.content
|
||||
.tryGet<int>('events_default');
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import 'package:collection/collection.dart';
|
|||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/controllers/text_to_speech_controller.dart';
|
||||
import 'package:fluffychat/pangea/enum/audio_encoding_enum.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_representation_event.dart';
|
||||
import 'package:fluffychat/pangea/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
|
|
|
|||
|
|
@ -68,26 +68,33 @@ class ConstructUses {
|
|||
}
|
||||
|
||||
enum ConstructUseType {
|
||||
/// encountered match and accepted it
|
||||
/// produced in chat by user, igc was run, and we've judged it to be a correct use
|
||||
wa,
|
||||
|
||||
/// produced in chat by user, igc was run, and we've judged it to be a incorrect use
|
||||
/// Note: if the IGC match is ignored, this is not counted as an incorrect use
|
||||
ga,
|
||||
|
||||
/// used without assistance
|
||||
wa,
|
||||
/// produced in chat by user and igc was not run
|
||||
unk,
|
||||
|
||||
/// selected correctly in IT flow
|
||||
corIt,
|
||||
|
||||
/// encountered as it distractor and selected it
|
||||
incIt,
|
||||
|
||||
/// encountered as IT distractor and correctly ignored it
|
||||
ignIt,
|
||||
|
||||
/// encountered as it distractor and selected it
|
||||
incIt,
|
||||
|
||||
/// encountered in igc match and ignored match
|
||||
ignIGC,
|
||||
|
||||
/// encountered in igc match and ignored match
|
||||
/// selected correctly in IGC flow
|
||||
corIGC,
|
||||
|
||||
/// encountered as distractor in IGC flow and selected it
|
||||
incIGC,
|
||||
}
|
||||
|
||||
extension on ConstructUseType {
|
||||
|
|
@ -107,6 +114,10 @@ extension on ConstructUseType {
|
|||
return 'ignIGC';
|
||||
case ConstructUseType.corIGC:
|
||||
return 'corIGC';
|
||||
case ConstructUseType.incIGC:
|
||||
return 'incIGC';
|
||||
case ConstructUseType.unk:
|
||||
return 'unk';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,6 +137,10 @@ extension on ConstructUseType {
|
|||
return Icons.close;
|
||||
case ConstructUseType.corIGC:
|
||||
return Icons.check;
|
||||
case ConstructUseType.incIGC:
|
||||
return Icons.close;
|
||||
case ConstructUseType.unk:
|
||||
return Icons.help;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/models/constructs_analytics_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/models/constructs_analytics_model.dart';
|
||||
import '../enum/vocab_proficiency_enum.dart';
|
||||
|
||||
class VocabHeadwords {
|
||||
|
|
@ -176,6 +176,11 @@ class VocabTotals {
|
|||
case ConstructUseType.corIGC:
|
||||
corIt++;
|
||||
break;
|
||||
case ConstructUseType.incIGC:
|
||||
incIt++;
|
||||
break;
|
||||
case ConstructUseType.unk:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/constants/choreo_constants.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/extensions/my_list_extionsion.dart';
|
||||
import 'package:fluffychat/pangea/extensions/my_list_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/student_analytics_summary_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
|
@ -104,7 +104,6 @@ class AnalyticsListTileState extends State<AnalyticsListTile> {
|
|||
)
|
||||
: null,
|
||||
selected: widget.selected,
|
||||
enabled: widget.enabled,
|
||||
onTap: () {
|
||||
(room?.isSpace ?? false) && widget.allowNavigateOnSelect
|
||||
? context.go(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/base_analytics_view.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/student_analytics/student_analytics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../../widgets/matrix.dart';
|
||||
|
|
@ -101,18 +102,40 @@ class BaseAnalyticsController extends State<BaseAnalyticsPage> {
|
|||
}
|
||||
}
|
||||
|
||||
void toggleSelection(AnalyticsSelected selectedParam) {
|
||||
Future<void> toggleSelection(AnalyticsSelected selectedParam) async {
|
||||
final bool joinSelectedRoom =
|
||||
selectedParam.type == AnalyticsEntryType.room &&
|
||||
!enableSelection(
|
||||
selectedParam,
|
||||
);
|
||||
|
||||
if (joinSelectedRoom) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
final waitForRoom = Matrix.of(context).client.waitForRoomInSync(
|
||||
selectedParam.id,
|
||||
join: true,
|
||||
);
|
||||
await Matrix.of(context).client.joinRoom(selectedParam.id);
|
||||
await waitForRoom;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
debugPrint("selectedParam.id is ${selectedParam.id}");
|
||||
currentLemma = null;
|
||||
selected = isSelected(selectedParam.id) ? null : selectedParam;
|
||||
});
|
||||
|
||||
pangeaController.analytics.setConstructs(
|
||||
constructType: ConstructType.grammar,
|
||||
defaultSelected: widget.defaultSelected,
|
||||
selected: selected,
|
||||
removeIT: true,
|
||||
);
|
||||
|
||||
Future.delayed(Duration.zero, () => setState(() {}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ class BaseAnalyticsView extends StatelessWidget {
|
|||
) *
|
||||
72,
|
||||
child: TabBarView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import 'dart:developer';
|
|||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/chart_analytics_model.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/base_analytics.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/enum/time_span.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/class_list/class_list_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../../../widgets/matrix.dart';
|
||||
import '../../../constants/pangea_event_types.dart';
|
||||
import '../../../controllers/pangea_controller.dart';
|
||||
|
|
@ -42,7 +41,11 @@ class AnalyticsClassListController extends State<AnalyticsClassList> {
|
|||
if (!(refreshTimer[newState.room.id]?.isActive ?? false)) {
|
||||
refreshTimer[newState.room.id] = Timer(
|
||||
const Duration(seconds: 3),
|
||||
() => updateClassAnalytics(context, newState.room),
|
||||
() {
|
||||
if (newState.room.isSpace) {
|
||||
updateClassAnalytics(context, newState.room);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/analytics_list_tile.dart';
|
||||
import 'package:fluffychat/pangea/pages/analytics/time_span_menu_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import 'dart:async';
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/my_analytics_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/construct_analytics_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_representation_event.dart';
|
||||
import 'package:fluffychat/pangea/models/constructs_analytics_model.dart';
|
||||
|
|
@ -169,7 +169,7 @@ class ConstructListViewState extends State<ConstructListView> {
|
|||
|
||||
int get lemmaIndex =>
|
||||
constructs?.indexWhere(
|
||||
(element) => element.content.lemma == widget.controller.currentLemma,
|
||||
(element) => element.lemma == widget.controller.currentLemma,
|
||||
) ??
|
||||
-1;
|
||||
|
||||
|
|
@ -217,7 +217,7 @@ class ConstructListViewState extends State<ConstructListView> {
|
|||
|
||||
setState(() => fetchingUses = true);
|
||||
try {
|
||||
final List<OneConstructUse> uses = currentConstruct!.content.uses;
|
||||
final List<OneConstructUse> uses = currentConstruct!.uses;
|
||||
_msgEvents.clear();
|
||||
|
||||
for (final OneConstructUse use in uses) {
|
||||
|
|
@ -236,16 +236,24 @@ class ConstructListViewState extends State<ConstructListView> {
|
|||
ErrorHandler.logError(
|
||||
e: err,
|
||||
s: s,
|
||||
m: "Failed to fetch uses for current construct ${currentConstruct?.content.lemma}",
|
||||
m: "Failed to fetch uses for current construct ${currentConstruct?.lemma}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<ConstructEvent>? get constructs =>
|
||||
widget.pangeaController.analytics.constructs;
|
||||
List<AggregateConstructUses>? get constructs =>
|
||||
widget.pangeaController.analytics.constructs != null
|
||||
? widget.pangeaController.myAnalytics
|
||||
.aggregateConstructData(
|
||||
widget.pangeaController.analytics.constructs!,
|
||||
)
|
||||
.sorted(
|
||||
(a, b) => b.uses.length.compareTo(a.uses.length),
|
||||
)
|
||||
: null;
|
||||
|
||||
ConstructEvent? get currentConstruct => constructs?.firstWhereOrNull(
|
||||
(element) => element.content.lemma == widget.controller.currentLemma,
|
||||
AggregateConstructUses? get currentConstruct => constructs?.firstWhereOrNull(
|
||||
(element) => element.lemma == widget.controller.currentLemma,
|
||||
);
|
||||
|
||||
// given the current lemma and list of message events, return a list of
|
||||
|
|
@ -280,6 +288,13 @@ class ConstructListViewState extends State<ConstructListView> {
|
|||
return allMsgErrorSteps;
|
||||
}
|
||||
|
||||
Future<void> showConstructMessagesDialog() async {
|
||||
await showDialog<ConstructMessagesDialog>(
|
||||
context: context,
|
||||
builder: (c) => ConstructMessagesDialog(controller: this),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.init || fetchingUses) {
|
||||
|
|
@ -294,58 +309,92 @@ class ConstructListViewState extends State<ConstructListView> {
|
|||
);
|
||||
}
|
||||
|
||||
final msgEventMatches = getMessageEventMatches();
|
||||
|
||||
return widget.controller.currentLemma == null
|
||||
? Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: constructs!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
constructs![index].content.lemma,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${L10n.of(context)!.total} ${constructs![index].content.uses.length}',
|
||||
),
|
||||
onTap: () {
|
||||
final String lemma = constructs![index].content.lemma;
|
||||
widget.controller.setCurrentLemma(lemma);
|
||||
fetchUses();
|
||||
},
|
||||
);
|
||||
},
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: constructs!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
constructs![index].lemma,
|
||||
),
|
||||
)
|
||||
: Expanded(
|
||||
subtitle: Text(
|
||||
'${L10n.of(context)!.total} ${constructs![index].uses.length}',
|
||||
),
|
||||
onTap: () async {
|
||||
final String lemma = constructs![index].lemma;
|
||||
widget.controller.setCurrentLemma(lemma);
|
||||
fetchUses().then((_) => showConstructMessagesDialog());
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ConstructMessagesDialog extends StatelessWidget {
|
||||
final ConstructListViewState controller;
|
||||
const ConstructMessagesDialog({
|
||||
super.key,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (controller.widget.controller.currentLemma == null) {
|
||||
return const AlertDialog(content: CircularProgressIndicator.adaptive());
|
||||
}
|
||||
|
||||
final msgEventMatches = controller.getMessageEventMatches();
|
||||
|
||||
return AlertDialog(
|
||||
title: Center(child: Text(controller.widget.controller.currentLemma!)),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (controller.constructs![controller.lemmaIndex].uses.length >
|
||||
controller._msgEvents.length)
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(L10n.of(context)!.roomDataMissing),
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (constructs![lemmaIndex].content.uses.length >
|
||||
_msgEvents.length)
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(L10n.of(context)!.roomDataMissing),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (context, index) =>
|
||||
...msgEventMatches.mapIndexed(
|
||||
(index, event) => Column(
|
||||
children: [
|
||||
ConstructMessage(
|
||||
msgEvent: event.msgEvent,
|
||||
lemma: controller.widget.controller.currentLemma!,
|
||||
errorMessage: event.lemmaMatch,
|
||||
),
|
||||
if (index < msgEventMatches.length - 1)
|
||||
const Divider(height: 1),
|
||||
itemCount: msgEventMatches.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ConstructMessage(
|
||||
msgEvent: msgEventMatches[index].msgEvent,
|
||||
lemma: widget.controller.currentLemma!,
|
||||
errorMessage: msgEventMatches[index].lemmaMatch,
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
|
||||
child: Text(
|
||||
L10n.of(context)!.close.toUpperCase(),
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).textTheme.bodyMedium?.color?.withAlpha(150),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/chart_analytics_model.dart';
|
||||
import 'package:fluffychat/pangea/widgets/common/list_placeholder.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
@ -11,7 +11,7 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
import '../../../../widgets/matrix.dart';
|
||||
import '../../../controllers/pangea_controller.dart';
|
||||
import '../../../extensions/client_extension.dart';
|
||||
import '../../../extensions/client_extension/client_extension.dart';
|
||||
import '../../../utils/sync_status_util_v2.dart';
|
||||
import '../base_analytics.dart';
|
||||
import 'student_analytics_view.dart';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/visibility.dart' as visible;
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
|
||||
class ClassNameHeader extends StatelessWidget {
|
||||
final Room room;
|
||||
final ChatDetailsController controller;
|
||||
|
|
@ -24,14 +22,14 @@ class ClassNameHeader extends StatelessWidget {
|
|||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25),
|
||||
),
|
||||
label: visible.Visibility(
|
||||
icon: visible.Visibility(
|
||||
visible: controller.showEditNameIcon,
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
icon: room.nameAndRoomTypeIcon(
|
||||
label: room.nameAndRoomTypeIcon(
|
||||
TextStyle(
|
||||
fontSize: 20,
|
||||
color: Theme.of(context).textTheme.bodyLarge!.color,
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/constants/url_query_parameter_keys.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/constants/url_query_parameter_keys.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../../../utils/fluffy_share.dart';
|
||||
import '../../../../widgets/avatar.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import 'package:matrix/matrix.dart';
|
|||
import '../../../../config/app_config.dart';
|
||||
import '../../../../widgets/matrix.dart';
|
||||
import '../../../constants/pangea_event_types.dart';
|
||||
import '../../../extensions/pangea_room_extension.dart';
|
||||
import '../../../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
|
||||
class RoomRulesEditor extends StatefulWidget {
|
||||
final String? roomId;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'dart:developer';
|
|||
|
||||
import 'package:fluffychat/pangea/constants/age_limits.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/p_user_age/p_user_age_view.dart';
|
||||
import 'package:fluffychat/pangea/utils/p_extension.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -75,11 +75,6 @@ void chatListHandleSpaceTap(
|
|||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
if (space.isExchange) {
|
||||
context.go(
|
||||
'/rooms/join_exchange/${controller.activeSpaceId}',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import '../constants/class_default_values.dart';
|
||||
import '../extensions/pangea_room_extension.dart';
|
||||
import '../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
|
||||
class ClassChatPowerLevels {
|
||||
static Future<Map<String, dynamic>> powerLevelOverrideForClassChat(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ void setClassDisplayname(BuildContext context, String? roomId) async {
|
|||
: L10n.of(context)!.changeTheNameOfTheChat,
|
||||
),
|
||||
content: TextField(
|
||||
maxLength: 32,
|
||||
maxLength: 64,
|
||||
controller: textFieldController,
|
||||
),
|
||||
actions: [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -18,6 +17,10 @@ void setClassTopic(Room room, BuildContext context) {
|
|||
),
|
||||
content: TextField(
|
||||
controller: textFieldController,
|
||||
keyboardType: TextInputType.multiline,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
maxLength: 2000,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
|
|
|||
|
|
@ -188,10 +188,13 @@ class MessageToolbarState extends State<MessageToolbar> {
|
|||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
currentMode = newMode;
|
||||
updatingMode = true;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
currentMode = newMode;
|
||||
updatingMode = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (!subscribed) {
|
||||
toolbarContent = MessageUnsubscribedCard(
|
||||
languageTool: newMode.title(context),
|
||||
|
|
@ -221,9 +224,11 @@ class MessageToolbarState extends State<MessageToolbar> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
updatingMode = false;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
updatingMode = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void showTranslation() {
|
||||
|
|
@ -289,7 +294,7 @@ class MessageToolbarState extends State<MessageToolbar> {
|
|||
final bool autoplay = MatrixState.pangeaController.pStoreService.read(
|
||||
PLocalKey.autoPlayMessages,
|
||||
) ??
|
||||
true;
|
||||
false;
|
||||
|
||||
if (widget.pangeaMessageEvent.isAudioMessage) {
|
||||
updateMode(MessageMode.speechToText);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,9 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
l2Code = MatrixState.pangeaController.languageController.activeL2Code(
|
||||
roomID: widget.messageEvent.room.id,
|
||||
);
|
||||
setState(() {});
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
loadTranslation(() async {
|
||||
if (widget.selection.selectedText != null) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import '../../../pages/chat_list/chat_list.dart';
|
||||
import '../../../widgets/matrix.dart';
|
||||
import '../../extensions/pangea_room_extension.dart';
|
||||
import '../../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
|
||||
class ChatListBodyStartText extends StatelessWidget {
|
||||
const ChatListBodyStartText({
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -33,9 +33,10 @@ class AddToSpaceToggles extends StatefulWidget {
|
|||
|
||||
class AddToSpaceState extends State<AddToSpaceToggles> {
|
||||
late Room? room;
|
||||
late List<SuggestionStatus> parents;
|
||||
late List<Room> parents;
|
||||
late List<Room> possibleParents;
|
||||
late bool isOpen;
|
||||
late bool isSuggested;
|
||||
|
||||
AddToSpaceState({Key? key});
|
||||
|
||||
|
|
@ -46,6 +47,9 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
? Matrix.of(context).client.getRoomById(widget.roomId!)
|
||||
: null;
|
||||
|
||||
isSuggested = true;
|
||||
room?.isSuggested().then((value) => isSuggested = value);
|
||||
|
||||
possibleParents = Matrix.of(context)
|
||||
.client
|
||||
.rooms
|
||||
|
|
@ -63,8 +67,6 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
(r) =>
|
||||
r.spaceChildren.any((room) => room.roomId == widget.roomId),
|
||||
)
|
||||
.map((r) => SuggestionStatus(false, r))
|
||||
.cast<SuggestionStatus>()
|
||||
.toList()
|
||||
: [];
|
||||
|
||||
|
|
@ -72,7 +74,7 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
final activeSpace =
|
||||
Matrix.of(context).client.getRoomById(widget.activeSpaceId!);
|
||||
if (activeSpace != null && activeSpace.canIAddSpaceChild(null)) {
|
||||
parents.add(SuggestionStatus(true, activeSpace));
|
||||
parents.add(activeSpace);
|
||||
} else {
|
||||
ErrorHandler.logError(
|
||||
e: Exception('activeSpaceId ${widget.activeSpaceId} not found'),
|
||||
|
|
@ -84,10 +86,9 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
//if possibleParent in parents, put first
|
||||
//use sort but use any instead of contains because contains uses == and we want to compare by id
|
||||
possibleParents.sort((a, b) {
|
||||
if (parents.any((suggestionStatus) => suggestionStatus.room.id == a.id)) {
|
||||
if (parents.any((parent) => parent.id == a.id)) {
|
||||
return -1;
|
||||
} else if (parents
|
||||
.any((suggestionStatus) => suggestionStatus.room.id == b.id)) {
|
||||
} else if (parents.any((parent) => parent.id == b.id)) {
|
||||
return 1;
|
||||
} else {
|
||||
return a.name.compareTo(b.name);
|
||||
|
|
@ -95,35 +96,21 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
});
|
||||
|
||||
isOpen = widget.startOpen;
|
||||
initSuggestedParents();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> initSuggestedParents() async {
|
||||
if (room != null) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
final parent = parents[i];
|
||||
final bool suggested =
|
||||
await room?.suggestedInSpace(parent.room) ?? false;
|
||||
parents[i].suggested = suggested;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _addSingleSpace(String roomToAddId, Room newParent) async {
|
||||
GoogleAnalytics.addParent(roomToAddId, newParent.classCode);
|
||||
await newParent.setSpaceChild(
|
||||
roomToAddId,
|
||||
suggested: isSuggestedInSpace(newParent),
|
||||
suggested: isSuggested,
|
||||
);
|
||||
await setSuggested(true, newParent);
|
||||
}
|
||||
|
||||
Future<void> addSpaces(String roomToAddId) async {
|
||||
final List<Future<void>> addFutures = [];
|
||||
for (final SuggestionStatus newParent in parents) {
|
||||
addFutures.add(_addSingleSpace(roomToAddId, newParent.room));
|
||||
for (final Room parent in parents) {
|
||||
addFutures.add(_addSingleSpace(roomToAddId, parent));
|
||||
}
|
||||
await addFutures.wait;
|
||||
}
|
||||
|
|
@ -148,39 +135,18 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
|
||||
setState(
|
||||
() => add
|
||||
? parents.add(SuggestionStatus(true, possibleParent))
|
||||
? parents.add(possibleParent)
|
||||
: parents.removeWhere(
|
||||
(suggestionStatus) =>
|
||||
suggestionStatus.room.id == possibleParent.id,
|
||||
(parent) => parent.id == possibleParent.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setSuggested(bool suggest, Room possibleParent) async {
|
||||
if (room != null) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room!.setSuggestedInSpace(suggest, possibleParent),
|
||||
);
|
||||
}
|
||||
|
||||
for (final SuggestionStatus suggestionStatus in parents) {
|
||||
if (suggestionStatus.room.id == possibleParent.id) {
|
||||
suggestionStatus.suggested = suggest;
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
bool isSuggestedInSpace(Room parent) =>
|
||||
parents.firstWhereOrNull((r) => r.room.id == parent.id)?.suggested ??
|
||||
false;
|
||||
|
||||
Widget getAddToSpaceToggleItem(int index) {
|
||||
final Room possibleParent = possibleParents[index];
|
||||
final String possibleParentName = possibleParent.getLocalizedDisplayname();
|
||||
final bool canAdd = possibleParent.canIAddSpaceChild(room);
|
||||
final bool canAdd = !(!possibleParent.isRoomAdmin &&
|
||||
widget.mode == AddToClassMode.exchange) &&
|
||||
possibleParent.canIAddSpaceChild(room);
|
||||
|
||||
return Opacity(
|
||||
opacity: canAdd ? 1 : 0.5,
|
||||
|
|
@ -189,7 +155,7 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
SwitchListTile.adaptive(
|
||||
title: possibleParent.nameAndRoomTypeIcon(),
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
value: parents.any((r) => r.room.id == possibleParent.id),
|
||||
value: parents.any((r) => r.id == possibleParent.id),
|
||||
onChanged: (bool add) => canAdd
|
||||
? handleAdd(add, possibleParent)
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
|
@ -198,53 +164,6 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
),
|
||||
),
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
child: parents.any((r) => r.room.id == possibleParent.id)
|
||||
? SwitchListTile.adaptive(
|
||||
title: Row(
|
||||
children: [
|
||||
const SizedBox(width: 32),
|
||||
Expanded(
|
||||
child: Text(
|
||||
L10n.of(context)!.suggestTo(possibleParentName),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Row(
|
||||
children: [
|
||||
const SizedBox(width: 32),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.mode == AddToClassMode.chat
|
||||
? L10n.of(context)!
|
||||
.suggestChatDesc(possibleParentName)
|
||||
: L10n.of(context)!.suggestExchangeDesc(
|
||||
possibleParentName,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
value: isSuggestedInSpace(possibleParent),
|
||||
onChanged: (bool suggest) => canAdd
|
||||
? setSuggested(suggest, possibleParent)
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.noPermission),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
),
|
||||
Divider(
|
||||
height: 0.5,
|
||||
color: Theme.of(context).colorScheme.secondary.withAlpha(25),
|
||||
|
|
@ -254,6 +173,16 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> setSuggested(bool suggested) async {
|
||||
setState(() => isSuggested = suggested);
|
||||
if (room != null) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async => await room?.setSuggested(suggested),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String title = widget.mode == AddToClassMode.exchange
|
||||
|
|
@ -292,9 +221,28 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
const Divider(height: 1),
|
||||
possibleParents.isNotEmpty
|
||||
? Column(
|
||||
children: possibleParents
|
||||
.mapIndexed((index, _) => getAddToSpaceToggleItem(index))
|
||||
.toList(),
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
title: Text(L10n.of(context)!.suggestToChat),
|
||||
secondary: Icon(
|
||||
isSuggested
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
subtitle: Text(L10n.of(context)!.suggestToChatDesc),
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
value: isSuggested,
|
||||
onChanged: (bool add) => setSuggested(add),
|
||||
),
|
||||
Divider(
|
||||
height: 0.5,
|
||||
color:
|
||||
Theme.of(context).colorScheme.secondary.withAlpha(25),
|
||||
),
|
||||
...possibleParents.mapIndexed(
|
||||
(index, _) => getAddToSpaceToggleItem(index),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Center(
|
||||
child: Padding(
|
||||
|
|
@ -312,10 +260,3 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SuggestionStatus {
|
||||
bool suggested;
|
||||
final Room room;
|
||||
|
||||
SuggestionStatus(this.suggested, this.room);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
import '../../../widgets/matrix.dart';
|
||||
import '../../constants/pangea_event_types.dart';
|
||||
import '../../extensions/pangea_room_extension.dart';
|
||||
import '../../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import '../../utils/error_handler.dart';
|
||||
|
||||
class ConversationBotSettings extends StatefulWidget {
|
||||
|
|
|
|||
|
|
@ -61,9 +61,11 @@ class PangeaRichTextState extends State<PangeaRichText> {
|
|||
widget.toolbarController?.toolbar?.textSelection.setMessageText(
|
||||
newTextSpan,
|
||||
);
|
||||
setState(() {
|
||||
textSpan = newTextSpan;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
textSpan = newTextSpan;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void setTextSpan() {
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ class WordMatchContent extends StatelessWidget {
|
|||
(e) => Choice(
|
||||
text: e.value,
|
||||
color: e.selected ? e.type.color : null,
|
||||
isGold: e.type.name == 'bestCorrection',
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import '../../constants/language_keys.dart';
|
|||
import '../../constants/pangea_event_types.dart';
|
||||
import '../../controllers/language_list_controller.dart';
|
||||
import '../../controllers/pangea_controller.dart';
|
||||
import '../../extensions/pangea_room_extension.dart';
|
||||
import '../../extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import '../../models/language_model.dart';
|
||||
import '../../utils/error_handler.dart';
|
||||
import '../user_settings/p_language_dropdown.dart';
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/download_chat.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue