Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SearchSnippet][Part-1] Implement SearchSnippet/get #99

Merged
merged 1 commit into from
Nov 6, 2024
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: 29 additions & 0 deletions lib/jmap/mail/email/search_snippet/search_snippet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/http/converter/email_id_converter.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:json_annotation/json_annotation.dart';

part 'search_snippet.g.dart';

@JsonSerializable(
includeIfNull: false,
explicitToJson: true,
converters: [EmailIdConverter()]
)
class SearchSnippet with EquatableMixin {
final EmailId emailId;
final String? subject;
final String? preview;

SearchSnippet({
required this.emailId,
required this.subject,
required this.preview,
});

factory SearchSnippet.fromJson(Map<String, dynamic> json) => _$SearchSnippetFromJson(json);
Map<String, dynamic> toJson() => _$SearchSnippetToJson(this);

@override
List<Object?> get props => [emailId, subject, preview];
}
30 changes: 30 additions & 0 deletions lib/jmap/mail/email/search_snippet/search_snippet.g.dart

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

63 changes: 63 additions & 0 deletions lib/jmap/mail/email/search_snippet/search_snippet_get_method.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/method/request/get_method.dart';
import 'package:jmap_dart_client/jmap/core/method/request/query_method.dart';
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
import 'package:jmap_dart_client/jmap/core/request/result_reference.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_filter_condition.dart';
import 'package:json_annotation/json_annotation.dart';

class SearchSnippetGetMethod extends GetMethod with OptionalFilter, OptionalReferenceEmailIds {
SearchSnippetGetMethod(super.accountId);

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

@override
List<Object?> get props => [methodName, accountId, filter];

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

factory SearchSnippetGetMethod.fromJson(Map<String, dynamic> json) {
return SearchSnippetGetMethod(
const AccountIdConverter().fromJson(json['accountId'])
)
..filter = json['filter'] == null
? null
: EmailFilterCondition.fromJson(json['filter'] as Map<String, dynamic>)
..referenceEmailIds = json['#emailIds'] == null
? null
: ResultReference.fromJson(json['#emailIds'] as Map<String, dynamic>);
}

@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('filter', filter?.toJson());
writeNotNull('#emailIds', referenceEmailIds?.toJson());

return val;
}
}

mixin OptionalReferenceEmailIds {
@JsonKey(name: '#emailIds', includeIfNull: false)
ResultReference? referenceEmailIds;

void addReferenceEmailIds(ResultReference resultReferenceIds) {
referenceEmailIds = resultReferenceIds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/method/method_response.dart';
import 'package:jmap_dart_client/jmap/mail/email/search_snippet/search_snippet.dart';
import 'package:json_annotation/json_annotation.dart';

part 'search_snippet_get_response.g.dart';

@JsonSerializable(
includeIfNull: false,
explicitToJson: true,
converters: [
AccountIdConverter(),
IdConverter(),
]
)
class SearchSnippetGetResponse extends ResponseRequiringAccountId {
SearchSnippetGetResponse(
super.accountId,
this.list,
this.notFound,
);

final List<SearchSnippet>? list;
final List<Id>? notFound;

factory SearchSnippetGetResponse.fromJson(Map<String, dynamic> json) => _$SearchSnippetGetResponseFromJson(json);
Map<String, dynamic> toJson() => _$SearchSnippetGetResponseToJson(this);

@override
List<Object?> get props => [accountId, list, notFound];
}

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

Loading
Loading