TF-2384 Create KeychainSharingManager to manage data push notification
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit f4b839642806597fd495da789d7654041cd9ef21)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/keychain/keychain_sharing_session.dart';
|
||||
|
||||
class KeychainSharingManager {
|
||||
final FlutterSecureStorage _secureStorage;
|
||||
|
||||
KeychainSharingManager(this._secureStorage);
|
||||
|
||||
Future save(KeychainSharingSession keychainSharingSession) => _secureStorage.write(
|
||||
key: keychainSharingSession.accountId.asString,
|
||||
value: jsonEncode(keychainSharingSession.toJson()),
|
||||
);
|
||||
|
||||
Future<bool> isSessionExist(AccountId accountId) =>
|
||||
_secureStorage.containsKey(key: accountId.asString);
|
||||
|
||||
Future<KeychainSharingSession?> getSharingSession(AccountId accountId) async {
|
||||
final jsonData = await _secureStorage.read(key: accountId.asString);
|
||||
if (jsonData?.isNotEmpty == true) {
|
||||
return KeychainSharingSession.fromJson(jsonDecode(jsonData!));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future delete({String? accountId}) {
|
||||
if (accountId != null) {
|
||||
return _secureStorage.delete(key: accountId);
|
||||
} else {
|
||||
return _secureStorage.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/user_name_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
|
||||
part 'keychain_sharing_session.g.dart';
|
||||
|
||||
@UserNameConverter()
|
||||
@AccountIdConverter()
|
||||
@JsonSerializable(includeIfNull: false, explicitToJson: true)
|
||||
class KeychainSharingSession with EquatableMixin {
|
||||
AccountId accountId;
|
||||
UserName userName;
|
||||
AuthenticationType authenticationType;
|
||||
String apiUrl;
|
||||
String? emailState;
|
||||
TokenOIDC? tokenOIDC;
|
||||
String? basicAuth;
|
||||
|
||||
KeychainSharingSession({
|
||||
required this.accountId,
|
||||
required this.userName,
|
||||
required this.authenticationType,
|
||||
required this.apiUrl,
|
||||
this.emailState,
|
||||
this.tokenOIDC,
|
||||
this.basicAuth,
|
||||
});
|
||||
|
||||
factory KeychainSharingSession.fromJson(Map<String, dynamic> json) => _$KeychainSharingSessionFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$KeychainSharingSessionToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
accountId,
|
||||
userName,
|
||||
authenticationType,
|
||||
apiUrl,
|
||||
emailState,
|
||||
tokenOIDC,
|
||||
basicAuth,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user