diff --git a/contact/pubspec.lock b/contact/pubspec.lock index 319ffe4ac..5e5916b00 100644 --- a/contact/pubspec.lock +++ b/contact/pubspec.lock @@ -492,7 +492,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/fcm/pubspec.lock b/fcm/pubspec.lock index f61f10856..dffc02fb4 100644 --- a/fcm/pubspec.lock +++ b/fcm/pubspec.lock @@ -296,7 +296,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/forward/pubspec.lock b/forward/pubspec.lock index f61f10856..dffc02fb4 100644 --- a/forward/pubspec.lock +++ b/forward/pubspec.lock @@ -296,7 +296,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/lib/features/email/data/datasource/calendar_event_datasource.dart b/lib/features/email/data/datasource/calendar_event_datasource.dart index f2c6b4283..a65dc1a9d 100644 --- a/lib/features/email/data/datasource/calendar_event_datasource.dart +++ b/lib/features/email/data/datasource/calendar_event_datasource.dart @@ -5,7 +5,7 @@ import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; import 'package:tmail_ui_user/features/email/domain/model/event_action.dart'; abstract class CalendarEventDataSource { - Future> parse(AccountId accountId, Set blobIds); + Future>> parse(AccountId accountId, Set blobIds); Future> getListEventAction(String emailContents); } \ No newline at end of file diff --git a/lib/features/email/data/datasource_impl/calendar_event_datasource_impl.dart b/lib/features/email/data/datasource_impl/calendar_event_datasource_impl.dart index 2dfca5a8e..42c162ece 100644 --- a/lib/features/email/data/datasource_impl/calendar_event_datasource_impl.dart +++ b/lib/features/email/data/datasource_impl/calendar_event_datasource_impl.dart @@ -15,7 +15,7 @@ class CalendarEventDataSourceImpl extends CalendarEventDataSource { CalendarEventDataSourceImpl(this._calendarEventAPI, this._exceptionThrower); @override - Future> parse(AccountId accountId, Set blobIds) { + Future>> parse(AccountId accountId, Set blobIds) { return Future.sync(() async { return await _calendarEventAPI.parse(accountId, blobIds); }).catchError(_exceptionThrower.throwException); diff --git a/lib/features/email/data/datasource_impl/local_calendar_event_datasource_impl.dart b/lib/features/email/data/datasource_impl/local_calendar_event_datasource_impl.dart index 54f2cb8be..084ff4a82 100644 --- a/lib/features/email/data/datasource_impl/local_calendar_event_datasource_impl.dart +++ b/lib/features/email/data/datasource_impl/local_calendar_event_datasource_impl.dart @@ -16,7 +16,7 @@ class LocalCalendarEventDataSourceImpl extends CalendarEventDataSource { LocalCalendarEventDataSourceImpl(this._htmlAnalyzer, this._exceptionThrower); @override - Future> parse(AccountId accountId, Set blobIds) { + Future>> parse(AccountId accountId, Set blobIds) { throw UnimplementedError(); } diff --git a/lib/features/email/data/network/calendar_event_api.dart b/lib/features/email/data/network/calendar_event_api.dart index 19ce72046..2f50c1e48 100644 --- a/lib/features/email/data/network/calendar_event_api.dart +++ b/lib/features/email/data/network/calendar_event_api.dart @@ -15,7 +15,7 @@ class CalendarEventAPI { CalendarEventAPI(this._httpClient); - Future> parse(AccountId accountId, Set blobIds) async { + Future>> parse(AccountId accountId, Set blobIds) async { final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation()); final calendarEventParseMethod = CalendarEventParseMethod(accountId, blobIds); final calendarEventParseInvocation = requestBuilder.invocation(calendarEventParseMethod); @@ -29,7 +29,7 @@ class CalendarEventAPI { CalendarEventParseResponse.deserialize); if (calendarEventParseResponse?.parsed?.isNotEmpty == true) { - return calendarEventParseResponse!.parsed!.values.toList(); + return calendarEventParseResponse!.parsed!; } else if (calendarEventParseResponse?.notParsable?.isNotEmpty == true) { throw NotParsableCalendarEventException(); } else if (calendarEventParseResponse?.notFound?.isNotEmpty == true) { diff --git a/lib/features/email/data/repository/calendar_event_repository_impl.dart b/lib/features/email/data/repository/calendar_event_repository_impl.dart index e88e8dc4a..877b2dbfd 100644 --- a/lib/features/email/data/repository/calendar_event_repository_impl.dart +++ b/lib/features/email/data/repository/calendar_event_repository_impl.dart @@ -14,7 +14,7 @@ class CalendarEventRepositoryImpl extends CalendarEventRepository { CalendarEventRepositoryImpl(this._calendarEventDataSource); @override - Future> parse(AccountId accountId, Set blobIds) { + Future>> parse(AccountId accountId, Set blobIds) { return _calendarEventDataSource[DataSourceType.network]!.parse(accountId, blobIds); } diff --git a/lib/features/email/domain/extensions/list_attachments_extension.dart b/lib/features/email/domain/extensions/list_attachments_extension.dart index bd9a0fc08..4bfa32c97 100644 --- a/lib/features/email/domain/extensions/list_attachments_extension.dart +++ b/lib/features/email/domain/extensions/list_attachments_extension.dart @@ -8,9 +8,14 @@ import 'package:tmail_ui_user/features/offline_mode/model/attachment_hive_cache. extension ListAttachmentsExtension on List { List toHiveCache() => map((attachment) => attachment.toHiveCache()).toList(); - Set get calendarAttachments => where((attachment) => attachment.isCalendarEvent).toSet(); + Set get calendarEventBlobIds => subtypeICSBlobIds.isEmpty ? subtypeCalendarBlobIds : subtypeICSBlobIds; - Set get calendarEventBlobIds => calendarAttachments + Set get subtypeICSBlobIds => where((attachment) => attachment.type?.subtype == Attachment.eventICSSubtype) + .map((attachment) => attachment.blobId) + .whereNotNull() + .toSet(); + + Set get subtypeCalendarBlobIds => where((attachment) => attachment.type?.subtype == Attachment.eventCalendarSubtype) .map((attachment) => attachment.blobId) .whereNotNull() .toSet(); diff --git a/lib/features/email/domain/repository/calendar_event_repository.dart b/lib/features/email/domain/repository/calendar_event_repository.dart index 068a0730b..809293bcd 100644 --- a/lib/features/email/domain/repository/calendar_event_repository.dart +++ b/lib/features/email/domain/repository/calendar_event_repository.dart @@ -5,7 +5,7 @@ import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; import 'package:tmail_ui_user/features/email/domain/model/event_action.dart'; abstract class CalendarEventRepository { - Future> parse(AccountId accountId, Set blobIds); + Future>> parse(AccountId accountId, Set blobIds); Future> getListEventAction(String emailContents); } \ No newline at end of file diff --git a/lib/features/email/domain/usecases/parse_calendar_event_interactor.dart b/lib/features/email/domain/usecases/parse_calendar_event_interactor.dart index 93752f3dc..e40e43dfa 100644 --- a/lib/features/email/domain/usecases/parse_calendar_event_interactor.dart +++ b/lib/features/email/domain/usecases/parse_calendar_event_interactor.dart @@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; +import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart'; import 'package:tmail_ui_user/features/email/domain/model/event_action.dart'; import 'package:tmail_ui_user/features/email/domain/repository/calendar_event_repository.dart'; import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart'; @@ -21,7 +22,7 @@ class ParseCalendarEventInteractor { try { yield Right(ParseCalendarEventLoading()); - final result = await Future.wait( + final listResult = await Future.wait( [ _calendarEventRepository.parse(accountId, blobIds), _calendarEventRepository.getListEventAction(emailContents), @@ -29,10 +30,24 @@ class ParseCalendarEventInteractor { eagerError: true ); - final calendarEventList = result.first as List; - final eventActionList = result.last as List; + final listCalendarEvent = List.empty(growable: true); + final listEventAction = List.empty(growable: true); - yield Right(ParseCalendarEventSuccess(calendarEventList, eventActionList)); + if (listResult[0] is Map>) { + final mapCalendarEvent = listResult[0] as Map>; + for (var calendarEvents in mapCalendarEvent.values) { + listCalendarEvent.addAll(calendarEvents); + } + } + if (listResult[1] is List) { + listEventAction.addAll(listResult[1] as List); + } + + if (listCalendarEvent.isNotEmpty) { + yield Right(ParseCalendarEventSuccess(listCalendarEvent, listEventAction)); + } else { + yield Left(ParseCalendarEventFailure(NotFoundCalendarEventException())); + } } catch (e) { yield Left(ParseCalendarEventFailure(e)); } diff --git a/model/lib/email/attachment.dart b/model/lib/email/attachment.dart index 2e78df771..a0f30e6b1 100644 --- a/model/lib/email/attachment.dart +++ b/model/lib/email/attachment.dart @@ -9,6 +9,9 @@ import 'package:uri/uri.dart'; class Attachment with EquatableMixin { + static const String eventICSSubtype = 'ics'; + static const String eventCalendarSubtype = 'calendar'; + final PartId? partId; final Id? blobId; final UnsignedInt? size; @@ -50,8 +53,6 @@ class Attachment with EquatableMixin { } } - bool get isCalendarEvent => type?.subtype == 'ics' || type?.subtype == 'calendar'; - @override List get props => [partId, blobId, size, name, type, cid, disposition]; } diff --git a/model/lib/extensions/email_extension.dart b/model/lib/extensions/email_extension.dart index 9d440f07f..afee2f592 100644 --- a/model/lib/extensions/email_extension.dart +++ b/model/lib/extensions/email_extension.dart @@ -119,22 +119,9 @@ extension EmailExtension on Email { return emailContents ?? []; } - List get allAttachments { - if (attachments != null) { - return attachments! - .where((element) => element.disposition != null) - .map((item) => item.toAttachment()) - .toList(); - } - return []; - } + List get allAttachments => attachments?.map((item) => item.toAttachment()).toList() ?? []; - List get attachmentsWithCid { - return attachments - ?.where((element) => element.disposition != null && element.cid?.isNotEmpty == true) - .map((item) => item.toAttachment()) - .toList() ?? []; - } + List get attachmentsWithCid => allAttachments.where((attachment) => attachment.hasCid()).toList(); PresentationMailbox? findMailboxContain(Map mapMailbox) { final newMailboxIds = mailboxIds; diff --git a/model/lib/extensions/list_attachment_extension.dart b/model/lib/extensions/list_attachment_extension.dart index 8f3b715ab..fa9c02d7a 100644 --- a/model/lib/extensions/list_attachment_extension.dart +++ b/model/lib/extensions/list_attachment_extension.dart @@ -13,15 +13,9 @@ extension ListAttachmentExtension on List { return 0; } - List get listAttachmentsDisplayedOutSide { - return where((attachment) => attachment.disposition == ContentDisposition.attachment || attachment.noCid()) - .toList(); - } + List get listAttachmentsDisplayedOutSide => where((attachment) => attachment.noCid()).toList(); - List get listAttachmentsDisplayedInContent { - return where((attachment) => attachment.hasCid()) - .toList(); - } + List get listAttachmentsDisplayedInContent => where((attachment) => attachment.hasCid()).toList(); Map toMapCidImageDownloadUrl({ required AccountId accountId, diff --git a/model/pubspec.lock b/model/pubspec.lock index 8cf50229d..0a83ff0e4 100644 --- a/model/pubspec.lock +++ b/model/pubspec.lock @@ -484,7 +484,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/pubspec.lock b/pubspec.lock index aad64c87e..c0009c468 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1011,7 +1011,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/rule_filter/pubspec.lock b/rule_filter/pubspec.lock index f61f10856..dffc02fb4 100644 --- a/rule_filter/pubspec.lock +++ b/rule_filter/pubspec.lock @@ -296,7 +296,7 @@ packages: description: path: "." ref: master - resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 + resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9 url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1"