TF-2182 Fix no blue bar for calendar events

(cherry picked from commit 7ea91d59e860dbd8f5bd38cefd76ca61bc4cc4e3)
This commit is contained in:
dab246
2023-10-04 16:18:32 +07:00
committed by Dat H. Pham
parent c3c8eacb9f
commit b4ce4651c0
17 changed files with 46 additions and 44 deletions
+1 -1
View File
@@ -492,7 +492,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
+1 -1
View File
@@ -296,7 +296,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
+1 -1
View File
@@ -296,7 +296,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@@ -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'; import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
abstract class CalendarEventDataSource { abstract class CalendarEventDataSource {
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds); Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds);
Future<List<EventAction>> getListEventAction(String emailContents); Future<List<EventAction>> getListEventAction(String emailContents);
} }
@@ -15,7 +15,7 @@ class CalendarEventDataSourceImpl extends CalendarEventDataSource {
CalendarEventDataSourceImpl(this._calendarEventAPI, this._exceptionThrower); CalendarEventDataSourceImpl(this._calendarEventAPI, this._exceptionThrower);
@override @override
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) { Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds) {
return Future.sync(() async { return Future.sync(() async {
return await _calendarEventAPI.parse(accountId, blobIds); return await _calendarEventAPI.parse(accountId, blobIds);
}).catchError(_exceptionThrower.throwException); }).catchError(_exceptionThrower.throwException);
@@ -16,7 +16,7 @@ class LocalCalendarEventDataSourceImpl extends CalendarEventDataSource {
LocalCalendarEventDataSourceImpl(this._htmlAnalyzer, this._exceptionThrower); LocalCalendarEventDataSourceImpl(this._htmlAnalyzer, this._exceptionThrower);
@override @override
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) { Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds) {
throw UnimplementedError(); throw UnimplementedError();
} }
@@ -15,7 +15,7 @@ class CalendarEventAPI {
CalendarEventAPI(this._httpClient); CalendarEventAPI(this._httpClient);
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) async { Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds) async {
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation()); final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
final calendarEventParseMethod = CalendarEventParseMethod(accountId, blobIds); final calendarEventParseMethod = CalendarEventParseMethod(accountId, blobIds);
final calendarEventParseInvocation = requestBuilder.invocation(calendarEventParseMethod); final calendarEventParseInvocation = requestBuilder.invocation(calendarEventParseMethod);
@@ -29,7 +29,7 @@ class CalendarEventAPI {
CalendarEventParseResponse.deserialize); CalendarEventParseResponse.deserialize);
if (calendarEventParseResponse?.parsed?.isNotEmpty == true) { if (calendarEventParseResponse?.parsed?.isNotEmpty == true) {
return calendarEventParseResponse!.parsed!.values.toList(); return calendarEventParseResponse!.parsed!;
} else if (calendarEventParseResponse?.notParsable?.isNotEmpty == true) { } else if (calendarEventParseResponse?.notParsable?.isNotEmpty == true) {
throw NotParsableCalendarEventException(); throw NotParsableCalendarEventException();
} else if (calendarEventParseResponse?.notFound?.isNotEmpty == true) { } else if (calendarEventParseResponse?.notFound?.isNotEmpty == true) {
@@ -14,7 +14,7 @@ class CalendarEventRepositoryImpl extends CalendarEventRepository {
CalendarEventRepositoryImpl(this._calendarEventDataSource); CalendarEventRepositoryImpl(this._calendarEventDataSource);
@override @override
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds) { Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds) {
return _calendarEventDataSource[DataSourceType.network]!.parse(accountId, blobIds); return _calendarEventDataSource[DataSourceType.network]!.parse(accountId, blobIds);
} }
@@ -8,9 +8,14 @@ import 'package:tmail_ui_user/features/offline_mode/model/attachment_hive_cache.
extension ListAttachmentsExtension on List<Attachment> { extension ListAttachmentsExtension on List<Attachment> {
List<AttachmentHiveCache> toHiveCache() => map((attachment) => attachment.toHiveCache()).toList(); List<AttachmentHiveCache> toHiveCache() => map((attachment) => attachment.toHiveCache()).toList();
Set<Attachment> get calendarAttachments => where((attachment) => attachment.isCalendarEvent).toSet(); Set<Id> get calendarEventBlobIds => subtypeICSBlobIds.isEmpty ? subtypeCalendarBlobIds : subtypeICSBlobIds;
Set<Id> get calendarEventBlobIds => calendarAttachments Set<Id> get subtypeICSBlobIds => where((attachment) => attachment.type?.subtype == Attachment.eventICSSubtype)
.map((attachment) => attachment.blobId)
.whereNotNull()
.toSet();
Set<Id> get subtypeCalendarBlobIds => where((attachment) => attachment.type?.subtype == Attachment.eventCalendarSubtype)
.map((attachment) => attachment.blobId) .map((attachment) => attachment.blobId)
.whereNotNull() .whereNotNull()
.toSet(); .toSet();
@@ -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'; import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
abstract class CalendarEventRepository { abstract class CalendarEventRepository {
Future<List<CalendarEvent>> parse(AccountId accountId, Set<Id> blobIds); Future<Map<Id, List<CalendarEvent>>> parse(AccountId accountId, Set<Id> blobIds);
Future<List<EventAction>> getListEventAction(String emailContents); Future<List<EventAction>> getListEventAction(String emailContents);
} }
@@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.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/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.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/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/repository/calendar_event_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart';
@@ -21,7 +22,7 @@ class ParseCalendarEventInteractor {
try { try {
yield Right(ParseCalendarEventLoading()); yield Right(ParseCalendarEventLoading());
final result = await Future.wait( final listResult = await Future.wait(
[ [
_calendarEventRepository.parse(accountId, blobIds), _calendarEventRepository.parse(accountId, blobIds),
_calendarEventRepository.getListEventAction(emailContents), _calendarEventRepository.getListEventAction(emailContents),
@@ -29,10 +30,24 @@ class ParseCalendarEventInteractor {
eagerError: true eagerError: true
); );
final calendarEventList = result.first as List<CalendarEvent>; final listCalendarEvent = List<CalendarEvent>.empty(growable: true);
final eventActionList = result.last as List<EventAction>; final listEventAction = List<EventAction>.empty(growable: true);
yield Right(ParseCalendarEventSuccess(calendarEventList, eventActionList)); if (listResult[0] is Map<Id, List<CalendarEvent>>) {
final mapCalendarEvent = listResult[0] as Map<Id, List<CalendarEvent>>;
for (var calendarEvents in mapCalendarEvent.values) {
listCalendarEvent.addAll(calendarEvents);
}
}
if (listResult[1] is List<EventAction>) {
listEventAction.addAll(listResult[1] as List<EventAction>);
}
if (listCalendarEvent.isNotEmpty) {
yield Right(ParseCalendarEventSuccess(listCalendarEvent, listEventAction));
} else {
yield Left(ParseCalendarEventFailure(NotFoundCalendarEventException()));
}
} catch (e) { } catch (e) {
yield Left(ParseCalendarEventFailure(e)); yield Left(ParseCalendarEventFailure(e));
} }
+3 -2
View File
@@ -9,6 +9,9 @@ import 'package:uri/uri.dart';
class Attachment with EquatableMixin { class Attachment with EquatableMixin {
static const String eventICSSubtype = 'ics';
static const String eventCalendarSubtype = 'calendar';
final PartId? partId; final PartId? partId;
final Id? blobId; final Id? blobId;
final UnsignedInt? size; final UnsignedInt? size;
@@ -50,8 +53,6 @@ class Attachment with EquatableMixin {
} }
} }
bool get isCalendarEvent => type?.subtype == 'ics' || type?.subtype == 'calendar';
@override @override
List<Object?> get props => [partId, blobId, size, name, type, cid, disposition]; List<Object?> get props => [partId, blobId, size, name, type, cid, disposition];
} }
+2 -15
View File
@@ -119,22 +119,9 @@ extension EmailExtension on Email {
return emailContents ?? []; return emailContents ?? [];
} }
List<Attachment> get allAttachments { List<Attachment> get allAttachments => attachments?.map((item) => item.toAttachment()).toList() ?? [];
if (attachments != null) {
return attachments!
.where((element) => element.disposition != null)
.map((item) => item.toAttachment())
.toList();
}
return [];
}
List<Attachment> get attachmentsWithCid { List<Attachment> get attachmentsWithCid => allAttachments.where((attachment) => attachment.hasCid()).toList();
return attachments
?.where((element) => element.disposition != null && element.cid?.isNotEmpty == true)
.map((item) => item.toAttachment())
.toList() ?? [];
}
PresentationMailbox? findMailboxContain(Map<MailboxId, PresentationMailbox> mapMailbox) { PresentationMailbox? findMailboxContain(Map<MailboxId, PresentationMailbox> mapMailbox) {
final newMailboxIds = mailboxIds; final newMailboxIds = mailboxIds;
@@ -13,15 +13,9 @@ extension ListAttachmentExtension on List<Attachment> {
return 0; return 0;
} }
List<Attachment> get listAttachmentsDisplayedOutSide { List<Attachment> get listAttachmentsDisplayedOutSide => where((attachment) => attachment.noCid()).toList();
return where((attachment) => attachment.disposition == ContentDisposition.attachment || attachment.noCid())
.toList();
}
List<Attachment> get listAttachmentsDisplayedInContent { List<Attachment> get listAttachmentsDisplayedInContent => where((attachment) => attachment.hasCid()).toList();
return where((attachment) => attachment.hasCid())
.toList();
}
Map<String, String> toMapCidImageDownloadUrl({ Map<String, String> toMapCidImageDownloadUrl({
required AccountId accountId, required AccountId accountId,
+1 -1
View File
@@ -484,7 +484,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
+1 -1
View File
@@ -1011,7 +1011,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
+1 -1
View File
@@ -296,7 +296,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: d374ca15dc5395a6e81cd7714c17a436439f4732 resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
url: "https://github.com/linagora/jmap-dart-client.git" url: "https://github.com/linagora/jmap-dart-client.git"
source: git source: git
version: "0.0.1" version: "0.0.1"