Merge pull request #771 from pangeachat/copy-and-space-error-updates

update copy when creating new chat/subspace from space view, show joi…
pull/1423/head
ggurdin 1 year ago committed by GitHub
commit 925d7506ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2812,7 +2812,7 @@
"type": "text", "type": "text",
"placeholders": {} "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": { "@unableToFindClass": {
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}

@ -4244,7 +4244,7 @@
"joinWithClassCode": "Únete a una clase o a un intercambio", "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.", "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", "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 🙂", "welcomeToYourNewClass": "Bienvenido 🙂",
"welcomeToClass": "Bienvenido! 🙂\n- ¡Prueba a unirte a un chat!\n- ¡Diviértete chateando!", "welcomeToClass": "Bienvenido! 🙂\n- ¡Prueba a unirte a un chat!\n- ¡Diviértete chateando!",
"unableToFindClassCode": "No se puede encontrar el código.", "unableToFindClassCode": "No se puede encontrar el código.",

@ -315,7 +315,10 @@ class _SpaceViewState extends State<SpaceView> {
actions: [ actions: [
AlertDialogAction( AlertDialogAction(
key: AddRoomType.subspace, key: AddRoomType.subspace,
label: L10n.of(context)!.createNewSpace, // #Pangea
// label: L10n.of(context)!.createNewSpace,
label: L10n.of(context)!.newChat,
// Pangea#
), ),
AlertDialogAction( AlertDialogAction(
key: AddRoomType.chat, key: AddRoomType.chat,

@ -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/models/space_model.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/firebase_analytics.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:fluffychat/widgets/matrix.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -63,110 +62,121 @@ class ClassController extends BaseController {
Future<void> joinClasswithCode(BuildContext context, String classCode) async { Future<void> joinClasswithCode(BuildContext context, String classCode) async {
final client = Matrix.of(context).client; final client = Matrix.of(context).client;
try { await showFutureLoadingDialog(
final knockResponse = await client.httpClient.post( context: context,
Uri.parse( future: () async {
'${client.homeserver}/_synapse/client/pangea/v1/knock_with_code', final knockResponse = await client.httpClient.post(
), Uri.parse(
headers: { '${client.homeserver}/_synapse/client/pangea/v1/knock_with_code',
'Content-Type': 'application/json', ),
'Authorization': 'Bearer ${client.accessToken}', headers: {
}, 'Content-Type': 'application/json',
body: jsonEncode({'access_code': classCode}), 'Authorization': 'Bearer ${client.accessToken}',
); },
if (knockResponse.statusCode == 429) { body: jsonEncode({'access_code': classCode}),
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<String>.from(knockResult['rooms']);
final alreadyJoined = List<String>.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 client.joinRoomById(chosenClassId); if (knockResponse.statusCode == 429) {
_pangeaController.pStoreService.delete(PLocalKey.justInputtedCode); await showFutureLoadingDialog(
} context: context,
future: () async {
if (_pangeaController.matrixState.client.getRoomById(chosenClassId) == throw L10n.of(context)!.tooManyRequest;
null) { },
await _pangeaController.matrixState.client.waitForRoomInSync( );
chosenClassId, return;
join: true, }
if (knockResponse.statusCode != 200) {
await showFutureLoadingDialog(
context: context,
future: () async {
throw L10n.of(context)!.unableToFindClass;
},
);
return;
}
final knockResult = jsonDecode(knockResponse.body);
final foundClasses = List<String>.from(knockResult['rooms']);
final alreadyJoined = List<String>.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 setActiveSpaceIdInChatListController(chosenClassId);
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);
// add the user's analytics room to this joined space // add the user's analytics room to this joined space
// so their teachers can join them via the space hierarchy // so their teachers can join them via the space hierarchy
final Room? joinedSpace = final Room? joinedSpace =
_pangeaController.matrixState.client.getRoomById(chosenClassId); _pangeaController.matrixState.client.getRoomById(chosenClassId);
// when possible, add user's analytics room the to space they joined // when possible, add user's analytics room the to space they joined
joinedSpace?.addAnalyticsRoomsToSpace(); joinedSpace?.addAnalyticsRoomsToSpace();
// and invite the space's teachers to the user's analytics rooms // and invite the space's teachers to the user's analytics rooms
joinedSpace?.inviteSpaceTeachersToAnalyticsRooms(); joinedSpace?.inviteSpaceTeachersToAnalyticsRooms();
GoogleAnalytics.joinClass(classCode); GoogleAnalytics.joinClass(classCode);
return; return;
} catch (err) { },
SpaceCodeUtil.messageSnack( );
context,
ErrorCopy(context, err).body,
);
}
// P-EPIC // P-EPIC
// prereq - server needs ability to invite to private room. how? // prereq - server needs ability to invite to private room. how?
// does server api have ability with admin token? // does server api have ability with admin token?

@ -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,
),
);
}
} }

Loading…
Cancel
Save