TF-4195 Implement add a Label to an email
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
|
||||
extension MapKeywordsExtension on Map<KeyWordIdentifier, bool> {
|
||||
|
||||
Map<String, bool> toMapString() => Map.fromIterables(keys.map((keyword) => keyword.value), values);
|
||||
extension MapKeywordsExtension on Map<KeyWordIdentifier, bool>? {
|
||||
Map<String, bool> toMapString() => Map.fromIterables(
|
||||
this?.keys.map((keyword) => keyword.value) ?? {},
|
||||
this?.values ?? [],
|
||||
);
|
||||
|
||||
List<KeyWordIdentifier> get enabledKeywords =>
|
||||
entries.where((e) => e.value).map((e) => e.key).toList();
|
||||
}
|
||||
this?.entries.where((e) => e.value).map((e) => e.key).toList() ?? [];
|
||||
|
||||
Map<KeyWordIdentifier, bool> withKeyword(KeyWordIdentifier keyword) {
|
||||
return Map<KeyWordIdentifier, bool>.from(this ?? {})..[keyword] = true;
|
||||
}
|
||||
|
||||
Map<KeyWordIdentifier, bool> withoutKeyword(KeyWordIdentifier keyword) {
|
||||
return Map<KeyWordIdentifier, bool>.from(this ?? {})..remove(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
|
||||
extension PresentationEmailMapExtension on Map<EmailId, PresentationEmail?> {
|
||||
Map<EmailId, PresentationEmail?> addEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((id, email) {
|
||||
if (id != emailId || email == null) {
|
||||
return MapEntry(id, email);
|
||||
}
|
||||
return MapEntry(id, email.addKeyword(keyword));
|
||||
});
|
||||
}
|
||||
|
||||
Map<EmailId, PresentationEmail?> removeEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((id, email) {
|
||||
if (id != emailId || email == null) {
|
||||
return MapEntry(id, email);
|
||||
}
|
||||
return MapEntry(id, email.removeKeyword(keyword));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user