update copy when creating new chat/subspace from space view, show join space error in middle of screen instead of snackbar
This commit is contained in:
parent
7aa69b3aa4
commit
9f17cf5dc1
5 changed files with 117 additions and 114 deletions
|
|
@ -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": {}
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -315,7 +315,10 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -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<void> 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,
|
||||
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}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (knockResponse.statusCode != 200) {
|
||||
SpaceCodeUtil.messageSnack(
|
||||
context,
|
||||
L10n.of(context)!.unableToFindClass,
|
||||
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<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;
|
||||
}
|
||||
},
|
||||
);
|
||||
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)) {
|
||||
if (joinResult.error != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setActiveSpaceIdInChatListController(chosenClassId);
|
||||
SpaceCodeUtil.messageSnack(context, L10n.of(context)!.alreadyInClass);
|
||||
|
||||
// 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();
|
||||
|
||||
// and invite the space's teachers to the user's analytics rooms
|
||||
joinedSpace?.inviteSpaceTeachersToAnalyticsRooms();
|
||||
GoogleAnalytics.joinClass(classCode);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
// P-EPIC
|
||||
// prereq - server needs ability to invite to private room. how?
|
||||
// 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…
Add table
Reference in a new issue