Skip to content

Commit

Permalink
TF-1857 Add headerCalendarEvent to email cached
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jul 19, 2023
1 parent b9f7a55 commit b2e043a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/cleanup/domain/model/email_cleanup_rule.dart';
Expand Down Expand Up @@ -31,6 +32,9 @@ extension EmailCacheExtension on EmailCache {
mailboxIds: mailboxIds != null
? Map.fromIterables(mailboxIds!.keys.map((value) => MailboxId(Id(value))), mailboxIds!.values)
: null,
headerCalendarEvent: headerCalendarEvent != null
? Map.fromIterables(headerCalendarEvent!.keys.map((value) => IndividualHeaderIdentifier(value)), headerCalendarEvent!.values)
: null
);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/features/thread/data/extensions/email_extension.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/thread/data/extensions/map_header_identifier_id_extension.dart';
import 'package:tmail_ui_user/features/thread/data/model/email_cache.dart';
import 'package:tmail_ui_user/features/thread/data/extensions/map_keywords_extension.dart';
import 'package:tmail_ui_user/features/thread/data/extensions/email_address_extension.dart';
Expand All @@ -23,6 +24,7 @@ extension EmailExtension on Email {
bcc: bcc?.map((emailAddress) => emailAddress.toEmailAddressHiveCache()).toList(),
replyTo: replyTo?.map((emailAddress) => emailAddress.toEmailAddressHiveCache()).toList(),
mailboxIds: mailboxIds?.toMapString(),
headerCalendarEvent: headerCalendarEvent?.toMapString(),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';

extension MapHeaderIdentifierExtension on Map<IndividualHeaderIdentifier, String?> {

Map<String, String?> toMapString() => Map.fromIterables(keys.map((identifier) => identifier.value), values);
}
5 changes: 5 additions & 0 deletions lib/features/thread/data/model/email_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class EmailCache extends HiveObject with EquatableMixin {
@HiveField(13)
Map<String, bool>? mailboxIds;

@HiveField(14)
Map<String, String?>? headerCalendarEvent;

EmailCache(
this.id,
{
Expand All @@ -67,6 +70,7 @@ class EmailCache extends HiveObject with EquatableMixin {
this.bcc,
this.replyTo,
this.mailboxIds,
this.headerCalendarEvent,
}
);

Expand All @@ -86,5 +90,6 @@ class EmailCache extends HiveObject with EquatableMixin {
preview,
hasAttachment,
mailboxIds,
headerCalendarEvent,
];
}
39 changes: 21 additions & 18 deletions model/lib/extensions/email_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/model.dart';
Expand Down Expand Up @@ -38,24 +39,25 @@ extension EmailExtension on Email {

Email updatedEmail({Map<KeyWordIdentifier, bool>? newKeywords, Map<MailboxId, bool>? newMailboxIds}) {
return Email(
id: id,
keywords: newKeywords ?? keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: newMailboxIds ?? mailboxIds,
htmlBody: htmlBody,
bodyValues: bodyValues,
headerUserAgent: headerUserAgent,
attachments: attachments
id: id,
keywords: newKeywords ?? keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: newMailboxIds ?? mailboxIds,
htmlBody: htmlBody,
bodyValues: bodyValues,
headerUserAgent: headerUserAgent,
attachments: attachments,
headerCalendarEvent: headerCalendarEvent
);
}

Expand Down Expand Up @@ -97,6 +99,7 @@ extension EmailExtension on Email {
bcc: updatedProperties.contain(EmailProperty.bcc) ? newEmail.bcc : bcc,
replyTo: updatedProperties.contain(EmailProperty.replyTo) ? newEmail.replyTo : replyTo,
mailboxIds: updatedProperties.contain(EmailProperty.mailboxIds) ? newEmail.mailboxIds : mailboxIds,
headerCalendarEvent: updatedProperties.contain(IndividualHeaderIdentifier.headerCalendarEvent.value) ? newEmail.headerCalendarEvent : headerCalendarEvent,
);
}

Expand Down
3 changes: 3 additions & 0 deletions model/lib/extensions/presentation_email_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ extension PresentationEmailExtension on PresentationEmail {
replyTo: replyTo,
htmlBody: htmlBody,
bodyValues: bodyValues,
mailboxIds: mailboxIds,
headers: emailHeader?.toSet(),
headerCalendarEvent: headerCalendarEvent
);
}

Expand Down

0 comments on commit b2e043a

Please sign in to comment.