addMessage static method
发送消息后添加聊天消息
Implementation
static void addMessage(MessageItemEntity msgInfo) {
try {
Map<String, List<MessageItemEntity>> newConfig = Map.from(messageListConfig.value);
List<MessageItemEntity> conversationIDAboutMsgList = newConfig[msgInfo.conversationID] ?? [];
if (conversationIDAboutMsgList.where((find) => find.iD == msgInfo.iD).isEmpty) {
conversationIDAboutMsgList.add(msgInfo);
conversationIDAboutMsgList.sort((a, b) {
int timeCompare = a.time.compareTo(b.time);
if (timeCompare != 0) return timeCompare;
int aSeq = int.tryParse(a.sequence.toString()) ?? 0;
int bSeq = int.tryParse(b.sequence.toString()) ?? 0;
int seqCompare = aSeq.compareTo(bSeq);
return seqCompare;
});
newConfig[msgInfo.conversationID] = conversationIDAboutMsgList;
messageListConfig.value = newConfig;
setCatch('messageListConfig', jsonEncode(messageListConfig.value));
}
} catch (_) {}
}