add rate limit, add already joined

This commit is contained in:
WilsonLe 2024-10-15 17:47:18 +11:00
parent f780f450ee
commit d2f1340f75
3 changed files with 17 additions and 0 deletions

View file

@ -4086,6 +4086,7 @@
}
},
"roomCapacityExplanation": "{roomType} capacity limits the number of non-admins allowed in a room.",
"tooManyRequest": "Too many request, please try again later.",
"@roomCapacityExplanation": {
"type": "text",
"placeholders": {

View file

@ -78,6 +78,13 @@ class ClassController extends BaseController {
},
body: jsonEncode({'access_code': classCode}),
);
if (knockResponse.statusCode == 429) {
SpaceCodeUtil.messageSnack(
context,
L10n.of(context)!.tooManyRequest,
);
return;
}
if (knockResponse.statusCode != 200) {
SpaceCodeUtil.messageSnack(
context,
@ -87,6 +94,14 @@ class ClassController extends BaseController {
}
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,

View file

@ -79,6 +79,7 @@ class SpaceCodeUtil {
SnackBar(
duration: const Duration(seconds: 10),
content: Text(message),
showCloseIcon: true,
),
);
}