home layout

This commit is contained in:
Christien Rioux 2023-07-28 20:36:05 -04:00
parent f754f7d5ed
commit ca6b00e021
45 changed files with 2168 additions and 561 deletions

View file

@ -14,6 +14,8 @@ import 'logins.dart';
part 'local_accounts.g.dart';
const String veilidChatAccountKey = 'com.veilid.veilidchat';
// Local account manager
@riverpod
class LocalAccounts extends _$LocalAccounts
@ -90,6 +92,7 @@ class LocalAccounts extends _$LocalAccounts
encryptionKeyType: encryptionKeyType,
biometricsEnabled: false,
hiddenAccount: false,
name: account.profile.name,
);
/////// Add account with profile to DHT
@ -114,8 +117,14 @@ class LocalAccounts extends _$LocalAccounts
await identityRec.eventualUpdateJson(Identity.fromJson,
(oldIdentity) async {
final accountRecords = IMapOfSets.from(oldIdentity.accountRecords)
.add('com.veilid.veilidchat', newAccountRecordInfo)
final oldAccountRecords = IMapOfSets.from(oldIdentity.accountRecords);
// Only allow one account per identity for veilidchat
if (oldAccountRecords.get(veilidChatAccountKey).isNotEmpty) {
throw StateError(
'Only one account per identity allowed for VeilidChat');
}
final accountRecords = oldAccountRecords
.add(veilidChatAccountKey, newAccountRecordInfo)
.asIMap();
return oldIdentity.copyWith(accountRecords: accountRecords);
});
@ -151,3 +160,18 @@ class LocalAccounts extends _$LocalAccounts
/// Recover an account with the master identity secret
}
@riverpod
Future<LocalAccount?> fetchLocalAccount(FetchLocalAccountRef ref,
{required TypedKey accountMasterRecordKey}) async {
final localAccounts = await ref.watch(localAccountsProvider.future);
try {
return localAccounts.firstWhere(
(e) => e.identityMaster.masterRecordKey == accountMasterRecordKey);
} on Exception catch (e) {
if (e is StateError) {
return null;
}
rethrow;
}
}