saveRecentForward static method
保存最近转发的会话 最多保存五条
Implementation
static void saveRecentForward(List<RecentForward> recentList) async {
final recentForwardKey = '$recentForwardSPKey${IMKitClient.account()}';
final recentForwardStr =
await PreferenceUtils.getString(recentForwardKey, '');
var saveList = <RecentForward>[];
if (recentList.length > maxRecentForward) {
saveList = recentList.sublist(0, maxRecentForward);
} else if (recentForwardStr.isNotEmpty) {
saveList.addAll(recentList);
final recentForwardList =
RecentForward.fromJsonArray(jsonDecode(recentForwardStr));
var cacheList =
recentForwardList.where((e) => !recentList.contains(e)).toList();
cacheList.sort((a, b) => a.time.compareTo(b.time));
if (saveList.length + cacheList.length > maxRecentForward) {
saveList
.addAll(cacheList.sublist(0, maxRecentForward - recentList.length));
} else {
saveList.addAll(cacheList);
}
} else {
saveList.addAll(recentList);
}
final jsonArray = RecentForward.toJsonList(saveList);
await PreferenceUtils.saveString(recentForwardKey, jsonEncode(jsonArray));
}