Finish KeyToken operations

This commit is contained in:
2025-04-18 18:56:17 +02:00
parent 1f0f280286
commit 78c895547e
23 changed files with 1089 additions and 211 deletions

View File

@@ -1,5 +1,7 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:simplecloudnotifier/api/api_client.dart';
import 'package:simplecloudnotifier/models/channel.dart';
import 'package:simplecloudnotifier/models/keytoken.dart';
import 'package:simplecloudnotifier/models/scn_message.dart';
import 'package:simplecloudnotifier/settings/app_settings.dart';
@@ -57,4 +59,21 @@ class SCNDataCache {
return cacheMessages;
}
Future<KeyToken> getOrQueryTokenByValue(String uid, String tokVal) async {
final cache = Hive.box<KeyToken>('scn-keytoken-value-cache');
final cacheVal = cache.get(tokVal);
if (cacheVal != null) {
print('[SCNDataCache] Found Token(${tokVal}) in cache');
return Future.value(cacheVal);
}
final tok = await APIClient.getKeyTokenByToken(uid, tokVal);
print('[SCNDataCache] Queried Token(${tokVal}) from API');
await cache.put(tokVal, tok);
return tok;
}
}