Skip to content

Commit

Permalink
Fix some file with mimeType is empty cannot drag n drop attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Oct 6, 2023
1 parent 14b0ff9 commit ad223e1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 43 deletions.
4 changes: 2 additions & 2 deletions core/lib/domain/extensions/media_type_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import 'package:core/domain/preview/supported_preview_file_types.dart';
import 'package:http_parser/http_parser.dart';

extension MediaTypeExtension on MediaType {
static const String imageType = 'image';

bool isAndroidSupportedPreview() => SupportedPreviewFileTypes.androidSupportedTypes.contains(mimeType);

bool isIOSSupportedPreview() => SupportedPreviewFileTypes.iOSSupportedTypes.containsKey(mimeType);

bool isImageFile() => SupportedPreviewFileTypes.imageMimeTypes.contains(mimeType);

bool isImageValid() => type == 'image';

bool isDocFile() => SupportedPreviewFileTypes.docMimeTypes.contains(mimeType);

bool isPowerPointFile() => SupportedPreviewFileTypes.pptMimeTypes.contains(mimeType);
Expand Down
32 changes: 3 additions & 29 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1955,26 +1955,10 @@ class ComposerController extends BaseController {
return;
}

if (fileUpload.type == null) {
final fileInfo = await fileUpload.toFileInfo();
if (fileInfo != null) {
_addAttachmentFromDragAndDrop(fileInfo: fileInfo);
} else if (context.mounted) {
_appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
);
}
return;
}

final mediaType = MediaType.parse(fileUpload.type!);
if (mediaType.isImageValid()) {
if (fileUpload.type?.startsWith(MediaTypeExtension.imageType) == true) {
_addInlineImageFromDragAndDrop(
base64Data: fileUpload.base64!,
name: fileUpload.name,
type: mediaType,
size: fileUpload.size,
);
} else {
final fileInfo = await fileUpload.toFileInfo();
Expand All @@ -1989,19 +1973,9 @@ class ComposerController extends BaseController {
}
}

void _addInlineImageFromDragAndDrop({
required String base64Data,
String? name,
MediaType? type,
int? size
}) {
void _addInlineImageFromDragAndDrop({required String base64Data, String? name}) {
log('ComposerController::_addInlineImageFromDragAndDrop:name: $name');
richTextWebController.insertInlineImage(
base64Data: base64Data,
name: name,
type: type,
size: size,
);
richTextWebController.insertInlineImage(base64Data: base64Data, name: name);
}

void handleImageUploadFailure({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:html_editor_enhanced/html_editor.dart';
import 'package:http_parser/http_parser.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/code_view_state.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/dropdown_menu_font_status.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/formatting_options_state.dart';
Expand Down Expand Up @@ -186,13 +185,8 @@ class RichTextWebController extends BaseRichTextController {
}
}

void insertInlineImage({
required String base64Data,
String? name,
MediaType? type,
int? size,
}) async {
log('RichTextWebController::insertInlineImage():name: $name | type: $type');
void insertInlineImage({required String base64Data, String? name}) async {
log('RichTextWebController::insertInlineImage():name: $name');
final base64Uri = '<img src="$base64Data" data-filename="$name" alt="Inline Image TeamMail" style="max-width: 100%" />';
editorController.insertHtml(base64Uri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_value.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/email/email_content.dart';
import 'package:model/extensions/media_type_extension.dart';
import 'package:model/extensions/media_type_nullable_extension.dart';

class ComposerCache with EquatableMixin {

Expand Down
2 changes: 1 addition & 1 deletion model/lib/email/presentation_email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/email/email_content.dart';
import 'package:model/extensions/email_address_extension.dart';
import 'package:model/extensions/media_type_extension.dart';
import 'package:model/extensions/media_type_nullable_extension.dart';
import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:model/mailbox/select_mode.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http_parser/http_parser.dart';
import 'package:model/email/email_content_type.dart';

extension MediaTypeExtension on MediaType? {
extension MediaTypeNullableExtension on MediaType? {

EmailContentType toEmailContentType() {
if (this == null) {
Expand Down
2 changes: 1 addition & 1 deletion model/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export 'extensions/list_presentation_email_extension.dart';
export 'extensions/mailbox_extension.dart';
export 'extensions/mailbox_id_extension.dart';
export 'extensions/mailbox_name_extension.dart';
export 'extensions/media_type_extension.dart';
export 'extensions/media_type_nullable_extension.dart';
export 'extensions/presentation_email_extension.dart';
export 'extensions/presentation_mailbox_extension.dart';
export 'extensions/properties_extension.dart';
Expand Down

0 comments on commit ad223e1

Please sign in to comment.