mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
xfer
This commit is contained in:
parent
b502bc20a7
commit
3c52931a74
@ -4,4 +4,5 @@ targets:
|
|||||||
json_serializable:
|
json_serializable:
|
||||||
options:
|
options:
|
||||||
explicit_to_json: true
|
explicit_to_json: true
|
||||||
|
generic_argument_factories: true
|
||||||
field_rename: snake
|
field_rename: snake
|
||||||
|
@ -25,10 +25,13 @@ class LocalAccounts extends _$LocalAccounts
|
|||||||
@override
|
@override
|
||||||
String tableKeyName() => "local_accounts";
|
String tableKeyName() => "local_accounts";
|
||||||
@override
|
@override
|
||||||
IList<LocalAccount> reviveJson(Object? obj) => obj != null
|
IList<LocalAccount> valueFromJson(Object? obj) => obj != null
|
||||||
? IList<LocalAccount>.fromJson(
|
? IList<LocalAccount>.fromJson(
|
||||||
obj, genericFromJson(LocalAccount.fromJson))
|
obj, genericFromJson(LocalAccount.fromJson))
|
||||||
: IList<LocalAccount>();
|
: IList<LocalAccount>();
|
||||||
|
@override
|
||||||
|
Object? valueToJson(IList<LocalAccount> val) =>
|
||||||
|
val.toJson((la) => la.toJson());
|
||||||
|
|
||||||
/// Get all local account information
|
/// Get all local account information
|
||||||
@override
|
@override
|
||||||
|
@ -21,9 +21,11 @@ class Logins extends _$Logins with AsyncTableDBBacked<ActiveLogins> {
|
|||||||
@override
|
@override
|
||||||
String tableKeyName() => "active_logins";
|
String tableKeyName() => "active_logins";
|
||||||
@override
|
@override
|
||||||
ActiveLogins reviveJson(Object? obj) => obj != null
|
ActiveLogins valueFromJson(Object? obj) => obj != null
|
||||||
? ActiveLogins.fromJson(obj as Map<String, dynamic>)
|
? ActiveLogins.fromJson(obj as Map<String, dynamic>)
|
||||||
: ActiveLogins.empty();
|
: ActiveLogins.empty();
|
||||||
|
@override
|
||||||
|
Object? valueToJson(ActiveLogins val) => val.toJson();
|
||||||
|
|
||||||
/// Get all local account information
|
/// Get all local account information
|
||||||
@override
|
@override
|
||||||
|
@ -2,5 +2,18 @@ import 'package:veilid/veilid.dart';
|
|||||||
|
|
||||||
Future<VeilidConfig> getVeilidChatConfig() async {
|
Future<VeilidConfig> getVeilidChatConfig() async {
|
||||||
VeilidConfig config = await getDefaultVeilidConfig("VeilidChat");
|
VeilidConfig config = await getDefaultVeilidConfig("VeilidChat");
|
||||||
|
if (const String.fromEnvironment("DELETE_TABLE_STORE") == "1") {
|
||||||
|
config =
|
||||||
|
config.copyWith(tableStore: config.tableStore.copyWith(delete: true));
|
||||||
|
}
|
||||||
|
if (const String.fromEnvironment("DELETE_PROTECTED_STORE") == "1") {
|
||||||
|
config = config.copyWith(
|
||||||
|
protectedStore: config.protectedStore.copyWith(delete: true));
|
||||||
|
}
|
||||||
|
if (const String.fromEnvironment("DELETE_BLOCK_STORE") == "1") {
|
||||||
|
config =
|
||||||
|
config.copyWith(blockStore: config.blockStore.copyWith(delete: true));
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -118,12 +118,12 @@ class DHTRecord {
|
|||||||
|
|
||||||
Future<T> deleteScope<T>(Future<T> Function(DHTRecord) scopeFunction) async {
|
Future<T> deleteScope<T>(Future<T> Function(DHTRecord) scopeFunction) async {
|
||||||
try {
|
try {
|
||||||
return await scopeFunction(this);
|
final out = await scopeFunction(this);
|
||||||
|
close();
|
||||||
|
return out;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
delete();
|
delete();
|
||||||
rethrow;
|
rethrow;
|
||||||
} finally {
|
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,13 +34,14 @@ Future<T> transactionScope<T>(
|
|||||||
abstract mixin class AsyncTableDBBacked<T> {
|
abstract mixin class AsyncTableDBBacked<T> {
|
||||||
String tableName();
|
String tableName();
|
||||||
String tableKeyName();
|
String tableKeyName();
|
||||||
T reviveJson(Object? obj);
|
T valueFromJson(Object? obj);
|
||||||
|
Object? valueToJson(T val);
|
||||||
|
|
||||||
/// Load things from storage
|
/// Load things from storage
|
||||||
Future<T> load() async {
|
Future<T> load() async {
|
||||||
final obj = await tableScope(tableName(), (tdb) async {
|
final obj = await tableScope(tableName(), (tdb) async {
|
||||||
final objJson = await tdb.loadStringJson(0, tableKeyName());
|
final objJson = await tdb.loadStringJson(0, tableKeyName());
|
||||||
return reviveJson(objJson);
|
return valueFromJson(objJson);
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -48,7 +49,7 @@ abstract mixin class AsyncTableDBBacked<T> {
|
|||||||
/// Store things to storage
|
/// Store things to storage
|
||||||
Future<void> store(T obj) async {
|
Future<void> store(T obj) async {
|
||||||
await tableScope(tableName(), (tdb) async {
|
await tableScope(tableName(), (tdb) async {
|
||||||
await tdb.storeStringJson(0, tableKeyName(), obj);
|
await tdb.storeStringJson(0, tableKeyName(), valueToJson(obj));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user