* removed unreferences functions

* better error logging for null lang_code String in PracticeActivityModel.fromJson

* updated to dialogs while joining space with code
pull/1544/head
ggurdin 12 months ago committed by GitHub
parent 472f924304
commit 852bdfb534
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -575,7 +575,9 @@ class ChatListController extends State<ChatList>
classStream = MatrixState.pangeaController.classController.stateStream
.listen((event) {
if (mounted) {
setActiveSpace(event["activeSpaceId"]);
event["activeSpaceId"] != null
? setActiveSpace(event["activeSpaceId"])
: clearActiveSpace();
if (event["activeSpaceId"] != null) {
context.go("/rooms/${event["activeSpaceId"]}/details");
}

@ -15,6 +15,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'base_controller.dart';
@ -63,7 +64,7 @@ class ClassController extends BaseController {
Future<void> joinClasswithCode(BuildContext context, String classCode) async {
final client = Matrix.of(context).client;
await showFutureLoadingDialog(
final space = await showFutureLoadingDialog<Room?>(
context: context,
future: () async {
final knockResponse = await client.httpClient.post(
@ -76,108 +77,79 @@ class ClassController extends BaseController {
},
body: jsonEncode({'access_code': classCode}),
);
if (knockResponse.statusCode == 429) {
await showFutureLoadingDialog(
context: context,
future: () async {
throw L10n.of(context)!.tooManyRequest;
},
);
return;
throw L10n.of(context)!.tooManyRequest;
}
if (knockResponse.statusCode != 200) {
await showFutureLoadingDialog(
context: context,
future: () async {
throw L10n.of(context)!.unableToFindClass;
},
);
return;
throw L10n.of(context)!.unableToFindClass;
}
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;
final bool inFoundClass = foundClasses.isNotEmpty &&
_pangeaController.matrixState.client.rooms.any(
(room) => room.id == foundClasses.first,
);
if (alreadyJoined.isNotEmpty || inFoundClass) {
context.go("/rooms/${alreadyJoined.first}/details");
throw L10n.of(context)!.alreadyInClass;
}
if (foundClasses.isEmpty) {
await showFutureLoadingDialog(
context: context,
future: () async {
throw L10n.of(context)!.unableToFindClass;
},
);
return;
throw L10n.of(context)!.unableToFindClass;
}
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);
}
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) {
Room? room = client.getRoomById(chosenClassId);
if (room == null) {
await _pangeaController.matrixState.client.waitForRoomInSync(
chosenClassId,
join: true,
);
room = client.getRoomById(chosenClassId);
if (room == null) return null;
}
return room;
},
);
if (space.isError || space.result == null) return;
final room = space.result!;
await room.join();
final isFull = await room.leaveIfFull();
if (isFull) {
await showFutureLoadingDialog(
context: context,
future: () async => throw L10n.of(context)!.roomFull,
);
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);
// when possible, add user's analytics room the to space they joined
room.addAnalyticsRoomsToSpace();
// 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);
// and invite the space's teachers to the user's analytics rooms
room.inviteSpaceTeachersToAnalyticsRooms();
GoogleAnalytics.joinClass(classCode);
// when possible, add user's analytics room the to space they joined
joinedSpace?.addAnalyticsRoomsToSpace();
if (room.client.getRoomById(room.id)?.membership != Membership.join) {
await room.client.waitForRoomInSync(room.id, join: true);
}
// and invite the space's teachers to the user's analytics rooms
joinedSpace?.inviteSpaceTeachersToAnalyticsRooms();
GoogleAnalytics.joinClass(classCode);
return;
},
);
context.go("/rooms/${room.id}/details");
return;
// P-EPIC
// prereq - server needs ability to invite to private room. how?
// does server api have ability with admin token?

@ -121,12 +121,6 @@ extension PangeaRoom on Room {
String nameIncludingParents(BuildContext context) =>
_nameIncludingParents(context);
List<String> get allSpaceChildRoomIds => _allSpaceChildRoomIds;
bool canAddAsParentOf(Room? child, {bool spaceMode = false}) {
return _canAddAsParentOf(child, spaceMode: spaceMode);
}
Future<void> pangeaSetSpaceChild(
String roomId, {
bool? suggested,

@ -108,40 +108,6 @@ extension ChildrenAndParentsRoomExtension on Room {
return "... > $nameSoFar";
}
// gets all space children of a given space, down the
// space tree.
List<String> get _allSpaceChildRoomIds {
final List<String> childIds = [];
for (final child in spaceChildren) {
if (child.roomId == null) continue;
childIds.add(child.roomId!);
final Room? room = client.getRoomById(child.roomId!);
if (room != null && room.isSpace) {
childIds.addAll(room._allSpaceChildRoomIds);
}
}
return childIds;
}
// Checks if has permissions to add child chat
// Or whether potential child space is ancestor of this
bool _canAddAsParentOf(Room? child, {bool spaceMode = false}) {
// don't add a room to itself
if (id == child?.id) return false;
spaceMode = child?.isSpace ?? spaceMode;
// get the bool for adding chats to spaces
final bool canAddChild =
(child?.isRoomAdmin ?? true) && canSendEvent(EventTypes.SpaceChild);
if (!spaceMode) return canAddChild;
// if adding space to a space, check if the child is an ancestor
// to prevent cycles
final bool isCycle =
child != null ? child._allSpaceChildRoomIds.contains(id) : false;
return canAddChild && !isCycle;
}
/// Wrapper around call to setSpaceChild with added functionality
/// to prevent adding one room to multiple spaces
Future<void> _pangeaSetSpaceChild(

@ -228,6 +228,13 @@ class PracticeActivityModel {
throw ("content is null in PracticeActivityModel.fromJson");
}
if (json['lang_code'] is! String) {
Sentry.addBreadcrumb(
Breadcrumb(data: {"json": json}),
);
throw ("lang_code is not a string in PracticeActivityModel.fromJson");
}
return PracticeActivityModel(
tgtConstructs: ((json['tgt_constructs'] ?? json['target_constructs'])
as List)

Loading…
Cancel
Save