import 'package:shared_preferences/shared_preferences.dart'; /// 本地记录各会话已同步到的最大 seq,断线重连后用于 gap fill。 class ImSeqStore { ImSeqStore._(); static SharedPreferences? _p; static Future ensure() async { _p ??= await SharedPreferences.getInstance(); } static Future lastSeq(String conversationId) async { if (conversationId.isEmpty) return 0; await ensure(); return _p?.getInt('im.seq.$conversationId') ?? 0; } static Future setLastSeq(String conversationId, int seq) async { if (conversationId.isEmpty || seq <= 0) return; await ensure(); final prev = _p?.getInt('im.seq.$conversationId') ?? 0; if (seq > prev) await _p!.setInt('im.seq.$conversationId', seq); } static Future applyItems(String conversationId, Iterable> items) async { var max = 0; for (final e in items) { final s = (e['seq'] as num?)?.toInt() ?? 0; if (s > max) max = s; } if (max > 0) await setLastSeq(conversationId, max); } }