This commit is contained in:
Christien Rioux 2024-06-16 22:12:24 -04:00
parent 2ccad50f9a
commit 360ba436f8
29 changed files with 501 additions and 317 deletions

View file

@ -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;
}
});

View file

@ -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(

View 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;
}

View file

@ -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';

View file

@ -7,7 +7,7 @@ enum AccountInfoStatus {
noAccount,
accountInvalid,
accountLocked,
accountReady,
accountUnlocked,
}
@immutable

View file

@ -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),

View file

@ -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(