TF-3250 Fix Share file from external to Twake Mail sometimes open home screen only
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/file_extension.dart';
|
||||
|
||||
extension SharedMediaFileExtension on SharedMediaFile {
|
||||
File toFile() {
|
||||
if (PlatformInfo.isIOS) {
|
||||
final pathFile = type == SharedMediaType.FILE
|
||||
? path.toString().replaceAll('file:/', '').replaceAll('%20', ' ')
|
||||
: path.toString().replaceAll('%20', ' ');
|
||||
return File(pathFile);
|
||||
} else {
|
||||
return File(path);
|
||||
}
|
||||
}
|
||||
File toFile() => File(path);
|
||||
|
||||
FileInfo toFileInfo({bool? isShared}) => toFile().toFileInfo(isInline: type == SharedMediaType.IMAGE, isShared: isShared);
|
||||
FileInfo toFileInfo({bool? isShared}) =>
|
||||
toFile().toFileInfo(
|
||||
isInline: type == SharedMediaType.image,
|
||||
isShared: isShared,
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:model/email/email_content_type.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
|
||||
@@ -45,7 +40,7 @@ class HomeController extends ReloadableController {
|
||||
void onInit() {
|
||||
if (PlatformInfo.isMobile) {
|
||||
_initFlutterDownloader();
|
||||
_registerReceivingSharingIntent();
|
||||
_registerReceivingFileSharing();
|
||||
}
|
||||
if (PlatformInfo.isIOS) {
|
||||
_registerNotificationClickOnIOS();
|
||||
@@ -85,20 +80,8 @@ class HomeController extends ReloadableController {
|
||||
], eagerError: true).then((_) => getAuthenticatedAccountAction());
|
||||
}
|
||||
|
||||
void _registerReceivingSharingIntent() {
|
||||
_emailReceiveManager.receivingSharingStream.listen((uri) {
|
||||
if (uri != null) {
|
||||
if (GetUtils.isEmail(uri.path)) {
|
||||
_emailReceiveManager.setPendingEmailAddress(EmailAddress(null, uri.path));
|
||||
} else if (uri.scheme == "file") {
|
||||
_emailReceiveManager.setPendingFileInfo([SharedMediaFile(uri.path, null, null, SharedMediaType.FILE)]);
|
||||
} else {
|
||||
_emailReceiveManager.setPendingEmailContent(EmailContent(EmailContentType.textPlain, Uri.decodeComponent(uri.path)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_emailReceiveManager.receivingFileSharingStream.listen(_emailReceiveManager.setPendingFileInfo);
|
||||
void _registerReceivingFileSharing() {
|
||||
_emailReceiveManager.registerReceivingFileSharingStreamWhileAppClosed();
|
||||
}
|
||||
|
||||
void _registerNotificationClickOnIOS() {
|
||||
|
||||
+87
-34
@@ -25,6 +25,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:rxdart/transformers.dart';
|
||||
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
||||
@@ -241,11 +242,8 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
|
||||
ComposerArguments? composerArguments;
|
||||
List<Identity>? _identities;
|
||||
ScrollController? listSearchFilterScrollController;
|
||||
|
||||
late StreamSubscription _emailAddressStreamSubscription;
|
||||
late StreamSubscription _emailContentStreamSubscription;
|
||||
late StreamSubscription _fileReceiveManagerStreamSubscription;
|
||||
|
||||
StreamSubscription? _pendingSharedFileInfoSubscription;
|
||||
StreamSubscription? _receivingFileSharingStreamSubscription;
|
||||
StreamSubscription? _currentEmailIdInNotificationIOSStreamSubscription;
|
||||
|
||||
final StreamController<Either<Failure, Success>> _progressStateController =
|
||||
@@ -288,6 +286,9 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
if (PlatformInfo.isMobile) {
|
||||
_registerReceivingFileSharingStream();
|
||||
}
|
||||
_registerStreamListener();
|
||||
BackButtonInterceptor.add(_onBackButtonInterceptor, name: AppRoutes.dashboard);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
@@ -301,9 +302,6 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
|
||||
if (PlatformInfo.isWeb) {
|
||||
listSearchFilterScrollController = ScrollController();
|
||||
}
|
||||
_registerPendingEmailAddress();
|
||||
_registerPendingEmailContents();
|
||||
_registerPendingFileInfo();
|
||||
if (PlatformInfo.isIOS) {
|
||||
_registerPendingCurrentEmailIdInNotification();
|
||||
}
|
||||
@@ -454,31 +452,85 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
|
||||
}
|
||||
}
|
||||
|
||||
void _registerPendingEmailAddress() {
|
||||
_emailAddressStreamSubscription =
|
||||
_emailReceiveManager.pendingEmailAddressInfo.stream.listen((emailAddress) {
|
||||
if (emailAddress?.email?.isNotEmpty == true) {
|
||||
goToComposer(ComposerArguments.fromEmailAddress(emailAddress!));
|
||||
}
|
||||
});
|
||||
void _registerReceivingFileSharingStream() {
|
||||
_receivingFileSharingStreamSubscription = _emailReceiveManager
|
||||
.receivingFileSharingStream
|
||||
.listen(
|
||||
_emailReceiveManager.setPendingFileInfo,
|
||||
onError: (err) {
|
||||
logError('MailboxDashBoardController::_registerReceivingFileSharingStream::receivingFileSharingStream:Exception = $err');
|
||||
},
|
||||
);
|
||||
|
||||
_pendingSharedFileInfoSubscription = _emailReceiveManager
|
||||
.pendingSharedFileInfo
|
||||
.listen(
|
||||
_handleReceivingFileSharing,
|
||||
onError: (err) {
|
||||
logError('MailboxDashBoardController::_registerReceivingFileSharingStream::pendingSharedFileInfo:Exception = $err');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _registerPendingEmailContents() {
|
||||
_emailContentStreamSubscription =
|
||||
_emailReceiveManager.pendingEmailContentInfo.stream.listen((emailContent) {
|
||||
if (emailContent?.content.isNotEmpty == true) {
|
||||
goToComposer(ComposerArguments.fromContentShared([emailContent!].asHtmlString));
|
||||
}
|
||||
});
|
||||
}
|
||||
void _handleReceivingFileSharing(List<SharedMediaFile> listSharedMediaFile) {
|
||||
log('MailboxDashBoardController::_handleReceivingFileSharing: LIST_LENGTH = ${listSharedMediaFile.length}');
|
||||
if (listSharedMediaFile.isEmpty) return;
|
||||
|
||||
void _registerPendingFileInfo() {
|
||||
_fileReceiveManagerStreamSubscription =
|
||||
_emailReceiveManager.pendingFileInfo.stream.listen((listFile) {
|
||||
if (listFile.isNotEmpty) {
|
||||
goToComposer(ComposerArguments.fromFileShared(listFile));
|
||||
}
|
||||
});
|
||||
for (var file in listSharedMediaFile) {
|
||||
log('MailboxDashBoardController::_handleReceivingFileSharing:SharedMediaFile = ${file.toMap()}');
|
||||
}
|
||||
|
||||
if (listSharedMediaFile.length == 1) {
|
||||
final sharedMediaFile = listSharedMediaFile.first;
|
||||
if (sharedMediaFile.path.trim().isEmpty) return;
|
||||
|
||||
switch (sharedMediaFile.type) {
|
||||
case SharedMediaType.image:
|
||||
case SharedMediaType.video:
|
||||
case SharedMediaType.file:
|
||||
goToComposer(
|
||||
ComposerArguments.fromFileShared([sharedMediaFile]),
|
||||
);
|
||||
break;
|
||||
case SharedMediaType.text:
|
||||
if (sharedMediaFile.mimeType == Constant.textVCardMimeType) {
|
||||
goToComposer(
|
||||
ComposerArguments.fromFileShared([sharedMediaFile]),
|
||||
);
|
||||
} else if (sharedMediaFile.mimeType == Constant.textPlainMimeType) {
|
||||
goToComposer(
|
||||
ComposerArguments.fromContentShared(sharedMediaFile.path.trim()),
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SharedMediaType.url:
|
||||
if (sharedMediaFile.path.startsWith(RouteUtils.mailtoPrefix)) {
|
||||
final navigationRouter = RouteUtils.generateNavigationRouterFromMailtoLink(sharedMediaFile.path);
|
||||
goToComposer(
|
||||
ComposerArguments.fromMailtoUri(
|
||||
listEmailAddress: navigationRouter.listEmailAddress,
|
||||
subject: navigationRouter.subject,
|
||||
body: navigationRouter.body,
|
||||
),
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SharedMediaType.mailto:
|
||||
if (EmailUtils.isEmailAddressValid(sharedMediaFile.path)) {
|
||||
goToComposer(
|
||||
ComposerArguments.fromEmailAddress(
|
||||
EmailAddress(null, sharedMediaFile.path),
|
||||
),
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
goToComposer(
|
||||
ComposerArguments.fromFileShared(listSharedMediaFile),
|
||||
);
|
||||
}
|
||||
|
||||
void _registerPendingCurrentEmailIdInNotification() {
|
||||
@@ -2861,14 +2913,15 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
|
||||
if (PlatformInfo.isWeb) {
|
||||
listSearchFilterScrollController?.dispose();
|
||||
}
|
||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||
if (PlatformInfo.isIOS) {
|
||||
_iosNotificationManager?.dispose();
|
||||
_currentEmailIdInNotificationIOSStreamSubscription?.cancel();
|
||||
}
|
||||
_emailAddressStreamSubscription.cancel();
|
||||
_emailContentStreamSubscription.cancel();
|
||||
_fileReceiveManagerStreamSubscription.cancel();
|
||||
if (PlatformInfo.isMobile) {
|
||||
_pendingSharedFileInfoSubscription?.cancel();
|
||||
_receivingFileSharingStreamSubscription?.cancel();
|
||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||
}
|
||||
_progressStateController.close();
|
||||
_refreshActionEventController.close();
|
||||
_notificationManager.closeStream();
|
||||
|
||||
@@ -1,75 +1,38 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class EmailReceiveManager {
|
||||
BehaviorSubject<List<SharedMediaFile>> _pendingSharedFileInfo =
|
||||
BehaviorSubject.seeded(List.empty(growable: true));
|
||||
BehaviorSubject<List<SharedMediaFile>> get pendingSharedFileInfo =>
|
||||
_pendingSharedFileInfo;
|
||||
|
||||
BehaviorSubject<EmailAddress?> _pendingEmailAddressInfo = BehaviorSubject.seeded(null);
|
||||
BehaviorSubject<EmailAddress?> get pendingEmailAddressInfo => _pendingEmailAddressInfo;
|
||||
Stream<List<SharedMediaFile>> get receivingFileSharingStream =>
|
||||
ReceiveSharingIntent.instance.getMediaStream();
|
||||
|
||||
BehaviorSubject<EmailContent?> _pendingEmailContentInfo = BehaviorSubject.seeded(null);
|
||||
BehaviorSubject<EmailContent?> get pendingEmailContentInfo => _pendingEmailContentInfo;
|
||||
void registerReceivingFileSharingStreamWhileAppClosed() {
|
||||
ReceiveSharingIntent.instance.getInitialMedia().then((value) {
|
||||
setPendingFileInfo(value);
|
||||
|
||||
BehaviorSubject<List<SharedMediaFile>> _pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
|
||||
BehaviorSubject<List<SharedMediaFile>> get pendingFileInfo => _pendingFileInfo;
|
||||
|
||||
Stream<Uri?> get receivingSharingStream {
|
||||
return Rx.merge([
|
||||
Stream.fromFuture(ReceiveSharingIntent.getInitialTextAsUri()),
|
||||
ReceiveSharingIntent.getTextStreamAsUri()
|
||||
]);
|
||||
}
|
||||
Stream<List<SharedMediaFile>> get receivingFileSharingStream {
|
||||
return Rx.merge([
|
||||
Stream.fromFuture(ReceiveSharingIntent.getInitialMedia()),
|
||||
ReceiveSharingIntent.getMediaStream()
|
||||
]);
|
||||
}
|
||||
|
||||
void setPendingEmailAddress(EmailAddress emailAddress) async {
|
||||
_clearPendingEmailAddress();
|
||||
_pendingEmailAddressInfo.add(emailAddress);
|
||||
}
|
||||
|
||||
void setPendingEmailContent(EmailContent emailContent) async {
|
||||
_clearPendingEmailContent();
|
||||
_pendingEmailContentInfo.add(emailContent);
|
||||
}
|
||||
|
||||
void _clearPendingEmailContent() {
|
||||
if (_pendingEmailContentInfo.isClosed) {
|
||||
_pendingEmailContentInfo = BehaviorSubject.seeded(null);
|
||||
} else {
|
||||
_pendingEmailContentInfo.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
void _clearPendingEmailAddress() {
|
||||
if(_pendingEmailAddressInfo.isClosed) {
|
||||
_pendingEmailAddressInfo = BehaviorSubject.seeded(null);
|
||||
} else {
|
||||
_pendingEmailAddressInfo.add(null);
|
||||
}
|
||||
ReceiveSharingIntent.instance.reset();
|
||||
});
|
||||
}
|
||||
|
||||
void closeEmailReceiveManagerStream() {
|
||||
_pendingEmailAddressInfo.close();
|
||||
_pendingEmailContentInfo.close();
|
||||
_pendingFileInfo.close();
|
||||
_pendingSharedFileInfo.close();
|
||||
}
|
||||
|
||||
void setPendingFileInfo(List<SharedMediaFile> list) async {
|
||||
void setPendingFileInfo(List<SharedMediaFile> list) {
|
||||
_clearPendingFileInfo();
|
||||
_pendingFileInfo.add(list);
|
||||
_pendingSharedFileInfo.add(list);
|
||||
}
|
||||
|
||||
void _clearPendingFileInfo() {
|
||||
if(_pendingFileInfo.isClosed) {
|
||||
_pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
|
||||
if(_pendingSharedFileInfo.isClosed) {
|
||||
_pendingSharedFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
|
||||
} else {
|
||||
_pendingFileInfo.add(List.empty(growable: true));
|
||||
_pendingSharedFileInfo.add(List.empty(growable: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user