setConversationListNative static method
设置会话数据 - 原生平台
Implementation
static Future<void> setConversationListNative(List<Map<String, dynamic>> list, { bool doClear = false, bool isRefresh = false }) async {
if (list.isEmpty && doClear) {
developerLog('清空会话列表');
conversationListNative.value = [];
needClearUnreadConversations.value = {};
setCatch('conversationListNative', jsonEncode(conversationListNative.value));
currentFocusConversationNative.value = null;
}
if (list.isNotEmpty) {
try {
List<Map<String, dynamic>> convListFilter = _doFilterConvDataListFunIsBlock ? list : (await ImState.doFilterConvDataList?.call(list, isRefresh ? PaginationType.refresh : PaginationType.more) ?? list);
if (!_doFilterConvDataListFunIsBlock && ImState.doFilterConvDataList != null) {
developerLog('设置会话列表,已通过业务数据筛选,数据筛选结果:');
developerLog(convListFilter);
}
if (isRefresh || doClear) {
developerLog('重置会话列表');
conversationListNative.value = convListFilter;
} else {
developerLog('追加数据到会话列表');
List<Map<String, dynamic>> all = [...conversationListNative.value, ...convListFilter];
final seenIds = <String>{};
final result = all.where((item) => seenIds.add(item['conv_id'])).toList();
conversationListNative.value = result;
}
needClearUnreadConversations.value = Set.from(
conversationListNative.value
.where((conversationItem) => (conversationItem['conv_unread_num'] ?? 0) > 0)
.map((conversationItem) => conversationItem['conv_id']?.toString() ?? '')
.where((id) => id.isNotEmpty)
);
setCatch('conversationListNative', jsonEncode(conversationListNative.value));
_resetCurrentFocusConversationFromSessionNative();
} catch (_) {}
}
}