refactor: Enhance file attachment handling and UI components
- Updated the file attachment service to utilize a new LocalAttachment class, improving the management of file metadata such as display names. - Refactored methods for picking and uploading files to accommodate the new LocalAttachment structure, ensuring consistent handling of file attributes. - Improved the chat page to validate and manage file attachments more effectively, enhancing user experience during file uploads. - Added functionality for image previews in the file attachment widget, allowing users to see selected images before sending. - Introduced a remove button for attachments, improving usability by enabling users to easily discard unwanted files.
This commit is contained in:
@@ -127,6 +127,43 @@ class TaskQueueNotifier extends Notifier<List<OutboundTask>> {
|
||||
await _save();
|
||||
}
|
||||
|
||||
Future<void> cancelUploadsForFile(String filePath) async {
|
||||
bool updated = false;
|
||||
state = [
|
||||
for (final task in state)
|
||||
task.maybeMap(
|
||||
uploadMedia: (upload) {
|
||||
if ((upload.status == TaskStatus.queued ||
|
||||
upload.status == TaskStatus.running) &&
|
||||
upload.filePath == filePath) {
|
||||
updated = true;
|
||||
return upload.copyWith(
|
||||
status: TaskStatus.cancelled,
|
||||
completedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
return upload;
|
||||
},
|
||||
imageToDataUrl: (image) {
|
||||
if ((image.status == TaskStatus.queued ||
|
||||
image.status == TaskStatus.running) &&
|
||||
image.filePath == filePath) {
|
||||
updated = true;
|
||||
return image.copyWith(
|
||||
status: TaskStatus.cancelled,
|
||||
completedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
return image;
|
||||
},
|
||||
orElse: () => task,
|
||||
),
|
||||
];
|
||||
if (updated) {
|
||||
await _save();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cancelByConversation(String conversationId) async {
|
||||
state = [
|
||||
for (final t in state)
|
||||
|
||||
@@ -107,6 +107,10 @@ class TaskWorker {
|
||||
QueuedAttachmentStatus.failed => FileUploadStatus.failed,
|
||||
QueuedAttachmentStatus.cancelled => FileUploadStatus.failed,
|
||||
};
|
||||
const imageExts = <String>{'.jpg', '.jpeg', '.png', '.gif', '.webp'};
|
||||
final lowerName = task.fileName.toLowerCase();
|
||||
final bool isImage =
|
||||
existing.isImage ?? imageExts.any(lowerName.endsWith);
|
||||
final newState = FileUploadState(
|
||||
file: File(task.filePath),
|
||||
fileName: task.fileName,
|
||||
@@ -117,6 +121,7 @@ class TaskWorker {
|
||||
status: status,
|
||||
fileId: entry.fileId ?? existing.fileId,
|
||||
error: entry.lastError,
|
||||
isImage: isImage,
|
||||
);
|
||||
_ref
|
||||
.read(attachedFilesProvider.notifier)
|
||||
@@ -260,6 +265,7 @@ class TaskWorker {
|
||||
progress: 0.0,
|
||||
status: FileUploadStatus.uploading,
|
||||
fileId: existing.fileId,
|
||||
isImage: existing.isImage ?? true,
|
||||
);
|
||||
_ref
|
||||
.read(attachedFilesProvider.notifier)
|
||||
|
||||
Reference in New Issue
Block a user