-
Notifications
You must be signed in to change notification settings - Fork 17
Get session #6
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
Merged
Merged
Get session #6
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
963372b
Add Capabilities and properties of these
hoangdat 87482a1
Add Account and AccountConverter
hoangdat 20feb7b
Add session model and its deserialization method
hoangdat 29ba059
Fix error can not convert Uri to Json
hoangdat f722106
Directly call to /.well-known/jmap
dab246 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:jmap_dart_client/http/converter/account_name_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/account_id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/account/account.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
|
||
import 'capabilities_converter.dart'; | ||
|
||
class AccountConverter { | ||
const AccountConverter(); | ||
|
||
MapEntry<AccountId, Account> convert(String key, dynamic value, CapabilitiesConverter converter) { | ||
final accountId = AccountId(Id(key)); | ||
final account = accountFromJson(value, converter); | ||
return MapEntry(accountId, account); | ||
} | ||
|
||
Account accountFromJson(Map<String, dynamic> json, CapabilitiesConverter converter) { | ||
return Account( | ||
const AccountNameConverter().fromJson(json['name'] as String), | ||
json['isPersonal'] as bool, | ||
json['isReadOnly'] as bool, | ||
(json['accountCapabilities'] as Map<String, dynamic>) | ||
hoangdat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.map((key, value) => converter.convert(key, value)) | ||
); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:jmap_dart_client/jmap/core/account/account.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class AccountNameConverter implements JsonConverter<AccountName, String> { | ||
const AccountNameConverter(); | ||
|
||
@override | ||
AccountName fromJson(String json) => AccountName(json); | ||
|
||
@override | ||
String toJson(AccountName object) => object.value; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/core_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/default_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/mail_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/mdn_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/submission_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/vacation_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/websocket_capability.dart'; | ||
|
||
class CapabilitiesConverter { | ||
static final defaultConverter = CapabilitiesConverter(); | ||
|
||
BuiltMap<CapabilityIdentifier, CapabilityProperties Function(Map<String, dynamic>)>? mapCapabilitiesConverter; | ||
final _mapCapabilityConverterBuilder = MapBuilder<CapabilityIdentifier, CapabilityProperties Function(Map<String, dynamic>)>(); | ||
|
||
CapabilitiesConverter() { | ||
_mapCapabilityConverterBuilder.addAll( | ||
{ | ||
CapabilityIdentifier.jmapMail: MailCapability.deserialize, | ||
CapabilityIdentifier.jmapCore: CoreCapability.deserialize, | ||
CapabilityIdentifier.jmapSubmission: SubmissionCapability.deserialize, | ||
CapabilityIdentifier.jmapVacationResponse: VacationCapability.deserialize, | ||
CapabilityIdentifier.jmapWebSocket: WebSocketCapability.deserialize, | ||
CapabilityIdentifier.jmapMdn: MdnCapability.deserialize | ||
}); | ||
} | ||
|
||
void addConverters(Map<CapabilityIdentifier, CapabilityProperties Function(Map<String, dynamic>)> converters) { | ||
_mapCapabilityConverterBuilder.addAll(converters); | ||
} | ||
|
||
void build() { | ||
mapCapabilitiesConverter = _mapCapabilityConverterBuilder.build(); | ||
} | ||
|
||
BuiltMap<CapabilityIdentifier, Function>? getConverters() { | ||
return mapCapabilitiesConverter; | ||
} | ||
|
||
MapEntry<CapabilityIdentifier, CapabilityProperties> convert(String key, dynamic value) { | ||
if (mapCapabilitiesConverter == null) { | ||
build(); | ||
} | ||
|
||
final identifier = CapabilityIdentifier(Uri.parse(key)); | ||
if (mapCapabilitiesConverter!.containsKey(identifier)) { | ||
return MapEntry(identifier, mapCapabilitiesConverter![identifier]!.call(value)); | ||
} else { | ||
return MapEntry(identifier, DefaultCapability(value)); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...erter/capability_identifier_onverter.dart → ...rter/capability_identifier_converter.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import 'package:jmap_dart_client/jmap/core/capability/capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class CapabilityIdentifierConverter implements JsonConverter<CapabilityIdentifier, String> { | ||
const CapabilityIdentifierConverter(); | ||
|
||
@override | ||
CapabilityIdentifier fromJson(String json) => CapabilityIdentifier(json); | ||
CapabilityIdentifier fromJson(String json) => CapabilityIdentifier(Uri.parse(json)); | ||
|
||
@override | ||
String toJson(CapabilityIdentifier object) => object.value; | ||
String toJson(CapabilityIdentifier object) => object.value.toString(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class UnsignedIntConverter implements JsonConverter<UnsignedInt, int> { | ||
const UnsignedIntConverter(); | ||
|
||
@override | ||
UnsignedInt fromJson(int json) { | ||
return UnsignedInt(json); | ||
} | ||
|
||
@override | ||
int toJson(UnsignedInt object) { | ||
return object.value.toInt(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:jmap_dart_client/jmap/core/url_jmap.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class UrlJmapConverter implements JsonConverter<UrlJmap, String> { | ||
const UrlJmapConverter(); | ||
|
||
@override | ||
UrlJmap fromJson(String json) => UrlJmap(json); | ||
|
||
@override | ||
String toJson(UrlJmap object) => object.value; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:jmap_dart_client/jmap/core/user_name.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class UserNameConverter implements JsonConverter<UserName, String> { | ||
const UserNameConverter(); | ||
|
||
@override | ||
UserName fromJson(String json) => UserName(json); | ||
|
||
@override | ||
String toJson(UserName object) => object.value; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart'; | ||
|
||
class Account with EquatableMixin { | ||
|
||
final AccountName name; | ||
final bool isPersonal; | ||
final bool isReadOnly; | ||
final Map<CapabilityIdentifier, CapabilityProperties> accountCapabilities; | ||
|
||
Account( | ||
this.name, | ||
this.isPersonal, | ||
this.isReadOnly, | ||
this.accountCapabilities, | ||
); | ||
|
||
@override | ||
List<Object> get props => [name, isPersonal, isReadOnly, accountCapabilities]; | ||
} | ||
|
||
class AccountName with EquatableMixin { | ||
|
||
final String value; | ||
|
||
AccountName(this.value); | ||
|
||
@override | ||
List<Object> get props => [value]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class CapabilityIdentifier with EquatableMixin { | ||
static final jmapCore = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:core')); | ||
static final jmapMail = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:mail')); | ||
static final jmapSubmission = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:submission')); | ||
static final jmapVacationResponse = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:vacationresponse')); | ||
static final jmapWebSocket = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:websocket')); | ||
static final jmapMdn = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:mdn')); | ||
|
||
final Uri value; | ||
|
||
CapabilityIdentifier(this.value); | ||
|
||
@override | ||
List<Object> get props => [value]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class CapabilityProperties with EquatableMixin { | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:jmap_dart_client/http/converter/unsigned_int_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart'; | ||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'core_capability.g.dart'; | ||
|
||
@UnsignedIntConverter() | ||
@JsonSerializable() | ||
class CoreCapability extends CapabilityProperties with EquatableMixin { | ||
final UnsignedInt maxSizeUpload; | ||
hoangdat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final UnsignedInt maxConcurrentUpload; | ||
hoangdat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final UnsignedInt maxSizeRequest; | ||
final UnsignedInt maxConcurrentRequests; | ||
final UnsignedInt maxCallsInRequest; | ||
final UnsignedInt maxObjectsInGet; | ||
final UnsignedInt maxObjectsInSet; | ||
final Set<String> collationAlgorithms; | ||
|
||
CoreCapability( | ||
this.maxSizeUpload, | ||
this.maxConcurrentUpload, | ||
this.maxSizeRequest, | ||
this.maxConcurrentRequests, | ||
this.maxCallsInRequest, | ||
this.maxObjectsInGet, | ||
this.maxObjectsInSet, | ||
this.collationAlgorithms); | ||
|
||
factory CoreCapability.fromJson(Map<String, dynamic> json) => _$CoreCapabilityFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CoreCapabilityToJson(this); | ||
|
||
static CoreCapability deserialize(Map<String, dynamic> json) => CoreCapability.fromJson(json); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
maxSizeUpload, | ||
maxConcurrentUpload, | ||
maxSizeRequest, | ||
maxConcurrentRequests, | ||
maxCallsInRequest, | ||
maxObjectsInGet, | ||
maxObjectsInSet, | ||
collationAlgorithms | ||
]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart'; | ||
|
||
class DefaultCapability extends CapabilityProperties with EquatableMixin { | ||
final Map<String, dynamic> properties; | ||
|
||
DefaultCapability(this.properties); | ||
|
||
@override | ||
List<Object?> get props => [properties]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.