25ed765a03
6 Wochen uncommittete Arbeit (Voice-Channels, LiveKit-Manager, Settings-Modal u.v.m.) als ein WIP-Commit gesichert, damit nichts verloren geht und der Pi den aktuellen Stand klonen kann. Thematische Aufarbeitung: siehe ROADMAP M0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CPrAGBxBT6GfPXzeWQ4AXb
39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class ReactionService {
|
|
static const _key = 'recent_reactions';
|
|
static const _maxRecent = 6;
|
|
|
|
static final _defaultReactions = ['👍', '❤️', '😂', '😮', '😢', '🙏'];
|
|
|
|
static List<String> _recent = [];
|
|
static bool _loaded = false;
|
|
|
|
static Future<void> load() async {
|
|
if (_loaded) return;
|
|
final prefs = await SharedPreferences.getInstance();
|
|
_recent = prefs.getStringList(_key) ?? [];
|
|
_loaded = true;
|
|
}
|
|
|
|
static List<String> get quickReactions {
|
|
if (_recent.isEmpty) return _defaultReactions;
|
|
// Fill up to 6 with defaults not already in recent
|
|
final result = List<String>.from(_recent);
|
|
for (final d in _defaultReactions) {
|
|
if (result.length >= _maxRecent) break;
|
|
if (!result.contains(d)) result.add(d);
|
|
}
|
|
return result.take(_maxRecent).toList();
|
|
}
|
|
|
|
static Future<void> recordUsed(String emoji) async {
|
|
await load();
|
|
_recent.remove(emoji);
|
|
_recent.insert(0, emoji);
|
|
if (_recent.length > _maxRecent) _recent = _recent.sublist(0, _maxRecent);
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setStringList(_key, _recent);
|
|
}
|
|
}
|