mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-14 17:05:28 -04:00
refactor
This commit is contained in:
parent
2ccad50f9a
commit
360ba436f8
29 changed files with 501 additions and 317 deletions
|
@ -1,23 +1,23 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../models/models.dart';
|
||||
import '../repository/account_repository.dart';
|
||||
|
||||
class ActiveAccountInfoCubit extends Cubit<AccountInfo> {
|
||||
ActiveAccountInfoCubit(AccountRepository accountRepository)
|
||||
class AccountInfoCubit extends Cubit<AccountInfo> {
|
||||
AccountInfoCubit(
|
||||
AccountRepository accountRepository, TypedKey superIdentityRecordKey)
|
||||
: _accountRepository = accountRepository,
|
||||
super(accountRepository
|
||||
.getAccountInfo(accountRepository.getActiveLocalAccount())) {
|
||||
super(accountRepository.getAccountInfo(superIdentityRecordKey)) {
|
||||
// Subscribe to streams
|
||||
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
|
||||
switch (change) {
|
||||
case AccountRepositoryChange.activeLocalAccount:
|
||||
case AccountRepositoryChange.localAccounts:
|
||||
case AccountRepositoryChange.userLogins:
|
||||
emit(accountRepository
|
||||
.getAccountInfo(accountRepository.getActiveLocalAccount()));
|
||||
emit(accountRepository.getAccountInfo(superIdentityRecordKey));
|
||||
break;
|
||||
}
|
||||
});
|
|
@ -11,7 +11,7 @@ typedef AccountRecordState = proto.Account;
|
|||
/// The saved state of a VeilidChat Account on the DHT
|
||||
/// Used to synchronize status, profile, and options for a specific account
|
||||
/// across multiple clients. This DHT record is the 'source of truth' for an
|
||||
/// account and is privately encrypted with an owned recrod from the 'userLogin'
|
||||
/// account and is privately encrypted with an owned record from the 'userLogin'
|
||||
/// tabledb-local storage, encrypted by the unlock code for the account.
|
||||
class AccountRecordCubit extends DefaultDHTRecordCubit<AccountRecordState> {
|
||||
AccountRecordCubit(
|
||||
|
|
35
lib/account_manager/cubits/active_local_account_cubit.dart
Normal file
35
lib/account_manager/cubits/active_local_account_cubit.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../repository/account_repository.dart';
|
||||
|
||||
class ActiveLocalAccountCubit extends Cubit<TypedKey?> {
|
||||
ActiveLocalAccountCubit(AccountRepository accountRepository)
|
||||
: _accountRepository = accountRepository,
|
||||
super(accountRepository.getActiveLocalAccount()) {
|
||||
// Subscribe to streams
|
||||
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
|
||||
switch (change) {
|
||||
case AccountRepositoryChange.activeLocalAccount:
|
||||
emit(_accountRepository.getActiveLocalAccount());
|
||||
break;
|
||||
// Ignore these
|
||||
case AccountRepositoryChange.localAccounts:
|
||||
case AccountRepositoryChange.userLogins:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await super.close();
|
||||
await _accountRepositorySubscription.cancel();
|
||||
}
|
||||
|
||||
final AccountRepository _accountRepository;
|
||||
late final StreamSubscription<AccountRepositoryChange>
|
||||
_accountRepositorySubscription;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
export 'account_info_cubit.dart';
|
||||
export 'account_record_cubit.dart';
|
||||
export 'account_records_bloc_map_cubit.dart';
|
||||
export 'active_account_info_cubit.dart';
|
||||
export 'active_local_account_cubit.dart';
|
||||
export 'local_accounts_cubit.dart';
|
||||
export 'user_logins_cubit.dart';
|
||||
|
|
|
@ -7,7 +7,7 @@ enum AccountInfoStatus {
|
|||
noAccount,
|
||||
accountInvalid,
|
||||
accountLocked,
|
||||
accountReady,
|
||||
accountUnlocked,
|
||||
}
|
||||
|
||||
@immutable
|
||||
|
|
|
@ -129,7 +129,7 @@ class AccountRepository {
|
|||
|
||||
// Got account, decrypted and decoded
|
||||
return AccountInfo(
|
||||
status: AccountInfoStatus.accountReady,
|
||||
status: AccountInfoStatus.accountUnlocked,
|
||||
active: active,
|
||||
unlockedAccountInfo:
|
||||
UnlockedAccountInfo(localAccount: localAccount, userLogin: userLogin),
|
||||
|
|
|
@ -70,9 +70,6 @@ class _EditAccountPageState extends State<EditAccountPage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final displayModalHUD = _isInAsyncCall;
|
||||
final accountRecordsCubit = context.watch<AccountRecordsBlocMapCubit>();
|
||||
final accountRecordCubit = accountRecordsCubit
|
||||
.operate(widget.superIdentityRecordKey, closure: (c) => c);
|
||||
|
||||
return Scaffold(
|
||||
// resizeToAvoidBottomInset: false,
|
||||
|
@ -118,9 +115,15 @@ class _EditAccountPageState extends State<EditAccountPage> {
|
|||
_isInAsyncCall = true;
|
||||
});
|
||||
try {
|
||||
// Update account profile DHT record
|
||||
// This triggers ConversationCubits to update
|
||||
await accountRecordCubit.updateProfile(newProfile);
|
||||
// Look up account cubit for this specific account
|
||||
final accountRecordsCubit =
|
||||
context.read<AccountRecordsBlocMapCubit>();
|
||||
await accountRecordsCubit.operateAsync(
|
||||
widget.superIdentityRecordKey, closure: (c) async {
|
||||
// Update account profile DHT record
|
||||
// This triggers ConversationCubits to update
|
||||
await c.updateProfile(newProfile);
|
||||
});
|
||||
|
||||
// Update local account profile
|
||||
await AccountRepository.instance.editAccountProfile(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue