simplify: dedupe boilerplate and remove dead code across all layers
This commit is contained in:
@@ -166,13 +166,24 @@ Future<void> _afterExternalFilesUploaded(
|
||||
GetRoomResponseObject room,
|
||||
List<String> uploadedRemotePaths,
|
||||
PendingShare share,
|
||||
) async {
|
||||
) => _runShareFlow(
|
||||
context,
|
||||
action: () =>
|
||||
shareFilesToChat(token: room.token, remoteFilePaths: uploadedRemotePaths),
|
||||
onSuccess: () => _setExternalDraftAndOpenChat(context, room, share),
|
||||
);
|
||||
|
||||
/// Shared share-flow scaffolding: shows the blocking spinner, runs [action],
|
||||
/// maps failures to an error dialog (popping the spinner first), and invokes
|
||||
/// [onSuccess] on success while still mounted.
|
||||
Future<void> _runShareFlow(
|
||||
BuildContext context, {
|
||||
required Future<void> Function() action,
|
||||
required VoidCallback onSuccess,
|
||||
}) async {
|
||||
unawaited(_showBlockingSpinner(context));
|
||||
try {
|
||||
await shareFilesToChat(
|
||||
token: room.token,
|
||||
remoteFilePaths: uploadedRemotePaths,
|
||||
);
|
||||
await action();
|
||||
} catch (e) {
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
if (context.mounted) {
|
||||
@@ -186,7 +197,7 @@ Future<void> _afterExternalFilesUploaded(
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
_setExternalDraftAndOpenChat(context, room, share);
|
||||
onSuccess();
|
||||
}
|
||||
|
||||
void _setExternalDraftAndOpenChat(
|
||||
@@ -213,61 +224,30 @@ Future<void> _internalShareFlow(
|
||||
BuildContext context,
|
||||
GetRoomResponseObject room,
|
||||
RemoteFileRef file,
|
||||
) async {
|
||||
unawaited(_showBlockingSpinner(context));
|
||||
try {
|
||||
await shareFilesToChat(
|
||||
token: room.token,
|
||||
remoteFilePaths: [file.path],
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
if (context.mounted) {
|
||||
InfoDialog.show(
|
||||
context,
|
||||
errorToUserMessage(e),
|
||||
title: 'Fehler',
|
||||
copyable: true,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
_finishWithChat(context, room);
|
||||
}
|
||||
) => _runShareFlow(
|
||||
context,
|
||||
action: () =>
|
||||
shareFilesToChat(token: room.token, remoteFilePaths: [file.path]),
|
||||
onSuccess: () => _finishWithChat(context, room),
|
||||
);
|
||||
|
||||
Future<void> _forwardMessageFlow(
|
||||
BuildContext context,
|
||||
GetRoomResponseObject room,
|
||||
String? text,
|
||||
RemoteFileRef? file,
|
||||
) async {
|
||||
unawaited(_showBlockingSpinner(context));
|
||||
try {
|
||||
) => _runShareFlow(
|
||||
context,
|
||||
action: () async {
|
||||
if (file != null) {
|
||||
await shareFilesToChat(
|
||||
token: room.token,
|
||||
remoteFilePaths: [file.path],
|
||||
);
|
||||
await shareFilesToChat(token: room.token, remoteFilePaths: [file.path]);
|
||||
}
|
||||
if (text != null && text.isNotEmpty) {
|
||||
await SendMessage(room.token, SendMessageParams(text)).run();
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
if (context.mounted) {
|
||||
InfoDialog.show(
|
||||
context,
|
||||
errorToUserMessage(e),
|
||||
title: 'Fehler',
|
||||
copyable: true,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
_finishWithChat(context, room);
|
||||
}
|
||||
},
|
||||
onSuccess: () => _finishWithChat(context, room),
|
||||
);
|
||||
|
||||
/// Modal progress overlay shown during share-API roundtrips. The dialog is
|
||||
/// popped together with the picker by the subsequent popUntil(isFirst).
|
||||
|
||||
Reference in New Issue
Block a user