Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive
(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:model/account/jmap_account.dart';
|
||||
|
||||
extension AccountExtension on Account {
|
||||
|
||||
Account fromAccountId({required AccountId accountId, required String apiUrl}) {
|
||||
return Account(
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected: isSelected,
|
||||
accountId: accountId,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
JmapAccount toJmapAccount(AccountId accountId) {
|
||||
return JmapAccount(
|
||||
accountId,
|
||||
name,
|
||||
isPersonal,
|
||||
isReadOnly,
|
||||
accountCapabilities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
|
||||
extension PersonalAccountExtension on PersonalAccount {
|
||||
|
||||
PersonalAccount fromAccount({
|
||||
required AccountId accountId,
|
||||
required String apiUrl,
|
||||
required UserName userName,
|
||||
}) {
|
||||
return PersonalAccount(
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected: isSelected,
|
||||
accountId: accountId,
|
||||
apiUrl: apiUrl,
|
||||
userName: userName);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ 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/empty_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:model/error_type_handler/account_exception.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:uri/uri.dart';
|
||||
|
||||
extension SessionExtension on Session {
|
||||
@@ -49,4 +51,18 @@ extension SessionExtension on Session {
|
||||
}
|
||||
return (capability as T);
|
||||
}
|
||||
|
||||
JmapAccount get personalAccount {
|
||||
if (accounts.isNotEmpty) {
|
||||
final listPersonalAccount = accounts.entries
|
||||
.map((entry) => entry.value.toJmapAccount(entry.key))
|
||||
.where((jmapAccount) => jmapAccount.isPersonal)
|
||||
.toList();
|
||||
|
||||
if (listPersonalAccount.isNotEmpty) {
|
||||
return listPersonalAccount.first;
|
||||
}
|
||||
}
|
||||
throw NotFoundPersonalAccountException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user