upsertAll method
The action for the upsert all.
Implementation
@action
void upsertAll(List<ModelBaseMessage> msgs) {
// Skip if empty list
if (msgs.isEmpty) return;
// Update or add each message to the map
for (final msg in msgs) {
if (!_map.containsKey(msg.id)) {
_order.add(msg.id);
}
_map[msg.id] = msg;
_messageStatusMap[msg.id] = msg.status;
}
// Sort the entire _order list based on sequence numbers
_order.sort((a, b) {
final seqA = _map[a]?.sequence ?? 0;
final seqB = _map[b]?.sequence ?? 0;
return seqB.compareTo(seqA); // Descending order (newer messages first)
});
}