feat: 重构会话管理与提醒通知系统

This commit is contained in:
qzl
2026-03-31 18:26:36 +08:00
parent a8c262e9c7
commit 9a231dae9e
31 changed files with 650 additions and 223 deletions
@@ -0,0 +1,42 @@
import '../../data/cache/cache_scope.dart';
import '../../data/cache/cache_store.dart';
class SessionScopeManager {
SessionScopeManager({required HybridCacheStore cacheStore})
: _cacheStore = cacheStore;
final HybridCacheStore _cacheStore;
String? _activeUserId;
Future<void> activate(String userId) async {
final normalizedUserId = userId.trim();
if (normalizedUserId.isEmpty) {
throw StateError('User id cannot be empty when activating cache scope');
}
final previousUserId = _activeUserId;
if (previousUserId == normalizedUserId) {
return;
}
_activeUserId = normalizedUserId;
CacheScope.configureProvider(() => 'user:$normalizedUserId');
if (previousUserId != null && previousUserId != normalizedUserId) {
await _clearUserCache(previousUserId);
}
}
Future<void> clearActiveUserScope() async {
final userId = _activeUserId;
_activeUserId = null;
CacheScope.resetProvider();
if (userId != null) {
await _clearUserCache(userId);
}
}
Future<void> _clearUserCache(String userId) {
return _cacheStore.clearByPrefix('cache:user:$userId:');
}
}