wrap new space submit function in futureLoadingDialog to display to the user if there's an error in the space creation flow
This commit is contained in:
parent
2900634900
commit
ce07c9cb72
1 changed files with 109 additions and 96 deletions
|
|
@ -14,6 +14,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
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:matrix/matrix.dart' as sdk;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -148,106 +149,118 @@ class NewSpaceController extends State<NewSpace> {
|
|||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
try {
|
||||
final avatar = this.avatar;
|
||||
avatarUrl ??= avatar == null ? null : await client.uploadContent(avatar);
|
||||
final classCode = await SpaceCodeUtil.generateSpaceCode(client);
|
||||
final spaceId = await client.createRoom(
|
||||
// #Pangea
|
||||
preset: publicGroup
|
||||
? sdk.CreateRoomPreset.publicChat
|
||||
: sdk.CreateRoomPreset.privateChat,
|
||||
// #Pangea
|
||||
creationContent: {'type': RoomCreationTypes.mSpace},
|
||||
visibility: publicGroup ? sdk.Visibility.public : null,
|
||||
// #Pangea
|
||||
// roomAliasName: publicGroup
|
||||
// ? nameController.text.trim().toLowerCase().replaceAll(' ', '_')
|
||||
// : null,
|
||||
// roomAliasName: SpaceCodeUtil.generateSpaceCode(),
|
||||
// Pangea#
|
||||
name: nameController.text.trim(),
|
||||
topic: topicController.text.isEmpty ? null : topicController.text,
|
||||
// #Pangea
|
||||
// powerLevelContentOverride: {'events_default': 100},
|
||||
powerLevelContentOverride: addToSpaceKey.currentState != null
|
||||
? await ClassChatPowerLevels.powerLevelOverrideForClassChat(
|
||||
context,
|
||||
addToSpaceKey.currentState!.parent,
|
||||
)
|
||||
: null,
|
||||
// Pangea#
|
||||
initialState: [
|
||||
// #Pangea
|
||||
...initialState,
|
||||
if (avatar != null)
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomAvatar,
|
||||
content: {'url': avatarUrl.toString()},
|
||||
),
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomJoinRules,
|
||||
content: {
|
||||
ModelKey.joinRule:
|
||||
sdk.JoinRules.knock.toString().replaceAll('JoinRules.', ''),
|
||||
ModelKey.accessCode: classCode,
|
||||
},
|
||||
),
|
||||
// #Pangea
|
||||
// try {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
try {
|
||||
// Pangea#
|
||||
],
|
||||
// Pangea#
|
||||
);
|
||||
// #Pangea
|
||||
final List<Future<dynamic>> futures = [
|
||||
Matrix.of(context).client.waitForRoomInSync(spaceId, join: true),
|
||||
];
|
||||
if (addToSpaceKey.currentState != null) {
|
||||
futures.add(addToSpaceKey.currentState!.addSpaces(spaceId));
|
||||
}
|
||||
await Future.wait(futures);
|
||||
final avatar = this.avatar;
|
||||
avatarUrl ??=
|
||||
avatar == null ? null : await client.uploadContent(avatar);
|
||||
final classCode = await SpaceCodeUtil.generateSpaceCode(client);
|
||||
final spaceId = await client.createRoom(
|
||||
// #Pangea
|
||||
preset: publicGroup
|
||||
? sdk.CreateRoomPreset.publicChat
|
||||
: sdk.CreateRoomPreset.privateChat,
|
||||
// #Pangea
|
||||
creationContent: {'type': RoomCreationTypes.mSpace},
|
||||
visibility: publicGroup ? sdk.Visibility.public : null,
|
||||
// #Pangea
|
||||
// roomAliasName: publicGroup
|
||||
// ? nameController.text.trim().toLowerCase().replaceAll(' ', '_')
|
||||
// : null,
|
||||
// roomAliasName: SpaceCodeUtil.generateSpaceCode(),
|
||||
// Pangea#
|
||||
name: nameController.text.trim(),
|
||||
topic: topicController.text.isEmpty ? null : topicController.text,
|
||||
// #Pangea
|
||||
// powerLevelContentOverride: {'events_default': 100},
|
||||
powerLevelContentOverride: addToSpaceKey.currentState != null
|
||||
? await ClassChatPowerLevels.powerLevelOverrideForClassChat(
|
||||
context,
|
||||
addToSpaceKey.currentState!.parent,
|
||||
)
|
||||
: null,
|
||||
// Pangea#
|
||||
initialState: [
|
||||
// #Pangea
|
||||
...initialState,
|
||||
if (avatar != null)
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomAvatar,
|
||||
content: {'url': avatarUrl.toString()},
|
||||
),
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomJoinRules,
|
||||
content: {
|
||||
ModelKey.joinRule: sdk.JoinRules.knock
|
||||
.toString()
|
||||
.replaceAll('JoinRules.', ''),
|
||||
ModelKey.accessCode: classCode,
|
||||
},
|
||||
),
|
||||
// Pangea#
|
||||
],
|
||||
// Pangea#
|
||||
);
|
||||
// #Pangea
|
||||
final List<Future<dynamic>> futures = [
|
||||
Matrix.of(context).client.waitForRoomInSync(spaceId, join: true),
|
||||
];
|
||||
if (addToSpaceKey.currentState != null) {
|
||||
futures.add(addToSpaceKey.currentState!.addSpaces(spaceId));
|
||||
}
|
||||
await Future.wait(futures);
|
||||
|
||||
final capacity = addCapacityKey.currentState?.capacity;
|
||||
final space = client.getRoomById(spaceId);
|
||||
if (capacity != null && space != null) {
|
||||
space.updateRoomCapacity(capacity);
|
||||
}
|
||||
final capacity = addCapacityKey.currentState?.capacity;
|
||||
final space = client.getRoomById(spaceId);
|
||||
if (capacity != null && space != null) {
|
||||
space.updateRoomCapacity(capacity);
|
||||
}
|
||||
|
||||
final Room? room = Matrix.of(context).client.getRoomById(spaceId);
|
||||
if (room == null) {
|
||||
ErrorHandler.logError(
|
||||
e: 'Failed to get new space by id $spaceId',
|
||||
);
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(spaceId);
|
||||
return;
|
||||
}
|
||||
final Room? room = Matrix.of(context).client.getRoomById(spaceId);
|
||||
if (room == null) {
|
||||
ErrorHandler.logError(
|
||||
e: 'Failed to get new space by id $spaceId',
|
||||
);
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(spaceId);
|
||||
return;
|
||||
}
|
||||
|
||||
GoogleAnalytics.createClass(room.name, room.classCode);
|
||||
try {
|
||||
await room.invite(BotName.byEnvironment);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to invite pangea bot to space ${room.id}",
|
||||
);
|
||||
}
|
||||
// Pangea#
|
||||
if (!mounted) return;
|
||||
// #Pangea
|
||||
// context.pop<String>(spaceId);
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(spaceId);
|
||||
// Pangea#
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
// #Pangea
|
||||
// topicError = e.toLocalizedString(context);
|
||||
// Pangea#
|
||||
});
|
||||
} finally {
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
GoogleAnalytics.createClass(room.name, room.classCode);
|
||||
try {
|
||||
await room.invite(BotName.byEnvironment);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to invite pangea bot to space ${room.id}",
|
||||
);
|
||||
}
|
||||
// Pangea#
|
||||
if (!mounted) return;
|
||||
// #Pangea
|
||||
// context.pop<String>(spaceId);
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(spaceId);
|
||||
// Pangea#
|
||||
} catch (e, s) {
|
||||
// #Pangea
|
||||
ErrorHandler.logError(e: e, s: s);
|
||||
rethrow;
|
||||
// setState(() {
|
||||
// topicError = e.toLocalizedString(context);
|
||||
// });
|
||||
// Pangea#
|
||||
} finally {
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
// TODO: Go to spaces
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue