Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions lib/jmap/mail/mailbox/mailbox.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/http/converter/is_subscribed_converter.dart';
import 'package:jmap_dart_client/http/converter/mailbox_id_converter.dart';
import 'package:jmap_dart_client/http/converter/mailbox_id_nullable_converter.dart';
import 'package:jmap_dart_client/http/converter/mailbox_name_converter.dart';
import 'package:jmap_dart_client/http/converter/role_converter.dart';
Expand All @@ -26,27 +25,47 @@ part 'mailbox.g.dart';
@RoleConverter()
@MailboxIdNullableConverter()
@MailboxNameConverter()
@MailboxIdConverter()
@JsonSerializable()
class Mailbox with EquatableMixin {
static Properties allProperties = Properties({
'id', 'name', 'parentId', 'role', 'sortOrder', 'totalEmails', 'unreadEmails',
'totalThreads', 'unreadThreads', 'myRights', 'isSubscribed'
});

final MailboxId id;
@JsonKey(includeIfNull: false)
final MailboxId? id;

@JsonKey(includeIfNull: false)
final MailboxName? name;

@JsonKey(includeIfNull: false)
final MailboxId? parentId;

@JsonKey(includeIfNull: false)
final Role? role;

@JsonKey(includeIfNull: false)
final SortOrder? sortOrder;

@JsonKey(includeIfNull: false)
final TotalEmails? totalEmails;

@JsonKey(includeIfNull: false)
final UnreadEmails? unreadEmails;

@JsonKey(includeIfNull: false)
final TotalThreads? totalThreads;

@JsonKey(includeIfNull: false)
final UnreadThreads? unreadThreads;

@JsonKey(includeIfNull: false)
final MailboxRights? myRights;

@JsonKey(includeIfNull: false)
final IsSubscribed? isSubscribed;

Mailbox(
Mailbox({
this.id,
this.name,
this.parentId,
Expand All @@ -58,7 +77,7 @@ class Mailbox with EquatableMixin {
this.unreadThreads,
this.myRights,
this.isSubscribed
);
});

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

Expand Down
84 changes: 50 additions & 34 deletions lib/jmap/mail/mailbox/mailbox.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions lib/jmap/mail/mailbox/set/set_mailbox_method.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
import 'package:jmap_dart_client/http/converter/id_converter.dart';
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/method/request/set_method.dart';
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:json_annotation/json_annotation.dart';

class SetMailboxMethod extends SetMethod<Mailbox> with OptionalOnDestroyRemoveEmails {
SetMailboxMethod(AccountId accountId) : super(accountId);

@override
MethodName get methodName => MethodName('Mailbox/set');

@override
Set<CapabilityIdentifier> get requiredCapabilities => {
CapabilityIdentifier.jmapMail,
CapabilityIdentifier.jmapCore
};

@override
Map<String, dynamic> toJson() {
final val = <String, dynamic>{
'accountId': const AccountIdConverter().toJson(accountId),
};

void writeNotNull(String key, dynamic value) {
if (value != null) {
val[key] = value;
}
}

writeNotNull('ifInState', ifInState?.value);
writeNotNull('create', create
?.map((id, create) => SetMethodPropertiesConverter().fromMapIdToJson(id, create.toJson())));
writeNotNull('update', update
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(id, update.toJson())));
writeNotNull('destroy', destroy
?.map((destroyId) => IdConverter().toJson(destroyId)).toList());
writeNotNull('onDestroyRemoveEmails', onDestroyRemoveEmails);

return val;
}

@override
List<Object?> get props => [accountId, ifInState, create, update, destroy];
}

mixin OptionalOnDestroyRemoveEmails {
@JsonKey(includeIfNull: false)
bool? onDestroyRemoveEmails;

void addOnDestroyRemoveEmails(bool value) {
onDestroyRemoveEmails = value;
}
}
76 changes: 76 additions & 0 deletions lib/jmap/mail/mailbox/set/set_mailbox_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
import 'package:jmap_dart_client/http/converter/id_converter.dart';
import 'package:jmap_dart_client/http/converter/state_converter.dart';
import 'package:jmap_dart_client/http/converter/state_nullable_converter.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';

class SetMailboxResponse extends SetResponse<Mailbox> {
SetMailboxResponse(
AccountId accountId,
State newState, {
State? oldState,
Map<Id, Mailbox>? created,
Map<Id, Mailbox?>? updated,
Set<Id>? destroyed,
Map<Id, SetError>? notCreated,
Map<Id, SetError>? notUpdated,
Map<Id, SetError>? notDestroyed
}) : super(
accountId,
newState,
oldState: oldState,
created: created,
updated: updated,
destroyed: destroyed,
notCreated: notCreated,
notUpdated: notUpdated,
notDestroyed: notDestroyed
);

static SetMailboxResponse deserialize(Map<String, dynamic> json) {
return SetMailboxResponse(
const AccountIdConverter().fromJson(json['accountId'] as String),
const StateConverter().fromJson(json['newState'] as String),
oldState: StateNullableConverter().fromJson(json['oldState'] as String?),
created: (json['created'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
Mailbox.fromJson(value as Map<String, dynamic>))),
updated: (json['updated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
value != null ? Mailbox.fromJson(value as Map<String, dynamic>) : null)),
destroyed: (json['destroyed'] as List<dynamic>?)
?.map((id) => IdConverter().fromJson(id)).toSet(),
notCreated: (json['notCreated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
notUpdated: (json['notUpdated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
notDestroyed: (json['notDestroyed'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
);
}

@override
List<Object?> get props => [
oldState,
newState,
created,
updated,
destroyed,
notCreated,
notUpdated,
notDestroyed
];
}
Loading