-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1193: Store/get/delete active account in persistent storage
- Loading branch information
Showing
14 changed files
with
332 additions
and
20 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
lib/data/datasource/multiple_account/multiple_account_datasource.dart
This file contains 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,7 @@ | ||
abstract class MultipleAccountDatasource { | ||
Future<void> storePersistActiveAccount(String userId); | ||
|
||
Future<String?> getPersistActiveAccount(); | ||
|
||
Future<void> deletePersistActiveAccount(); | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart
This file contains 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,23 @@ | ||
import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart'; | ||
import 'package:fluffychat/data/local/multiple_account/multiple_account_cache_manager.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
|
||
class MultipleAccountDatasourceImpl implements MultipleAccountDatasource { | ||
final MultipleAccountCacheManager _multipleAccountCacheManager = | ||
getIt.get<MultipleAccountCacheManager>(); | ||
|
||
@override | ||
Future<String?> getPersistActiveAccount() { | ||
return _multipleAccountCacheManager.getPersistActiveAccount(); | ||
} | ||
|
||
@override | ||
Future<void> storePersistActiveAccount(String userId) { | ||
return _multipleAccountCacheManager.storePersistActiveAccount(userId); | ||
} | ||
|
||
@override | ||
Future<void> deletePersistActiveAccount() { | ||
return _multipleAccountCacheManager.deletePersistActiveAccount(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/data/local/multiple_account/multiple_account_cache_manager.dart
This file contains 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,20 @@ | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/utils/famedlysdk_store.dart'; | ||
|
||
class MultipleAccountCacheManager { | ||
final pres = getIt.get<Store>(); | ||
|
||
static const String persistActiveAccountKey = 'persist_active_account_key'; | ||
|
||
Future<void> storePersistActiveAccount(String userId) async { | ||
await pres.setItem(persistActiveAccountKey, userId); | ||
} | ||
|
||
Future<String?> getPersistActiveAccount() async { | ||
return await pres.getItem(persistActiveAccountKey); | ||
} | ||
|
||
Future<void> deletePersistActiveAccount() async { | ||
await pres.deleteItem(persistActiveAccountKey); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/data/repository/multiple_account/multiple_account_repository_impl.dart
This file contains 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,23 @@ | ||
import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; | ||
|
||
class MultipleAccountRepositoryImpl extends MultipleAccountRepository { | ||
final MultipleAccountDatasource _multipleAccountDatasource = | ||
getIt.get<MultipleAccountDatasource>(); | ||
|
||
@override | ||
Future<String?> getPersistActiveAccount() { | ||
return _multipleAccountDatasource.getPersistActiveAccount(); | ||
} | ||
|
||
@override | ||
Future<void> storePersistActiveAccount(String userId) { | ||
return _multipleAccountDatasource.storePersistActiveAccount(userId); | ||
} | ||
|
||
@override | ||
Future<void> deletePersistActiveAccount() { | ||
return _multipleAccountDatasource.deletePersistActiveAccount(); | ||
} | ||
} |
This file contains 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
14 changes: 14 additions & 0 deletions
14
lib/domain/app_state/multiple_account/delete_persist_active_account_state.dart
This file contains 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,14 @@ | ||
import 'package:fluffychat/presentation/state/failure.dart'; | ||
import 'package:fluffychat/presentation/state/success.dart'; | ||
|
||
class DeletePersistActiveAccountSuccess extends UIState { | ||
DeletePersistActiveAccountSuccess(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class DeletePersistActiveAccountFailure extends FeatureFailure { | ||
const DeletePersistActiveAccountFailure(dynamic exception) | ||
: super(exception: exception); | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/domain/app_state/multiple_account/get_persist_active_account_state.dart
This file contains 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,18 @@ | ||
import 'package:fluffychat/presentation/state/failure.dart'; | ||
import 'package:fluffychat/presentation/state/success.dart'; | ||
|
||
class GetPersistActiveAccountSuccess extends UIState { | ||
final String userId; | ||
|
||
GetPersistActiveAccountSuccess(this.userId); | ||
|
||
@override | ||
List<Object?> get props => [userId]; | ||
} | ||
|
||
class GetPersistActiveAccountFailure extends FeatureFailure { | ||
const GetPersistActiveAccountFailure(dynamic exception) | ||
: super(exception: exception); | ||
} | ||
|
||
class PersistedActiveAccountIsEmpty extends FeatureFailure {} |
14 changes: 14 additions & 0 deletions
14
lib/domain/app_state/multiple_account/store_persist_active_account_state.dart
This file contains 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,14 @@ | ||
import 'package:fluffychat/presentation/state/failure.dart'; | ||
import 'package:fluffychat/presentation/state/success.dart'; | ||
|
||
class StorePersistActiveAccountSuccess extends UIState { | ||
StorePersistActiveAccountSuccess(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class StorePersistActiveAccountFailure extends FeatureFailure { | ||
const StorePersistActiveAccountFailure(dynamic exception) | ||
: super(exception: exception); | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/domain/repository/multiple_account/multiple_account_repository.dart
This file contains 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,7 @@ | ||
abstract class MultipleAccountRepository { | ||
Future<void> storePersistActiveAccount(String userId); | ||
|
||
Future<String?> getPersistActiveAccount(); | ||
|
||
Future<void> deletePersistActiveAccount(); | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart
This file contains 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,22 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/app_state/multiple_account/delete_persist_active_account_state.dart'; | ||
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class DeletePersistActiveAccountInteractor { | ||
final MultipleAccountRepository _multipleAccountRepository = | ||
getIt.get<MultipleAccountRepository>(); | ||
|
||
Future<Either<Failure, Success>> execute() async { | ||
try { | ||
await _multipleAccountRepository.deletePersistActiveAccount(); | ||
return Right(DeletePersistActiveAccountSuccess()); | ||
} catch (e) { | ||
Logs().e('DeletePersistActiveAccountInteractor::execute(): Error $e'); | ||
return Left(DeletePersistActiveAccountFailure(e)); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/domain/usecase/multiple_account/get_persist_active_account_interactor.dart
This file contains 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:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/app_state/multiple_account/get_persist_active_account_state.dart'; | ||
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class GetPersistActiveAccountInteractor { | ||
final MultipleAccountRepository _multipleAccountRepository = | ||
getIt.get<MultipleAccountRepository>(); | ||
|
||
Future<Either<Failure, Success>> execute() async { | ||
try { | ||
final persistActiveAccount = | ||
await _multipleAccountRepository.getPersistActiveAccount(); | ||
if (persistActiveAccount == null) { | ||
return Left(PersistedActiveAccountIsEmpty()); | ||
} else { | ||
return Right(GetPersistActiveAccountSuccess(persistActiveAccount)); | ||
} | ||
} catch (e) { | ||
Logs().e('GetPersistActiveAccountInteractor::execute(): Error $e'); | ||
return Left(GetPersistActiveAccountFailure(e)); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/domain/usecase/multiple_account/store_persist_active_account_interactor.dart
This file contains 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,22 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/app_state/multiple_account/store_persist_active_account_state.dart'; | ||
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class StorePersistActiveAccountInteractor { | ||
final MultipleAccountRepository _multipleAccountRepository = | ||
getIt.get<MultipleAccountRepository>(); | ||
|
||
Future<Either<Failure, Success>> execute(String userId) async { | ||
try { | ||
await _multipleAccountRepository.storePersistActiveAccount(userId); | ||
return Right(StorePersistActiveAccountSuccess()); | ||
} catch (e) { | ||
Logs().e('GetPersistActiveAccountInteractor::execute(): Error $e'); | ||
return Left(StorePersistActiveAccountFailure(e)); | ||
} | ||
} | ||
} |
Oops, something went wrong.