Skip to content

Commit 5fb0801

Browse files
dab246hoangdat
authored andcommitted
Create set mailbox method and response
1 parent 8adab6d commit 5fb0801

File tree

5 files changed

+320
-39
lines changed

5 files changed

+320
-39
lines changed

lib/jmap/mail/mailbox/mailbox.dart

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:equatable/equatable.dart';
22
import 'package:jmap_dart_client/http/converter/is_subscribed_converter.dart';
3-
import 'package:jmap_dart_client/http/converter/mailbox_id_converter.dart';
43
import 'package:jmap_dart_client/http/converter/mailbox_id_nullable_converter.dart';
54
import 'package:jmap_dart_client/http/converter/mailbox_name_converter.dart';
65
import 'package:jmap_dart_client/http/converter/role_converter.dart';
@@ -26,27 +25,47 @@ part 'mailbox.g.dart';
2625
@RoleConverter()
2726
@MailboxIdNullableConverter()
2827
@MailboxNameConverter()
29-
@MailboxIdConverter()
3028
@JsonSerializable()
3129
class Mailbox with EquatableMixin {
3230
static Properties allProperties = Properties({
3331
'id', 'name', 'parentId', 'role', 'sortOrder', 'totalEmails', 'unreadEmails',
3432
'totalThreads', 'unreadThreads', 'myRights', 'isSubscribed'
3533
});
3634

37-
final MailboxId id;
35+
@JsonKey(includeIfNull: false)
36+
final MailboxId? id;
37+
38+
@JsonKey(includeIfNull: false)
3839
final MailboxName? name;
40+
41+
@JsonKey(includeIfNull: false)
3942
final MailboxId? parentId;
43+
44+
@JsonKey(includeIfNull: false)
4045
final Role? role;
46+
47+
@JsonKey(includeIfNull: false)
4148
final SortOrder? sortOrder;
49+
50+
@JsonKey(includeIfNull: false)
4251
final TotalEmails? totalEmails;
52+
53+
@JsonKey(includeIfNull: false)
4354
final UnreadEmails? unreadEmails;
55+
56+
@JsonKey(includeIfNull: false)
4457
final TotalThreads? totalThreads;
58+
59+
@JsonKey(includeIfNull: false)
4560
final UnreadThreads? unreadThreads;
61+
62+
@JsonKey(includeIfNull: false)
4663
final MailboxRights? myRights;
64+
65+
@JsonKey(includeIfNull: false)
4766
final IsSubscribed? isSubscribed;
4867

49-
Mailbox(
68+
Mailbox({
5069
this.id,
5170
this.name,
5271
this.parentId,
@@ -58,7 +77,7 @@ class Mailbox with EquatableMixin {
5877
this.unreadThreads,
5978
this.myRights,
6079
this.isSubscribed
61-
);
80+
});
6281

6382
factory Mailbox.fromJson(Map<String, dynamic> json) => _$MailboxFromJson(json);
6483

lib/jmap/mail/mailbox/mailbox.g.dart

Lines changed: 50 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
2+
import 'package:jmap_dart_client/http/converter/id_converter.dart';
3+
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart';
4+
import 'package:jmap_dart_client/jmap/account_id.dart';
5+
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
6+
import 'package:jmap_dart_client/jmap/core/method/request/set_method.dart';
7+
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
8+
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
9+
import 'package:json_annotation/json_annotation.dart';
10+
11+
class SetMailboxMethod extends SetMethod<Mailbox> with OptionalOnDestroyRemoveEmails {
12+
SetMailboxMethod(AccountId accountId) : super(accountId);
13+
14+
@override
15+
MethodName get methodName => MethodName('Mailbox/set');
16+
17+
@override
18+
Set<CapabilityIdentifier> get requiredCapabilities => {
19+
CapabilityIdentifier.jmapMail,
20+
CapabilityIdentifier.jmapCore
21+
};
22+
23+
@override
24+
Map<String, dynamic> toJson() {
25+
final val = <String, dynamic>{
26+
'accountId': const AccountIdConverter().toJson(accountId),
27+
};
28+
29+
void writeNotNull(String key, dynamic value) {
30+
if (value != null) {
31+
val[key] = value;
32+
}
33+
}
34+
35+
writeNotNull('ifInState', ifInState?.value);
36+
writeNotNull('create', create
37+
?.map((id, create) => SetMethodPropertiesConverter().fromMapIdToJson(id, create.toJson())));
38+
writeNotNull('update', update
39+
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(id, update.toJson())));
40+
writeNotNull('destroy', destroy
41+
?.map((destroyId) => IdConverter().toJson(destroyId)).toList());
42+
writeNotNull('onDestroyRemoveEmails', onDestroyRemoveEmails);
43+
44+
return val;
45+
}
46+
47+
@override
48+
List<Object?> get props => [accountId, ifInState, create, update, destroy];
49+
}
50+
51+
mixin OptionalOnDestroyRemoveEmails {
52+
@JsonKey(includeIfNull: false)
53+
bool? onDestroyRemoveEmails;
54+
55+
void addOnDestroyRemoveEmails(bool value) {
56+
onDestroyRemoveEmails = value;
57+
}
58+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
2+
import 'package:jmap_dart_client/http/converter/id_converter.dart';
3+
import 'package:jmap_dart_client/http/converter/state_converter.dart';
4+
import 'package:jmap_dart_client/http/converter/state_nullable_converter.dart';
5+
import 'package:jmap_dart_client/jmap/account_id.dart';
6+
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
7+
import 'package:jmap_dart_client/jmap/core/id.dart';
8+
import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart';
9+
import 'package:jmap_dart_client/jmap/core/state.dart';
10+
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
11+
12+
class SetMailboxResponse extends SetResponse<Mailbox> {
13+
SetMailboxResponse(
14+
AccountId accountId,
15+
State newState, {
16+
State? oldState,
17+
Map<Id, Mailbox>? created,
18+
Map<Id, Mailbox?>? updated,
19+
Set<Id>? destroyed,
20+
Map<Id, SetError>? notCreated,
21+
Map<Id, SetError>? notUpdated,
22+
Map<Id, SetError>? notDestroyed
23+
}) : super(
24+
accountId,
25+
newState,
26+
oldState: oldState,
27+
created: created,
28+
updated: updated,
29+
destroyed: destroyed,
30+
notCreated: notCreated,
31+
notUpdated: notUpdated,
32+
notDestroyed: notDestroyed
33+
);
34+
35+
static SetMailboxResponse deserialize(Map<String, dynamic> json) {
36+
return SetMailboxResponse(
37+
const AccountIdConverter().fromJson(json['accountId'] as String),
38+
const StateConverter().fromJson(json['newState'] as String),
39+
oldState: StateNullableConverter().fromJson(json['oldState'] as String?),
40+
created: (json['created'] as Map<String, dynamic>?)
41+
?.map((key, value) => MapEntry(
42+
IdConverter().fromJson(key),
43+
Mailbox.fromJson(value as Map<String, dynamic>))),
44+
updated: (json['updated'] as Map<String, dynamic>?)
45+
?.map((key, value) => MapEntry(
46+
IdConverter().fromJson(key),
47+
value != null ? Mailbox.fromJson(value as Map<String, dynamic>) : null)),
48+
destroyed: (json['destroyed'] as List<dynamic>?)
49+
?.map((id) => IdConverter().fromJson(id)).toSet(),
50+
notCreated: (json['notCreated'] as Map<String, dynamic>?)
51+
?.map((key, value) => MapEntry(
52+
IdConverter().fromJson(key),
53+
SetError.fromJson(value))),
54+
notUpdated: (json['notUpdated'] as Map<String, dynamic>?)
55+
?.map((key, value) => MapEntry(
56+
IdConverter().fromJson(key),
57+
SetError.fromJson(value))),
58+
notDestroyed: (json['notDestroyed'] as Map<String, dynamic>?)
59+
?.map((key, value) => MapEntry(
60+
IdConverter().fromJson(key),
61+
SetError.fromJson(value))),
62+
);
63+
}
64+
65+
@override
66+
List<Object?> get props => [
67+
oldState,
68+
newState,
69+
created,
70+
updated,
71+
destroyed,
72+
notCreated,
73+
notUpdated,
74+
notDestroyed
75+
];
76+
}

0 commit comments

Comments
 (0)