From 9f17cf5dc107b1864ee74fb9f03626ff4bf00060 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 21 Oct 2024 09:49:34 -0400 Subject: [PATCH] update copy when creating new chat/subspace from space view, show join space error in middle of screen instead of snackbar --- assets/l10n/intl_en.arb | 2 +- assets/l10n/intl_es.arb | 2 +- lib/pages/chat_list/space_view.dart | 5 +- lib/pangea/controllers/class_controller.dart | 208 ++++++++++--------- lib/pangea/utils/space_code.dart | 10 - 5 files changed, 115 insertions(+), 112 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index a87697a15..83de9e423 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2812,7 +2812,7 @@ "type": "text", "placeholders": {} }, - "unableToFindClass": "We are unable to find the space. Please double-check the information with the space administrator. If you are still experiencing an issue, please contact support@pangea.chat.", + "unableToFindClass": "There's no space with that code. Please try again.", "@unableToFindClass": { "type": "text", "placeholders": {} diff --git a/assets/l10n/intl_es.arb b/assets/l10n/intl_es.arb index 49421500b..dd8312d8f 100644 --- a/assets/l10n/intl_es.arb +++ b/assets/l10n/intl_es.arb @@ -4244,7 +4244,7 @@ "joinWithClassCode": "Únete a una clase o a un intercambio", "joinWithClassCodeDesc": "Conéctese a una clase o espacio de intercambio con el código de invitación de 6 dígitos proporcionado por el administrador del espacio.", "joinWithClassCodeHint": "Introduzca el código de invitación", - "unableToFindClass": "No podemos encontrar la clase o el intercambio. Por favor, vuelva a comprobar la información con el administrador del espacio. Si sigue teniendo problemas, póngase en contacto con support@pangea.chat.", + "unableToFindClass": "No hay espacio con ese código. Por favor inténtalo de nuevo.", "welcomeToYourNewClass": "Bienvenido 🙂", "welcomeToClass": "Bienvenido! 🙂\n- ¡Prueba a unirte a un chat!\n- ¡Diviértete chateando!", "unableToFindClassCode": "No se puede encontrar el código.", diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 12d38b1fc..a45d28f43 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -315,7 +315,10 @@ class _SpaceViewState extends State { actions: [ AlertDialogAction( key: AddRoomType.subspace, - label: L10n.of(context)!.createNewSpace, + // #Pangea + // label: L10n.of(context)!.createNewSpace, + label: L10n.of(context)!.newChat, + // Pangea# ), AlertDialogAction( key: AddRoomType.chat, diff --git a/lib/pangea/controllers/class_controller.dart b/lib/pangea/controllers/class_controller.dart index 186cac389..0e51e700c 100644 --- a/lib/pangea/controllers/class_controller.dart +++ b/lib/pangea/controllers/class_controller.dart @@ -10,7 +10,6 @@ import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_e import 'package:fluffychat/pangea/models/space_model.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; -import 'package:fluffychat/pangea/utils/space_code.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -63,110 +62,121 @@ class ClassController extends BaseController { Future joinClasswithCode(BuildContext context, String classCode) async { final client = Matrix.of(context).client; - try { - final knockResponse = await client.httpClient.post( - Uri.parse( - '${client.homeserver}/_synapse/client/pangea/v1/knock_with_code', - ), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ${client.accessToken}', - }, - body: jsonEncode({'access_code': classCode}), - ); - if (knockResponse.statusCode == 429) { - SpaceCodeUtil.messageSnack( - context, - L10n.of(context)!.tooManyRequest, - ); - return; - } - if (knockResponse.statusCode != 200) { - SpaceCodeUtil.messageSnack( - context, - L10n.of(context)!.unableToFindClass, - ); - return; - } - final knockResult = jsonDecode(knockResponse.body); - final foundClasses = List.from(knockResult['rooms']); - final alreadyJoined = List.from(knockResult['already_joined']); - if (alreadyJoined.isNotEmpty) { - SpaceCodeUtil.messageSnack( - context, - L10n.of(context)!.alreadyInClass, - ); - return; - } - if (foundClasses.isEmpty) { - SpaceCodeUtil.messageSnack( - context, - L10n.of(context)!.unableToFindClass, - ); - return; - } - final chosenClassId = foundClasses.first; - if (_pangeaController.matrixState.client.rooms - .any((room) => room.id == chosenClassId)) { - setActiveSpaceIdInChatListController(chosenClassId); - SpaceCodeUtil.messageSnack(context, L10n.of(context)!.alreadyInClass); - return; - } else { - await _pangeaController.pStoreService.save( - PLocalKey.justInputtedCode, - classCode, - isAccountData: false, + await showFutureLoadingDialog( + context: context, + future: () async { + final knockResponse = await client.httpClient.post( + Uri.parse( + '${client.homeserver}/_synapse/client/pangea/v1/knock_with_code', + ), + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ${client.accessToken}', + }, + body: jsonEncode({'access_code': classCode}), ); - await client.joinRoomById(chosenClassId); - _pangeaController.pStoreService.delete(PLocalKey.justInputtedCode); - } - - if (_pangeaController.matrixState.client.getRoomById(chosenClassId) == - null) { - await _pangeaController.matrixState.client.waitForRoomInSync( - chosenClassId, - join: true, + if (knockResponse.statusCode == 429) { + await showFutureLoadingDialog( + context: context, + future: () async { + throw L10n.of(context)!.tooManyRequest; + }, + ); + return; + } + if (knockResponse.statusCode != 200) { + await showFutureLoadingDialog( + context: context, + future: () async { + throw L10n.of(context)!.unableToFindClass; + }, + ); + return; + } + final knockResult = jsonDecode(knockResponse.body); + final foundClasses = List.from(knockResult['rooms']); + final alreadyJoined = List.from(knockResult['already_joined']); + if (alreadyJoined.isNotEmpty) { + await showFutureLoadingDialog( + context: context, + future: () async { + throw L10n.of(context)!.alreadyInClass; + }, + ); + return; + } + if (foundClasses.isEmpty) { + await showFutureLoadingDialog( + context: context, + future: () async { + throw L10n.of(context)!.unableToFindClass; + }, + ); + return; + } + final chosenClassId = foundClasses.first; + if (_pangeaController.matrixState.client.rooms + .any((room) => room.id == chosenClassId)) { + setActiveSpaceIdInChatListController(chosenClassId); + await showFutureLoadingDialog( + context: context, + future: () async { + throw L10n.of(context)!.alreadyInClass; + }, + ); + return; + } else { + await _pangeaController.pStoreService.save( + PLocalKey.justInputtedCode, + classCode, + isAccountData: false, + ); + await client.joinRoomById(chosenClassId); + _pangeaController.pStoreService.delete(PLocalKey.justInputtedCode); + } + + if (_pangeaController.matrixState.client.getRoomById(chosenClassId) == + null) { + await _pangeaController.matrixState.client.waitForRoomInSync( + chosenClassId, + join: true, + ); + } + + // If the room is full, leave + final room = + _pangeaController.matrixState.client.getRoomById(chosenClassId); + if (room == null) { + return; + } + final joinResult = await showFutureLoadingDialog( + context: context, + future: () async { + if (await room.leaveIfFull()) { + throw L10n.of(context)!.roomFull; + } + }, ); - } + if (joinResult.error != null) { + return; + } - // If the room is full, leave - final room = - _pangeaController.matrixState.client.getRoomById(chosenClassId); - if (room == null) { - return; - } - final joinResult = await showFutureLoadingDialog( - context: context, - future: () async { - if (await room.leaveIfFull()) { - throw L10n.of(context)!.roomFull; - } - }, - ); - if (joinResult.error != null) { - return; - } - - setActiveSpaceIdInChatListController(chosenClassId); + setActiveSpaceIdInChatListController(chosenClassId); - // add the user's analytics room to this joined space - // so their teachers can join them via the space hierarchy - final Room? joinedSpace = - _pangeaController.matrixState.client.getRoomById(chosenClassId); + // add the user's analytics room to this joined space + // so their teachers can join them via the space hierarchy + final Room? joinedSpace = + _pangeaController.matrixState.client.getRoomById(chosenClassId); - // when possible, add user's analytics room the to space they joined - joinedSpace?.addAnalyticsRoomsToSpace(); + // when possible, add user's analytics room the to space they joined + joinedSpace?.addAnalyticsRoomsToSpace(); - // and invite the space's teachers to the user's analytics rooms - joinedSpace?.inviteSpaceTeachersToAnalyticsRooms(); - GoogleAnalytics.joinClass(classCode); - return; - } catch (err) { - SpaceCodeUtil.messageSnack( - context, - ErrorCopy(context, err).body, - ); - } + // and invite the space's teachers to the user's analytics rooms + joinedSpace?.inviteSpaceTeachersToAnalyticsRooms(); + GoogleAnalytics.joinClass(classCode); + return; + }, + ); // P-EPIC // prereq - server needs ability to invite to private room. how? // does server api have ability with admin token? diff --git a/lib/pangea/utils/space_code.dart b/lib/pangea/utils/space_code.dart index 957e04ca8..99dd189de 100644 --- a/lib/pangea/utils/space_code.dart +++ b/lib/pangea/utils/space_code.dart @@ -73,14 +73,4 @@ class SpaceCodeUtil { ], ), ); - - static void messageSnack(BuildContext context, String message) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 10), - content: Text(message), - showCloseIcon: true, - ), - ); - } }